Skip to content

Commit

Permalink
Setting up for exe
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianGH committed Sep 9, 2019
1 parent 03ce9de commit 52ac156
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ dmypy.json
pong_old.py
pong_backup.py
icon.ico
output/
Binary file added freesansbold.ttf
Binary file not shown.
24 changes: 9 additions & 15 deletions pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def display_best_fitness(self, fitness_list):
# Draw Game-Over-Screen.
@staticmethod
def game_over_screen(player):
game_over_font = pygame.font.Font('freesansbold.ttf', 90)
lost_font = pygame.font.Font('freesansbold.ttf', 45)
game_over_font = pygame.font.Font(resource_path('freesansbold.ttf'), 90)
lost_font = pygame.font.Font(resource_path('freesansbold.ttf'), 45)
box = pygame.Rect(0, 0, width / 2, height / 2)
box.center = (width / 2, height / 2)
game_surf = game_over_font.render('GAME', True, black)
Expand Down Expand Up @@ -226,7 +226,7 @@ def pong(genomes, config):
global basicfont, basicfontsize
global auto_play_state
basicfontsize = 20
basicfont = pygame.font.Font('freesansbold.ttf', basicfontsize)
basicfont = pygame.font.Font(resource_path('freesansbold.ttf'), basicfontsize)
fpsclock = pygame.time.Clock()
disp = pygame.display.set_mode((width, height))
pygame.display.set_caption('Pong')
Expand Down Expand Up @@ -320,7 +320,8 @@ def pong(genomes, config):
balls.pop(x)
ge.pop(x)
continue
elif paddle_ai.score >= 20:
elif paddle_ai.score >= 10:
ge[x].fitness -= 1
paddles_ai.pop(x)
nets.pop(x)
balls.pop(x)
Expand All @@ -346,11 +347,9 @@ def pong(genomes, config):


def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(relative_path)


def start_ai(config):
Expand All @@ -367,11 +366,6 @@ def start_ai(config):
print(winner)


print('hi')
input()
if __name__ == '__main__':
input()
config_path = resource_path(os.path.dirname(os.path.abspath(__file__))) + '\\neat-config.txt'
print(config_path)
input()
config_path = resource_path('neat-config.txt')
start_ai(config_path)

0 comments on commit 52ac156

Please sign in to comment.