Example #1
0
 def __init__(self,
              state: State = State(),
              p1: Player = None,
              p2: Player = None):
     self.state = state
     self.p1 = p1
     self.p2 = p2
Example #2
0
    def play(self):
        self.gameState = State()

        while not self.gameState.game_over():
            player1Action = self.player1.choose_action(self.gameState)
            self.gameState.execute(player1Action)
            util.pprint(self.gameState)

            if self.gameState.game_over():
                break

            player2Action = self.player2.choose_action(self.gameState)
            self.gameState.execute(player2Action)
            util.pprint(self.gameState)

        return self.gameState.winner()
Example #3
0
from connect3 import State, util
from game import Game
from human import HumanPlayer
from agent import RandomPlayer, MinimaxPlayer

def make_player(p: str = "", c: str = ""):
    if p[0] == "h":
        return HumanPlayer(c)
    if p[0] == "r":
        return RandomPlayer(c)
    if p[0] == "m":
        return MinimaxPlayer(c)
    print("Please enter a valid player string: [human, random, minimax]")
    exit()

p1 = util.get_arg(1)
p2 = util.get_arg(2)
print(p1, "vs.", p2)
if p1 and p2:
    p1 = make_player(p1, 'X')
    p2 = make_player(p2, 'O')
    print(p1, "vs.", p2)
    game = Game(state=State(), p1=p1, p2=p2)
    hist = game.play()
    print("Game over!", hist.pop(0), "wins!")
    util.pprint(hist)
else:
    print("Usage: python3 main.py PlayerType PlayerType")