예제 #1
0
def playGame():
    game = Tetris(numColors=MAXCOLORS, numColumns=10, numRows=10)
    ai = AI(function)
    # loop count variables:
    numTicks = 0
    while not game.lost:  # game loop ends when game is lost
        ai.ai(game, display=False)
        game.incrementTime()
        numTicks += 1
    return game.numLines
예제 #2
0
def playGame():
    game = Tetris(numColors=MAXCOLORS)
    ai = AI(function)
    # loop count variables:
    numPieces = 0
    sumHeights = 0
    while not game.lost and game.numPieces < 200:  # game loop ends when game is lost
        ai.ai(game)
        game.incrementTime()
        if game.numPieces > numPieces:
            sumHeights += height(game)
            numPieces += 1
    return (game.numLines, sumHeights / numPieces)
예제 #3
0
def playGame():
    game = Tetris(numColors=MAXCOLORS)
    ai = AI()

    # a dictionary of pygame buttons and their functions:
    global AI_BUTTON
    AI_BUTTON = pygame.Rect(
        (WINDOWWIDTH - 122, 300, 50, 30))  # ai enable button

    render(game)

    # loop count variables:
    numTicks = 0
    timeSinceIncrement = 0

    pressedKeys = [-1, -1, -1, -1]  # up, down, left, right
    while not game.lost:  # game loop ends when game is lost

        if INPUT: handleInput(game, pressedKeys, numTicks)
        else:
            for event in pygame.event.get():  # event handling loop
                if event.type == pygame.QUIT:
                    terminate()  # exit game

        # increment time (move blocks down)
        if timeSinceIncrement > DELAY:  # number of ticks between time increments

            if not INPUT: ai.ai(game)

            game.incrementTime()
            timeSinceIncrement = 0
            render(game)

        FPSCLOCK.tick(FPS)
        numTicks += 1
        timeSinceIncrement += 1
    return "Game Over"
def playGame():
    seed = int(time.time())
    game = Tetris(numColors=MAXCOLORS, seed=seed)
    aiGame = Tetris(numColors=MAXCOLORS, seed=seed)
    ai = AI()
    render(game, aiGame)

    DELAY = 20  # delay between each incrementTime

    # loop count variables:
    numTicks = 0
    timeSinceIncrement = 0
    level = 0
    pressedKeys = [-1, -1, -1, -1]  # up, down, left, right
    while not game.lost or aiGame.lost:  # game loop ends when game is lost

        updated = handleInput(game, pressedKeys, numTicks)
        while aiGame.numTurns < game.numTurns:
            ai.ai(aiGame)
            aiGame.incrementTime()
            if game.numTurns - aiGame.numTurns % 10 == 0 or game.numTurns - aiGame.numTurns % 5 < 10:
                render(game, aiGame)
        if updated:
            render(game, aiGame)
        if timeSinceIncrement > DELAY:  # number of ticks between time increments
            game.incrementTime()
            timeSinceIncrement = 0
            render(game, aiGame)
        if game.numLines // 10 > level:
            level = game.numLines // 10
            DELAY = DELAY * 0.8

        FPSCLOCK.tick(FPS)
        numTicks += 1
        timeSinceIncrement += 1

    return "Game Over" if game.lost else "You Win!"