def update_AI(self): solver = Solver(self.env.gameState) action = solver.get_action() self.env.step(action) self.render(self.main_window) pg.display.update()
def counter_double_menace(): print( '|----------------------------------------------------------------------------|' ) print(' TEST OBJECTIVE: counter the double menace\n') start_time = time() shape = (4, 5) sequence = [18, 13, 17] game = DynamicGame(grid_shape=shape) for action in sequence: game.step(action) print('Initial state: \n', game) solver = Solver(game.gameState) game.step(solver.get_action()) print('\n', game) end_time = time() assert (game.gameState.board[16] == -1) print('\n TEST SUCCESSFUL:', solver.nodes_explored, 'nodes explored in ', round(end_time - start_time, 2), 'seconds.') print( '|----------------------------------------------------------------------------|' )
def first_move(): print( '|----------------------------------------------------------------------------|' ) print(' TEST OBJECTIVE: choose the optimal first move\n') start_time = time() shape = (4, 5) game = DynamicGame(grid_shape=shape) print('\n', game) solver = Solver(game.gameState) game.step(solver.get_action()) end_time = time() assert (game.gameState.board[17] == 1) print('\n TEST SUCCESSFUL:', solver.nodes_explored, 'nodes explored in ', round(end_time - start_time, 2), 'seconds.') print( '|----------------------------------------------------------------------------|' )
def double_menace(): print( '|----------------------------------------------------------------------------|' ) print(' TEST OBJECTIVE: complete the double menace\n') start_time = time() shape = (4, 5) sequence = [18, 13, 17, 12] game = DynamicGame(grid_shape=shape) for action in sequence: game.step(action) print('Initial state: \n', game) total_nodes = 0 for x in range(3): solver = Solver(game.gameState) game.step(solver.get_action()) total_nodes += solver.nodes_explored print('\n', game) end_time = time() assert (game.gameState.board[15] == 1 and game.gameState.board[16] == 1 or game.gameState.board[16] == 1 and game.gameState.board[19] == 1) print('\n TEST SUCCESSFUL:', total_nodes, ' nodes explored in ', round(end_time - start_time, 2), 'seconds.') print( '|----------------------------------------------------------------------------|' )