Пример #1
0
def humanVsAI(human, ai_algorithm, board):
    b = kb.KonaneBoard(board)

    if human == 'x':
        player_x = student.player(b, 'x', 99, "Human")
        player_o = student.player(b, 'o', 99, ai_algorithm)
    else:
        player_o = student.player(b, 'o', 99, "Human")
        player_x = student.player(b, 'x', 99, ai_algorithm)

    print('Konane Test Game')
    print('  AI Algorithm:  %s' % ai_algorithm)
    print('  Human Playing as: %s' % human)
    print('  Starting Board:')
    print(b)

    moves_o = []
    moves_x = []

    done = False
    while not done and len(moves_o) <= 99:
        [done, move] = player_x.takeTurn()
        moves_x.append(move)
        if done:
            print('PlayerO WINS!!!')
        else:
            print(b)
            [done, move] = player_o.takeTurn()
            moves_o.append(move)
            if done:
                print('PlayerX WINS!!!')
            else:
                print(b)

    print('Game Over.')
def runGame(board, max_moves, depth, algoG, algoS, student_xo):
    start = time.clock()
    moves_x = []
    moves_o = []

    b = kb.KonaneBoard(board)

    if student_xo == "x":
        player_x = student.player(b, 'x', depth, algoS)
        player_o = student.player(b, 'o', depth, algoG)
    else:
        player_o = student.player(b, 'o', depth, algoS)
        player_x = student.player(b, 'x', depth, algoG)

    done = False
    while not done and len(moves_o) < max_moves:
        [done, move] = player_x.takeTurn()
        moves_x.append(move)
        if not done:
            [done, move] = player_o.takeTurn()
            moves_o.append(move)

    timing = time.clock() - start

    if student_xo == 'x':
        return (moves_x, timing)
    else:
        return (moves_o, timing)
Пример #3
0
def test(board, max_moves, depth, algoG, algoS, student_xo):

    moves_x = []
    moves_o = []

    b = kb.KonaneBoard(board)

    # instantiates student and grader players based upon students' 'x' or 'o' designation
    if student_xo == 'x':
        player_x = sc.player(b, 'x', depth, algoS)
        player_o = sc.player(b, 'o', depth, algoG)
    else:
        player_o = sc.player(b, 'o', depth, algoS)
        player_x = sc.player(b, 'x', depth, algoG)

    # displays paramters of specific game used for evaluation
    if verbose:
        print('Konane Test Game')
        print('  Grader Algorithm:   %s' % algoG)
        print('  Student Algorithm:  %s' % algoS)
        print('  Student Playing as: %s' % student_xo)
        print('  Maximum Moves:      %d' % max_moves)
        print('  Maximum Depth:      %d' % depth)
        print('  Boards:')
        print(b)

    # players continue to alternate turns until gameover or maximum moves reached
    done = False
    while not done and len(moves_o) < max_moves:
        [done, move] = player_x.takeTurn()
        moves_x.append(move)
        if done:
            if verbose:
                print 'PlayerX moved', move
                print(b)
                print('PlayerO WINS!!!')
        else:
            if verbose:
                print 'PlayerX moved', move
                print(b)
            [done, move] = player_o.takeTurn()
            moves_o.append(move)
            if done:
                if verbose:
                    print 'PlayerO moved', move
                    print(b)
                    print('PlayerX WINS!!!')
            else:
                if verbose:
                    print 'PlayerO moved', move
                    print(b)

    if verbose:
        print('Game Over.')

    # returns appropriate list of moves based upon player's 'x' or 'o' designation
    if student_xo == 'x':
        return (moves_x)
    else:
        return (moves_o)
Пример #4
0
# print kath.s, "kath does ((2, 3), (0, 3))"
# kath.makeNextMove(((2, 3), (0, 3)))
# print b
# momove = mo.getFirstMove()
# mo.makeNextMove(momove)
# print "mo does", momove
# print b
# kp = b.possibleNextMoves(kath.s)
# print "kath has these options:", kp
# print kath.s, "kath does ((2, 1), (2, 3))"
# kath.makeNextMove(((2, 1), (2, 3)))
# print b

## ALPHA BETA GOLD
boardC = [['x', 'o', 'x', 'o', 'x', 'o'], ['o', 'x', 'o', 'x', 'o', 'x'],
          ['x', 'o', 'x', 'o', 'x', 'o'], ['o', 'x', ' ', ' ', 'o', 'x'],
          ['x', 'o', 'x', 'o', 'x', 'o'], ['o', 'x', 'o', 'x', 'o', 'x']]
ans3 = [((3, 5), (3, 3)), ((4, 2), (2, 2)), ((1, 3), (1, 1)), ((3, 3), (1, 3)),
        ((4, 4), (2, 4)), ((5, 5), (3, 5)), ((4, 0), (4, 2)), ((2, 0), (4, 0)),
        ((5, 3), (5, 5)), ((4, 2), (4, 4)), ((0, 4), (0, 2)), ((4, 0), (4, 2)),
        ((5, 1), (5, 3)), ((4, 2), (4, 4))]
game3 = [copy.deepcopy(boardC), ans3, 100, 5, 'First Move', 'AlphaBeta', 'x']
b = kb.KonaneBoard(copy.deepcopy(boardC))

kath = student.player(b, 'x', 5, 'Alpha Beta')
gr = student.player(b, 'o', 5, 'First Move')
print "starting board", b
kp = b.possibleNextMoves(kath.s)
print "kath has these options:", kp
print "kath does ((3, 5), (3, 3))"