Skip to content

Commit

Permalink
- Added demo mode that just shows, the AI playing against random player.
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelVI13 committed May 6, 2019
1 parent 4d71d19 commit 833fa79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions gui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class GameType(Enum):
SINGLE_PLAYER = auto()
MULTI_PLAYER = auto()
DEMO_MODE = auto()


BORDER_THICKNESS = 2
Expand Down
18 changes: 13 additions & 5 deletions gui/gui_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,8 @@ def click_random_cell(self):
def get_best_engine_move(self):
return uct_multi(self.board, itermax=1000, verbose=False)

def do_nothing(self):
pass # todo remove this later

def get_game_input(self, game_type, mouse_pos):
if game_type == GameType.SINGLE_PLAYER:
# self.click_random_cell() used for debugginh
if self.board.playerJustMoved == PLAYER_O: # X's turn todo allow user to select side to play
if mouse_pos is not None:
self.click_cell_under_mouse(mouse_pos)
Expand All @@ -121,6 +117,18 @@ def get_game_input(self, game_type, mouse_pos):
if mouse_pos is not None:
self.click_cell_under_mouse(mouse_pos)

elif game_type == GameType.DEMO_MODE:
if self.board.playerJustMoved == PLAYER_O:
self.click_random_cell()
else:
board, move = self.get_best_engine_move()
for cell in self.allowed_cells:
if cell.board_idx == board and cell.cell_idx == move:
self.subcell_clicked(cell)
break
else:
raise Exception('Wrong engine move (move not in allowed moves) ({}{})'.format(board, move))

def game_loop(self, game_type):
pygame.event.clear(pygame.MOUSEBUTTONUP) # clear all mouse clicks
self.reset_game()
Expand Down Expand Up @@ -176,7 +184,7 @@ def menu_loop(self):
action=partial(self.game_loop, GameType.SINGLE_PLAYER))
self.button("Two Player", **MENU_BUTTON_PROPERTIES[1],
action=partial(self.game_loop, GameType.MULTI_PLAYER))
self.button("Settings", **MENU_BUTTON_PROPERTIES[2], action=self.do_nothing)
self.button("Demo", **MENU_BUTTON_PROPERTIES[2], action=partial(self.game_loop, GameType.DEMO_MODE))
self.button("Quit", **MENU_BUTTON_PROPERTIES[3], action=self.quit_game)

pygame.display.update()
Expand Down

0 comments on commit 833fa79

Please sign in to comment.