コード例 #1
0
ファイル: results.py プロジェクト: prashantkthakur/AI_Game
def gamePlay(evalFT, evalFG, numGames):
    winners = []
    ebfs = []
    minimax = MiniMax()
    for i in range(numGames):
        game = GameBoard()
        moves = 0
        while not game.isOver() and moves < 100:
            if game.player == 'T':
                value, move = minimax.minimax(game, 3, game.player, evalFT)
            else:
                value, move = minimax.minimax(game, 3, game.player, evalFG)
            if move is None:
                print('move is None. Stopping')
                break
            game.makeMove(move)
            moves += 1
            if moves > 98:
                print("\nPlayer", game.player, "to", move, "for value", value)
                print(game)
            game.changePlayer()
        winner = game.getWinner()
        print("game", i, "winner", winner)
        winners.append(winner if winner is not None else 'D')
        ebfs.append(Evaluation.ebf(game.getMovesExplored(), moves))
    return winners, ebfs
コード例 #2
0
    def gamePlay(self):
        game = GameBoard()

        moves = 0
        while not game.isOver() and moves < 101:
            value, move = self.alphabeta(game,
                                         4,
                                         game.player,
                                         Evaluation.evaluate,
                                         sorting=False)
            if move is None:
                print('move is None. Stopping')
                break
            game.makeMove(move)
            moves += 1
            print("\nPlayer", game.player, "to", move, "for value", value)
            print(game)
            game.changePlayer()
        print("Moves Explored", game.getMovesExplored(), "Moves: ", moves)
        print("EBF: ", Evaluation.ebf(game.getMovesExplored(), moves))
コード例 #3
0
ファイル: baghchal.py プロジェクト: prashantkthakur/AI_Game
if __name__ == "__main__":
    state = [
        'T', 'G', '', 'G', 'T', '', '', '', '', '', '', '', '', '', '', '', '',
        '', '', '', 'T', '', '', '', 'T'
    ]
    game = GameBoard()

    state2 = [
        'T', '', '', 'G', 'G', 'T', 'G', 'G', '', '', '', 'G', 'T', 'G', 'G',
        'G', 'G', '', 'G', 'G', 'G', 'G', 'G', 'G', 'T'
    ]
    game.board = state2
    game.changePlayer()
    print(game)
    print(Evaluation.sortTigerMoves(game, game.availableMoves()))
    print(Evaluation.ebf(189985, 200))
    """
    GameBoard.printState(state2)
    tiger_move = game.valid_tiger_move(state2)
    print("Tiger moves:{}".format(tiger_move))
    goat_move = game.valid_goat_move(state2)
    print("Goat move", goat_move)
    print("All moves", game.availableMoves(state2))

    state2 = ['T', '', '', 'G', 'G', 'T', 'G', 'G', '', '', '', 'G', 'T', 'G', 'G', 'G', 'G', '', 'G', 'G', 'G', 'G',
              'G', 'G', 'T']
    game.printState(state2)
    game.makeMove(state2, (12,10))
    game.printState(state2)
    print(game.goat_lost)
    game.unmakeMove(state2, (12,10))