Esempio n. 1
0
    def dev_height(self):
        return np.std(self.heights())

    def rating(self, weights):
        factors = np.array([
            self.count_gaps(),
            self.max_height(),
            self.avg_height(),
            self.dev_height()
        ])
        return (factors * weights).sum()


if __name__ == '__main__':
    f = Field()
    f.drop(Tetromino.ITetromino(), 6)
    f.drop(Tetromino.ITetromino(), 2)
    f.drop(Tetromino.OTetromino(), 3)
    f.drop(Tetromino.JTetromino().rotate_left(), 0)
    f.drop(Tetromino.JTetromino().rotate_left(), 2)
    f.drop(Tetromino.OTetromino(), 5)
    f.drop(Tetromino.OTetromino(), 7)
    f.drop(Tetromino.ITetromino(), 6)
    f.drop(Tetromino.OTetromino(), 5)
    print(f)
    print(f.count_gaps())
    print(f.max_height())
    print(f.avg_height())
    print(f.dev_height())
    print(f.rating(np.array([-2, -0.1, -0.2, -1.5])))
    # import sys
Esempio n. 2
0
        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'])
Esempio n. 3
0
        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'])