Example #1
0
def play_one_game(players, lucky):
    game = s.init()
    done = False
    moves = []
    while not done:
        # do move for someone
        player = s.getCurrentPlayer(game)
        if needRandomMove(len(moves)):
            move = lucky.move(game)
        else:
            move = players[player]['ai'].move(game)
        if move is None:
            logger.error("null move! ", game)
        mt = [s.flipBoardCurrentPlayer(game), s.flipMove(move, player), player]
        moves.append(mt)
        game = s.doMove(game, move)
        done = s.isGameOver(game)
    winner = s.getWinner(game)
    score = s.getScore(game)
    # make training set with move, gamestate, and 1 for win, 0 for lose
    trainingset = [
        d[0:2] + [int(winner == d[2])] + list(score)[::1 - d[2] * 2]
        for d in moves
    ]
    for move in trainingset:
        results.info(move)
    i = 0
    for p in players:
        isWinner = (1 if i == winner else 0)
        p['ai'].gameOver(isWinner)
        p['wins'] += isWinner
        i += 1
    return (winner, trainingset)
Example #2
0
def play_game(players):
    game = s.init()
    done = False
    moves = []
    while not done:
        # do move for someone
        player = s.getCurrentPlayer(game)
        move = players[player]['ai'].move(game)
        if move is None:
            print("null move! ", game)
        mt = {
            "move": s.flipMove(move, player),
            "board": s.flipBoardCurrentPlayer(game),
            "player": player,
            "name": players[player]['module'].__name__
        }
        moves.append(mt)
        game = s.doMove(game, move)
        done = s.isGameOver(game)
    winner = s.getWinner(game)
    # make training set with move, gamestate, and 1 for win, 0 for lose
    trainingset = [dict(d, winner=int(winner == d['player'])) for d in moves]
    i = 0
    for p in players:
        p['ai'].gameOver(i == winner)
        i += 1
    return (winner, trainingset)
Example #3
0
 def __init__(self, opponent):
     self.player_algorithm = {}
     cprint("Player 1 is human.", PLAYER_COLORS[0])
     for player in range(1, s.NUM_PLAYERS):
         self.choosePlayer(player, opponent)
     self.gamestate = s.init()
     self.priorstate = self.gamestate[:]
     self.betweenMoves()
Example #4
0
def play_game(*players):
    game = s.init()
    done = False
    while not done:
        player = s.getCurrentPlayer(game)
        move = players[player].move(game)
        game = s.doMove(game, move)
        done = s.isGameOver(game)
    return s.getWinner(game)