def test_actions_from_vector(self): self.hive = Hive.load_state_with_player(self._list_repr, Player.WHITE) all_actions = represent.get_all_action_vector(self.hive) indices = [i for i, v in enumerate(all_actions) if v > 0] for action_number in indices: self.hive.action_from_vector(action_number) # test other player's turn self.hive._toggle_player(self.hive.current_player) all_actions = represent.get_all_action_vector(self.hive) indices = [i for i, v in enumerate(all_actions) if v > 0] for action_number in indices: self.hive.action_from_vector(action_number)
def test_action_vector(self): self.hive = Hive.load_state_with_player(self._list_repr, Player.WHITE) __location__ = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) with open(os.path.join(__location__, 'repr_data.json')) as f: print(self.hive) d = json.load(f) res = represent.get_all_action_vector(self.hive) print(res) assert all([a == b for a,b in zip(res, d["test_action_vector"])])
def test_action_numbers(self): self.hive = Hive() self.hive.place_piece_without_action("wB2") self.hive.level.current_player = Player.BLACK self.hive.place_piece_without_action("bB1", "wB2", Direction.HX_W) self.hive.level.current_player = Player.WHITE self.hive.place_piece_without_action("wA2", "wB2", Direction.HX_SE) self.hive.level.current_player = Player.BLACK self.hive.place_piece_without_action("bS2", "bB1", Direction.HX_W) self.hive.level.current_player = Player.WHITE self.assertEqual(represent.get_all_action_vector(self.hive)[90], 0) self.assertRaises(HiveException, self.hive.action_from_vector, 90)
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)
def getActionSize(): """ :return: Number of possible actions in the given state """ hive = Hive() return len(represent.get_all_action_vector(hive))
def _val_indices(self): # TODO currently only white player supported (which is indicated by 1) val_moves = represent.get_all_action_vector(self.env.hive) return [i for i, v in enumerate(val_moves) if v > 0]
def test_10000(self): hive = importexport.import_hive( importexport.saved_game_path("test_10000.json")) actions = represent.get_all_action_vector(hive) self.assertEqual(0, actions[775])