Пример #1
0
def baseline(seed):
    random.seed(seed)
    game = Tetris(numColumns=10, numRows=10)
    baselineAI = AI(baselineFunction)
    while (not game.lost):
        baselineAI.aiSequence(game)
    random.seed()

    if VERBOSE: print(f"Baseline AI played game with score {game.numLines}.")
    return game.numLines
def playGame():
    game = Tetris(numColors=MAXCOLORS, seed=int(time.time()))
    ai = AI(func1)

    game2 = Tetris(numColors=MAXCOLORS, seed=int(time.time()))
    ai2 = AI(func2)

    render(game, game2)

    pressedKeys = [-1, -1, -1, -1]  # up, down, left, right
    while not game.lost and not game2.lost:  # game loop ends when game is lost
        for event in pygame.event.get():  # event handling loop
            if event.type == pygame.QUIT:
                terminate()  # exit game

        # increment time (move blocks down)
        ai.aiSequence(game)
        ai2.aiSequence(game2)
        render(game, game2)

        FPSCLOCK.tick(FPS)
    return "Player 2 (Will) won" if game.lost else "Player 1 (Bill) won"