Beispiel #1
0
 def change_player(self):
     self.currentPlayer = -self.currentPlayer
     self.gameState.playerTurn = -self.gameState.playerTurn
     self.gameState.board = turn_board(self.gameState.board)
     self.gameState.current_position = (12 -
                                        self.gameState.current_position[0],
                                        8 -
                                        self.gameState.current_position[1])
Beispiel #2
0
 def test_turn_board_with_lines(self):
     game = Game()
     board = game.gameState.board.copy()
     game.gameState.board[18, 5] = 1
     game.gameState.board[28, 6] = 1
     board[30, 2] = 1
     board[20, 1] = 1
     self.assertEqual(
         turn_board(game.gameState.board).tolist(), board.tolist())
Beispiel #3
0
    def test_turn_board_with_broad_lines(self):
        game = Game()
        board = game.gameState.board.copy()
        game.gameState.board[4, 0] = 1
        game.gameState.board[42, 0] = 1
        game.gameState.board[6, 7] = 1
        board[44, 7] = 1
        board[6, 7] = 1
        board[42, 0] = 1

        self.assertEqual(
            turn_board(game.gameState.board).tolist(), board.tolist())
Beispiel #4
0
    def addNode(self, parent, edge):
        state = copy.deepcopy(parent.state)
        done, res = state.make_move(edge)

        state.playerTurn = -state.playerTurn
        state.board = turn_board(state.board)
        state.current_position = (12 - state.current_position[0], 8 - state.current_position[1])

        node = Node(state, parent, e=edge)
        if done != 0:
            node.result = res
            node.value = 999999*res
        node.edges = node.state.get_full_moves_simple(max_moves=config.MAX_MOVES_MCTS_DEEP,
                                                          max_time=config.MAX_TIME_MCTS_DEEP)
        if len(node.edges) == 0:
            node.result = -1
        return node
Beispiel #5
0
 def check_for_danger(board, tmp_current_pos, full_moves_final=[]):
     board_temp = turn_board(board)
     tmp_current_pos_turned = (12 - tmp_current_pos[0],
                               8 - tmp_current_pos[1])
     local_moves = []
     get_full_moves_utils(self, [],
                          board_temp,
                          tmp_current_pos_turned,
                          local_moves,
                          c_p=tmp_current_pos_turned,
                          max_moves=max_checked_moves,
                          full_moves_final=full_moves_final)
     if len(full_moves_final) >= 1:
         if full_moves_final[0][2] == 1:
             return -1
     if len(full_moves_final) > max_final_moves:
         return -1
     if not local_moves:
         return 1
     elif local_moves[0][2] == 1:
         return -1
     return 0
Beispiel #6
0
    def simulate(self):
        # print('level',self.level)
        # print('visited',self.visited)
        player = self.state.playerTurn
        const_player = player
        result = 0
        done = False
        # state_copy = copy.deepcopy(self.state)
        i = 1
        while not done:
            move =self.state.get_random_move()
            # if len(move) > 0:
            #     print(move[1])
            # else:
                # print('none')
            player = self.state.playerTurn
            # print(player)
            done, result =self.state.make_move(move)
            self.state.playerTurn = -self.state.playerTurn
            self.state.board = turn_board(self.state.board)
            self.state.current_position = (12 - self.state.current_position[0], 8 - self.state.current_position[1])

        return const_player * result * player
Beispiel #7
0
 def test_turn_empty_board(self):
     game = Game()
     board = turn_board(game.gameState.board)
     self.assertEqual(game.gameState.board.tolist(), board.tolist())
     board[0, 0] = 0
     self.assertNotEqual(game.gameState.board.tolist(), board.tolist())
Beispiel #8
0
 def test_turn_full_board(self):
     game = Game()
     board = np.zeros((48, 8), dtype=int)
     board[:48, :8] = 1
     # print(board)
     self.assertEqual(turn_board(board).tolist(), board.tolist())