Ejemplo n.º 1
0
 def test_2_human_players_cl(self):
     player1 = HumanPlayer('H1')
     player2 = HumanPlayer('H2')
     game = TicTacToe()
     gui = CommandlineGui(game)
     match = Match(gui, game, players=[player1, player2])
     match.play()
Ejemplo n.º 2
0
 def test_2_human_players(self):
     player1 = HumanPlayer('H1')
     player2 = HumanPlayer('H2')
     game = TicTacToe()
     gui = KtinterGui(game)
     match = Match(gui, game, players=[player1, player2])
     match.play()
Ejemplo n.º 3
0
def main():
    board = ChessBoard()
    change_settings = 0
    while True:
        if change_settings == 0:
            num_player = get_user_response("How many players do you want (1-2)?: ", "012")
            if num_player == 0:
                p1 = CPUPlayer(Color.WHITE)
                p2 = CPUPlayer(Color.BLACK)
            elif num_player == 1:
                who_first = get_user_response("Do you want to be White(W) or Black(B)?: ", "WB")
                difficulty = get_user_response("How good do you want the computer to play (1-9): ", "123456789")
                if who_first == 0:
                    p1 = HumanPlayer(Color.WHITE)
                    p2 = CPUPlayer(Color.BLACK)
                else:
                    p1 = CPUPlayer(Color.WHITE)
                    p2 = HumanPlayer(Color.BLACK)
            else:
                p1 = HumanPlayer(Color.WHITE)
                p2 = HumanPlayer(Color.BLACK)
        board.init_board()
        play_game(p1, p2, board)
        pa_resp = get_user_response("Do you want to play again Y/N: ", "YN")
        if pa_resp == 1:  # break if user wanted to quit
            break
        change_settings = get_user_response("Do you want to change the settings Y/N: ", "YN")
    del board
    del p1
    del p2
Ejemplo n.º 4
0
 def test_random_human_players_cl(self):
     player1 = RandomPlayer()
     player2 = HumanPlayer()
     game = TicTacToe()
     gui = CommandlineGui(game)
     match = Match(gui, game, players=[player1, player2])
     match.play()
Ejemplo n.º 5
0
 def test_human_learner_players(self):
     player1 = HumanPlayer()
     player2 = Learner()
     game = TicTacToe()
     gui = KtinterGui(game)
     match = Match(gui, game, players=[player1, player2])
     match.play()
Ejemplo n.º 6
0
 def test_human_learner_players_cl(self):
     player1 = HumanPlayer()
     player2 = Learner()
     game = TicTacToe()
     gui = CommandlineGui(game)
     match = Match(gui, game, players=[player1, player2])
     match.play()
Ejemplo n.º 7
0
def play():
    board = Board()
    player1 = HumanPlayer('X')
    player2 = AIPlayer('O', 6)

    print "Let's play connect four!\nTo place a move, type a number [1-7]"

    current_player = player1
    other_player = player2

    winner = None
    game_over = False

    while not game_over:
        print board

        move_allowed = False
        while not move_allowed:
            move = current_player.get_move(board, other_player)
            move_allowed = board.try_place_piece(move, current_player.sign)

        game_over, winner = board.is_game_over(board.board,
                                               current_player.sign,
                                               other_player.sign)
        current_player, other_player = other_player, current_player

    print board
    if winner:
        print "Computer ", 'won!\nGame over'
    else:
        print 'Tie game!'

    ans = raw_input('Do you want to play again? y/n\n')

    if ans.lower() == 'y':
        play()
Ejemplo n.º 8
0
                ) == "B" else self.bPlayer
                self.textLabel.configure(
                    text="It is " + self.activePlayer.getMarker() + "\'s turn")


def playGameTerminal(game, rPlayer, bPlayer) -> None:
    game.printBoard()
    activePlayer = rPlayer

    while not game.hasWinner() and game.hasMoves():
        move = activePlayer.getMove(game)
        game.makeMove(move, activePlayer)
        game.printBoard()
        if game.wonGame(activePlayer):
            game.setWinner(activePlayer)
        else:
            activePlayer = rPlayer if activePlayer.getMarker(
            ) == "B" else bPlayer

    if game.hasWinner:
        print(activePlayer.getMarker() + " wins!")
    else:
        print("It's a tie")


if __name__ == "__main__":
    c = ConnectFour()
    r = HumanPlayer("R")
    b = AIComputer("B")
    playGameTerminal(c, r, b)
    #gui = BoardGame(c, r, b)
Ejemplo n.º 9
0
            reward = 100
        elif self.match.winner == other_player:
            reward = -100
        else:
            reward = -50
        self.learner.learn(self.game, reward, self.match.current_player())


if __name__ == '__main__':
    learner = Learner('X')
    other_mark = 'O'
    experiment = Experiment(learner, Gui.KtinterGui)

    trainer = RandomPlayer(other_mark)
    tester1 = RandomPlayer(other_mark)
    tester2 = HumanPlayer(other_mark)

    parser = argparse.ArgumentParser(description='Configures the experiment.')
    parser.add_argument('-train',
                        '--no_of_training_rounds',
                        type=int,
                        default=1000,
                        help='Number of training rounds')
    parser.add_argument(
        '-atest',
        '--number_of_automated_testrounds',
        type=int,
        default=100,
        help='Number of testing rounds for automated evaluation')
    parser.add_argument('-mtest',
                        '--number_of_manual_testrounds',
Ejemplo n.º 10
0
                self.game.play(*move, player)
                if self.gui:
                    self.gui.play_view(*move, player)
            self.next_player()
        if self.gui:
            if self.game.is_winner(self.current_player()):
                self.gui.game_over(self.current_player())
            else:
                self.gui.game_over()

    ## Checks if the game has ended. A games is over if
    # - either of the player has won
    # - or there is a draw preventing either playing from winning.
    # Sets winner variable to current_player(), if not a draw.
    # @return True if the game is over, and false otherwise.
    def is_game_over(self):
        won = self.game.is_winner(self.current_player())
        draw = not self.game.available_moves()
        if won:
            self.winner = self.current_player()
        return won or draw


if __name__ == '__main__':
    player1 = HumanPlayer('P1')
    player2 = RandomPlayer('P2')
    game = TicTacToe()
    gui = KtinterGui(game)
    match = Match(gui, game, players=[player1, player2])
    match.play()