from board import Board from heuristics import Heuristicizer from tetromino import Tetromino import queue import random import time tetrominos = { 1: Tetromino.OTet(), 2: Tetromino.ITet(), 3: Tetromino.JTet(), 4: Tetromino.LTet(), 5: Tetromino.STet(), 6: Tetromino.ZTet(), 7: Tetromino.TTet(), } tets = [1, 2, 3, 4, 5, 6, 7] random.shuffle(tets) q = queue.Queue(maxsize=20) if __name__ == '__main__': board = Board() while board.board_height() < board.HEIGHT: for tet in tets: q.put(tet) while not q.empty(): t = tetrominos[q.get()] h = Heuristicizer.get_drop(t, board) turns = h['t_rot']
min_gaps = float('inf') min_height = float('inf') for drop in drops: min_gaps = min(min_gaps, drop['b_gaps']) drops = list(filter(lambda drop: drop['b_gaps'] == min_gaps, drops)) for drop in drops: min_height = min(min_height, drop['b_height']) drops = list(filter(lambda drop: drop['b_height'] == min_height, drops)) for drop in drops: min_row = min(min_row, drop['t_row']) drops = list(filter(lambda drop: drop['t_row'] == min_row, drops)) return drops[0] if __name__ == '__main__': b = Board() b.drop(Tetromino.OTet(), 3) print(b) h = Heuristicizer.get_drop(Tetromino.ITet(), b) b.drop(Tetromino.ITet(), h['t_col']) print(b) h2 = Heuristicizer.get_drop(Tetromino.JTet(), b) b.drop(Tetromino.JTet(), h2['t_col']) print(b) print(h2['t_rot'])