agent = Agent() sample = 'waiting' solver = Solver() playfield = Playfield() current_tetromino = agent.start_game() block_num = 0 game_over = False while not game_over: block_num += 1 # decide outcome chosen_outcome = solver.decide_outcome(playfield, current_tetromino) # execute outcome next_shape = agent.execute_outcome_and_sample(chosen_outcome, interval=0.04, sleep=0.4) playfield.execute_outcome(chosen_outcome, current_tetromino) # decode old sample and get new sample try: current_tetromino = Tetromino(next_shape) except: game_over = True print('GAME OVER, {} blocks placed'.format(block_num))
filter(lambda outcome: outcome['cost'] == lowest_cost, outcomes)) # if None was swapped out, ban hold for next turn self.ban_hold = outcomes[0]['tetromino'] == None # With multiple lowest cost outcomes, selection is only affected by # number of keystrokes outcome requires. The lowest outcome in the # list is more likely to not require swap and not require any # rotations return outcomes[0] if __name__ == "__main__": solver = Solver() playfield = Playfield() game_over = False shape = random.choice(Tetromino.SHAPES) tetromino = Tetromino(shape) tetromino = playfield.hold_tetromino(tetromino) score = 0 while not game_over: shape = random.choice(Tetromino.SHAPES) tetromino = Tetromino(shape) chosen_outcome = solver.decide_outcome(playfield, tetromino) playfield.execute_outcome(chosen_outcome, tetromino) print('score = {}, cost = {}'.format(score, chosen_outcome['cost'])) print(playfield) score += 1 print('GAME OVER, score = {}'.format(score)) print(chosen_outcome)