예제 #1
0
 def getNextState(board, player, action_number):
     assert action_number >= 0
     hive = represent.load_state_with_player(
         board, AIEnvironment._player_to_inner_player(player))
     try:
         (piece, to_cell) = hive.action_from_vector(action_number)
     except HiveException as error:
         logging.error("HiveException was caught: {}".format(error))
         logging.error("action number: {}".format(action_number))
         importexport.export_hive(
             hive, importexport.saved_game_path("last_error.json"))
         raise
     # TODO handle pass
     try:
         hive.action_piece_to(piece, to_cell)
     except HiveException as error:
         logging.error("HiveException was caught: {}".format(error))
         logging.error(
             "action number: {}, resulting action: ({}, {})".format(
                 action_number, piece, to_cell))
         logging.error("Hive:\n{}".format(hive))
         importexport.export_hive(
             hive, importexport.saved_game_path("last_error.json"))
         raise
     return represent.two_dim_representation(
         represent.get_adjacency_state(hive)), player * (-1)
예제 #2
0
 def getGameEnded_original(board, player_num):
     hive = represent.load_state_with_player(
         board, AIEnvironment._player_to_inner_player(player_num))
     status = hive.check_victory()
     if status == GameStatus.UNFINISHED:
         return 0
     if player_num == 1:  # Hive.WHITE
         return -1 if status == GameStatus.BLACK_WIN else 1
     elif player_num == -1:  # Hive.BLACK
         return -1 if status == GameStatus.WHITE_WIN else 1
     else:
         raise ValueError('Unexpected game status')
예제 #3
0
 def getGameEnded_simpified(board, player):
     inner_player = AIEnvironment._player_to_inner_player(player)
     hive = represent.load_state_with_player(board, inner_player)
     res = 0
     white_queen_pos = hive.locate("wQ1")
     if white_queen_pos:
         if len(hive.level.occupied_surroundings(white_queen_pos)) > 1:
             res = -1 if inner_player == Player.WHITE else 1
     black_queen_pos = hive.locate("bQ1")
     if black_queen_pos:
         if len(hive.level.occupied_surroundings(black_queen_pos)) > 1:
             res = -1 if inner_player == Player.BLACK else 1
     return res
예제 #4
0
 def getValidMoves(board, player_num) -> List[int]:
     hive = represent.load_state_with_player(
         board, AIEnvironment._player_to_inner_player(player_num))
     return represent.get_all_action_vector(hive)
예제 #5
0
 def getCanonicalForm(two_dim_repr: List[List[int]], player_num):
     hive = represent.load_state_with_player(
         two_dim_repr, AIEnvironment._player_to_inner_player(player_num))
     return represent.two_dim_representation(
         represent.canonical_adjacency_state(hive))