Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made visual rendering steps optional for major runtime enhancements #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controller_specialist_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
playermode="ai",
player_controller=player_controller(n_hidden_neurons),
speed="normal",
visualmode="yes",
enemymode="static",
level=2)

Expand Down
36 changes: 24 additions & 12 deletions evoman/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pygame.locals import *
import struct
import tmx
import os

from player import *
from controller import Controller
Expand All @@ -32,6 +33,7 @@ def __init__(self,
playermode="ai", # ai or human
enemymode="static", # ai or static
speed="fastest", # normal or fastest
visualmode="yes", # yes or no. turns off visual processing if "no" for faster performance
inputscoded="no", # yes or no
randomini="no", # yes or no
sound="off", # on or off
Expand Down Expand Up @@ -60,6 +62,7 @@ def __init__(self,
self.playermode = playermode
self.enemymode = enemymode
self.speed = speed
self.visualmode = visualmode
self.inputscoded = inputscoded
self.randomini = randomini
self.sound = sound
Expand All @@ -74,6 +77,9 @@ def __init__(self,
self.joy = 0
self.use_joystick = use_joystick

# Does not open pygame on screen if visualmode is off
if self.visualmode == "no":
os.environ["SDL_VIDEODRIVER"] = "dummy"

# initializes default random controllers

Expand Down Expand Up @@ -109,7 +115,7 @@ def __init__(self,
self.joy = pygame.joystick.get_count()

self.clock = pygame.time.Clock() # initializes game clock resource

if self.fullscreen:
flags = DOUBLEBUF | FULLSCREEN
else:
Expand Down Expand Up @@ -471,24 +477,30 @@ def run_single(self,enemyn,pcont,econt):
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
return

# updates objects and draws its itens on screen
self.screen.fill((250,250,250))
if self.visualmode == "yes":
# updates objects and draws its itens on screen
self.screen.fill((250,250,250))

self.tilemap.update( 33 / 1000., self)
self.tilemap.draw(self.screen)

if self.visualmode == "yes":
self.tilemap.draw(self.screen)

# player life bar
vbar = int(100 *( 1-(self.player.life/float(self.player.max_life)) ))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anywhere else. may be moved under the condition

pygame.draw.line(self.screen, (0, 0, 0), [40, 40],[140, 40], 2)
pygame.draw.line(self.screen, (0, 0, 0), [40, 45],[140, 45], 5)
pygame.draw.line(self.screen, (150,24,25), [40, 45],[140 - vbar, 45], 5)
pygame.draw.line(self.screen, (0, 0, 0), [40, 49],[140, 49], 2)
if self.visualmode == "yes":
pygame.draw.line(self.screen, (0, 0, 0), [40, 40],[140, 40], 2)
pygame.draw.line(self.screen, (0, 0, 0), [40, 45],[140, 45], 5)
pygame.draw.line(self.screen, (150,24,25), [40, 45],[140 - vbar, 45], 5)
pygame.draw.line(self.screen, (0, 0, 0), [40, 49],[140, 49], 2)

# enemy life bar
vbar = int(100 *( 1-(self.enemy.life/float(self.enemy.max_life)) ))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my also be moved under the condition

pygame.draw.line(self.screen, (0, 0, 0), [590, 40],[695, 40], 2)
pygame.draw.line(self.screen, (0, 0, 0), [590, 45],[695, 45], 5)
pygame.draw.line(self.screen, (194,118,55), [590, 45],[695 - vbar, 45], 5)
pygame.draw.line(self.screen, (0, 0, 0), [590, 49],[695, 49], 2)
if self.visualmode == "yes":
pygame.draw.line(self.screen, (0, 0, 0), [590, 40],[695, 40], 2)
pygame.draw.line(self.screen, (0, 0, 0), [590, 45],[695, 45], 5)
pygame.draw.line(self.screen, (194,118,55), [590, 45],[695 - vbar, 45], 5)
pygame.draw.line(self.screen, (0, 0, 0), [590, 49],[695, 49], 2)


#gets fitness for training agents
Expand Down