def test_compute_game_value_with_evaluation_function(self): # We only check it runs tic_tac_toe = pyspiel.load_game("tic_tac_toe") game_score, _ = minimax.alpha_beta_search(tic_tac_toe, value_function=lambda x: 0, maximum_depth=1) self.assertEqual(0., game_score)
def test_win(self): tic_tac_toe = pyspiel.load_game("tic_tac_toe") state = tic_tac_toe.new_initial_state() # Construct: # .o. # .x. # ... state.apply_action(4) state.apply_action(1) game_score, _ = minimax.alpha_beta_search(tic_tac_toe, state=state) self.assertEqual(1., game_score)
def test_loss(self): tic_tac_toe = pyspiel.load_game("tic_tac_toe") state = tic_tac_toe.new_initial_state() # Construct: # ... # xox # ..o state.apply_action(5) state.apply_action(4) state.apply_action(3) state.apply_action(8) game_score, _ = minimax.alpha_beta_search(tic_tac_toe, state=state) self.assertEqual(-1., game_score)
def step(self, state): _, action = minimax.alpha_beta_search(self._game, state=state) return action
def test_compute_game_value(self): tic_tac_toe = pyspiel.load_game("tic_tac_toe") game_score, _ = minimax.alpha_beta_search(tic_tac_toe) self.assertEqual(0., game_score)
def play(self, state): legal_actions = state.legal_actions() _ , action = alpha_beta_search(state.get_game(), state, self.evaluate, 2 , self.idx) return action