Esempio n. 1
0
def test_possible_player_moves():
    b = Board()
    b.board = [0, 4, 0, 13, 5, 5, 5, 0, 4, 4, 4, 4, 4, 4]
    assert list(b.possible_player_moves()) == [0, 2, 3, 4, 5]
Esempio n. 2
0
    def compete(self, brain1: Brain, brain2: Brain):

        board = Board()
        brain1.set_board(board)
        brain2.set_board(board)

        brain1.set_player_num(1)
        brain2.set_player_num(2)

        if self.verbosity > 3:
            print("{} is playing against {}".format(brain1.getName(),
                                                    brain2.getName()))

        winner = None
        full_game_played = False
        move_count = 0

        while winner == None:
            (move, confidence) = brain1.predict()
            if (self.verbosity > 4):
                print("\n\nP1 move is {} with {}".format(move, confidence))
            if not move in board.possible_player_moves():
                winner = 2
                continue
            has_move = board.make_player_move(move, 1)
            if (self.verbosity > 4):
                board.print()

            move_count += 1

            (move, confidence) = brain2.predict()
            if (self.verbosity > 4):
                print("\n\nP2 move is {} with {}".format(move, confidence))
            if not move in board.get_opponent_board().possible_player_moves():
                winner = 1
                continue
            has_move = board.make_player_move(move, 2)
            if (self.verbosity > 4):
                board.print()

            move_count += 1

        if winner == None:
            full_game_played = True
            self.full_game_list.append(1)
            ending = " with a score of {} to {} after a FULL GAME\n FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME FULL GAME".format(
                board.player_points, board.opponent_points)
            if board.player_points > board.opponent_points:
                winner = 1
            else:
                winner = 2
        else:
            self.full_game_list.append(0)
            ending = "by disqualification after {} moves. Score was {} to {}".format(
                move_count, board.player_points, board.opponent_points)

        self.scores.append(board.player_points)
        self.scores.append(board.opponent_points)
        self.rounds.append(move_count / 2)

        if winner == 1:
            name = brain1.getName()
            brain1.record_win()
            brain2.record_loss()
        else:
            name = brain2.getName()
            brain2.record_win()
            brain1.record_loss()

        if self.verbosity > 2:
            print("{} wins {}".format(name, ending))

        return winner
Esempio n. 3
0
def test_possible_player_moves():
    b = Board()
    b.board = [0, 4, 0, 13, 5, 5, 5, 0, 4, 4, 4, 4, 4, 4]
    assert list(b.possible_player_moves()) == [0, 2, 3, 4, 5]