コード例 #1
0
    return keys


if __name__ == '__main__':
    mouse = detect_mouse()
    print("Mouse coordinates: {}".format(mouse))
    field = Field()
    print("First tetromino:")
    current_tetromino = Tetromino.create(input())
    next_tetromino = None
    time.sleep(2)
    while True:
        next_tetromino = TETROMINO[get_pixel(mouse)]()
        opt = Optimizer.get_optimal_drop(field, current_tetromino)
        rotation = opt['tetromino_rotation']
        column = opt['tetromino_column']
        current_tetromino.rotate(rotation)
        field.drop(current_tetromino, column)
        keys = Optimizer.get_keystrokes(
            rotation, column, {
                'rotate_right': 'x',
                'rotate_left': 'z',
                'move_left': 'left',
                'move_right': 'right',
                'drop': ' '
            })
        pyautogui.typewrite(keys)
        print(field)
        current_tetromino = next_tetromino
        time.sleep(0.2)
コード例 #2
0
ファイル: test.py プロジェクト: evilcat311/tetris-bot
from optimizer import Optimizer
from tetromino import Tetromino

import pyautogui
import time

if __name__ == '__main__':
    field = Field()
    tetromino = None
    key = input()
    while True:
        if key in Tetromino.TYPES:
            tetromino = Tetromino.create(key)
            opt = Optimizer.get_optimal_drop(field, tetromino)
            rotation = opt['tetromino_rotation']
            column = opt['tetromino_column']
            tetromino.rotate(rotation)
            field.drop(tetromino, column)
            keys = Optimizer.get_keystrokes(
                rotation, column, {
                    'rotate_right': 'x',
                    'rotate_left': 'z',
                    'move_left': 'left',
                    'move_right': 'right',
                    'drop': ' '
                })
            print(field)
        else:
            print("Invalid input")
        key = input()
コード例 #3
0
ファイル: optimizer.py プロジェクト: lhhong/skrubs
        if rotation == 1:
            keys.append(keymap['rotate_right'])
        elif rotation == 2:
            keys.append(keymap['rotate_right'])
            keys.append(keymap['rotate_right'])
        elif rotation == 3:
            keys.append(keymap['rotate_left'])
        # Then we move it all the way to the the left that we are guaranteed
        # that it is at column 0. The main reason for doing this is that when
        # the tetromino is rotated, the bottom-leftmost piece in the tetromino
        # may not be in the 3rd column due to the way Tetris rotates the piece
        # about a specific point. There are too many edge cases so instead of
        # implementing tetromino rotation on the board, it's easier to just
        # flush all the pieces to the left after orienting them.
        for i in range(4):
            keys.append(keymap['move_left'])
        # Now we can move it back to the correct column. Since pyautogui's
        # typewrite is instantaneous, we don't have to worry about the delay
        # from moving it all the way to the left.
        for i in range(column):
            keys.append(keymap['move_right'])
        keys.append(keymap['drop'])
        return keys

if __name__ == '__main__':
    f = Field()
    f.drop(Tetromino.TTetromino(), 3)
    opt = Optimizer.get_optimal_drop(
        f['tetromino_rotation'], f['tetromino_column'], Tetromino.ITetromino())
    print(opt['field'])