コード例 #1
0
ファイル: main.py プロジェクト: AlexEladas/comp472
    player2 = Player("G", "R")

    print("You want to play as Red(1) or Green(2)?")
    while True:
        try:
            player_choice = int(input())
            if player_choice == 1 or player_choice == 2:
                break
            else:
                print("Enter 1 for Red Player or 2 for Green Player")
        except ValueError:
            print("Enter 1 for Red Player or 2 for Green Player")

    if player_choice == 1:
        while True:
            AI1.build_tree(board, AI1, player1)
            move = AI1.moves[AI1.evaluation]
            print(move)
            if not board.check_if_valid(move, AI1):
                print("AI ENTERED INVALID MOVE. YOU WIN")
                break
            board.move(move, AI1)

            if board.check_if_attacking_move(move, AI1):
                board.attack(move, AI1)
            print(AI1.evaluation)
            board.display()

            if AI1.number_of_tokens == 0:
                print("Green wins!")
                break
コード例 #2
0
args = parser.parse_args()

if __name__ == '__main__':
    if args.test == 1:
        test()
    elif args.test == 2:
        test_ec()
    elif args.test == 3:
        # CASE 3: USE THIS TO GENERATE NEW TESTS
        for seed in range(
                40, 50):  #TODO: Seeds to use. start inclusive, end exclusive
            random.seed(seed)
            game = Game()
            while not game.game_over():
                ai = AI(game.get_state(), 3)
                ai.build_tree()
                print(f"{4} {ai.root.state[1]} {ai.root.state[0]}")
                direction, s = ai.expectimax(ai.root)
                print(f"{direction} {s}")
                if direction != None:
                    game.move_and_place(direction)
    elif args.test == 4:
        # CASE 4: USE THIS TO COMPARE AGAINST DEFINED TESTS (I.E. STATE AND SOL FILES)
        start_seed = 40  # TODO: Change me
        end_seed = 50  # TODO: Change me
        test(f'seed_{start_seed}_to_{end_seed}_states.txt',
             f'seed_{start_seed}_to_{end_seed}_sols.txt')
    else:
        import pygame
        from pygame.locals import *
        ROTATIONS = {
コード例 #3
0
ファイル: test_ai.py プロジェクト: dem4ply/tic_tae_toe
from unittest import TestCase
from unittest.mock import Mock
from ai import AI

ai_tree = {}
p2 = AI( ai_tree, 2 )
p2.build_tree()


class Test_ai( TestCase ):
    def test_case_1( self ):
        board = [ [ 'O', 'X', ' ' ],
                  [ ' ', 'X', ' ' ],
                  [ ' ', ' ', ' ' ], ]
        result, move = p2.search_node( board, 'O' )
        x, y = move
        board[x][y] = 'O'
        self.assertTupleEqual( move, ( 2, 1 ) )

    def test_case_2( self ):
        board = [ [ 'X', 'X', ' ' ],
                  [ ' ', ' ', ' ' ],
                  [ 'O', ' ', ' ' ], ]
        result, move = p2.search_node( board, 'O' )
        x, y = move
        board[x][y] = 'O'
        self.assertTupleEqual( move, ( 0, 2 ) )