Beispiel #1
0
def evaluate(seq):
    import sys
    f = Field()
    from optimizer import Optimizer
    answer = []
    for i in range(len(seq)):
        t = Tetromino.create(seq[i])
        try:
            opt = Optimizer.get_optimal_drop(f, t)
            t.rotate(opt['tetromino_rotation'])
            f.drop(t, opt['tetromino_column'])
        except:
            opt = {"tetromino_rotation": 0, "tetromino_column": 0}
        action = int(
            str(opt['tetromino_rotation']) + str(opt['tetromino_column']))
        answer.append(action)
        # print(f, t, i, action)
    return answer
Beispiel #2
0
from field import Field
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")
Beispiel #3
0
        keys.append(keymap['move_right'])
    keys.append(keymap['drop'])
    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