Ejemplo n.º 1
0
 def get_legal_moves(self):
     moves = []
     for x in range(BOARD_SIZE):
         for y in range(BOARD_SIZE):
             if self.board[Helper.tuple2idx(BOARD_SIZE, x, y)] is None:
                 moves.append((x, y))
     return moves
 def test_get_action(self):
     player = NNPolicy()
     input = np.zeros((1, fe.get_feature_dim(player.features), 2 * gm.START_HANDS))
     
     game = gm.GameState()
     while(not game.is_end_of_game()): 
         (card, move) = player.get_action(game)
         self.assertTrue(card.position == (-1, -1) and card.owner == game.current_player)
         self.assertTrue(game.board[Helper.tuple2idx(game.board_size, *move)] is None)
         game.play_round(card, *move)
Ejemplo n.º 3
0
 def action_to_vector(self, state, card, move):
     card_idx = [0] * (2 * gm.START_HANDS)
     board_idx = [0] * (gm.BOARD_SIZE**2)
     for i in range(2 * gm.START_HANDS):
         if i < gm.START_HANDS and state.left_cards[i] is card:
             card_idx[i] = 1
         if i >= gm.START_HANDS and state.right_cards[
                 i - gm.START_HANDS] is card:
             card_idx[i] = 1
     board_idx[Helper.tuple2idx(gm.BOARD_SIZE, *move)] = 1
     return card_idx, board_idx
Ejemplo n.º 4
0
 def place_card(self, card, x_pos, y_pos):
     # Drop the card on the board based on the coordinates
     if self.on_Board(x_pos, y_pos):
         self.board[Helper.tuple2idx(BOARD_SIZE, x_pos, y_pos)] = card
         card.position = (x_pos, y_pos)
         card.visible = True
Ejemplo n.º 5
0
 def get_card(self, x_pos, y_pos):
     # returns the card on the board. If out side of the board returns None
     if self.on_Board(x_pos, y_pos):
         return self.board[Helper.tuple2idx(BOARD_SIZE, x_pos, y_pos)]
     else:
         return None