def run(): root = Tk() # Try making window a dialog if the system allows it. try: root.attributes('-type', 'dialog') except TclError: pass args = parser.parse_args() if args.manual: player = UserPlayer(root) else: player = SelectedPlayer() adversary = RandomAdversary(DEFAULT_SEED) board = Board(BOARD_WIDTH, BOARD_HEIGHT) def runner(): for move in board.run(player, adversary): # When not playing manually, allow some time to see the move. if not args.manual: sleep(0.001) Visual(board) background = Thread(target=runner) background.daemon = True background.start() root.mainloop() raise SystemExit
def run(): board = Board(BOARD_WIDTH, BOARD_HEIGHT) adversary = RandomAdversary(DEFAULT_SEED) args = parser.parse_args() if args.manual: player = UserPlayer() else: player = SelectedPlayer() pygame.init() screen = pygame.display.set_mode([(BOARD_WIDTH + 6) * CELL_WIDTH, BOARD_HEIGHT * CELL_HEIGHT]) clock = pygame.time.Clock() # Set timer to force block down when no input is given. pygame.time.set_timer(EVENT_FORCE_DOWN, INTERVAL) for move in board.run(player, adversary): render(screen, board) pygame.display.flip() # If we are not playing manually, clear the events. if not args.manual: check_stop() clock.tick(FRAMES_PER_SECOND) while True: check_stop()
def run(window, seed): global score board = Board(BOARD_WIDTH, BOARD_HEIGHT) adversary = RandomAdversary(seed, BLOCK_LIMIT) args = parser.parse_args() if args.manual: window.timeout(INTERVAL) player = UserPlayer(window) else: window.timeout(0) player = SelectedPlayer() try: for move in board.run(player, adversary): render(window, board) if not args.manual: while True: key = window.getch() if key == -1: break elif key == curses.ascii.ESC: raise SystemExit #sleep(0.1) finally: score = board.score
def run(window): board = Board(BOARD_WIDTH, BOARD_HEIGHT) adversary = RandomAdversary(DEFAULT_SEED) args = parser.parse_args() if args.manual: window.timeout(INTERVAL) player = UserPlayer(window) else: window.timeout(0) player = SelectedPlayer() for move in board.run(player, adversary): render(window, board) if not args.manual: while True: key = window.getch() if key == -1: break elif key == curses.ascii.ESC: raise SystemExit sleep(0.1) window.timeout(-1) window.getch()
def run(seed, player): board = Board(BOARD_WIDTH, BOARD_HEIGHT) adversary = RandomAdversary(seed=seed) for move in board.run(player=player, adversary=adversary): pass return board.score
def run(window): board = Board(BOARD_WIDTH, BOARD_HEIGHT) adversary = RandomAdversary(DEFAULT_SEED) args = parser.parse_args() if args.manual: window.timeout(INTERVAL) player = UserPlayer(window) else: window.timeout(0) player = SelectedPlayer() for move in board.run(player, adversary): render(window, board) if not args.manual: while True: key = window.getch() if key == -1: break elif key == curses.ascii.ESC: raise SystemExit sleep(0.1) # window.timeout(-1) window.getch() try: fin = open('scores.txt', 'r') content = fin.readlines() fin.close() content.append(str(board.score) + '\n') except FileNotFoundError: content = [f'{board.score}\n'] fin = open('scores.txt', 'w') fin.writelines(content) fin.close()
return Direction(instruction) except ValueError: pass try: return Rotation(instruction) except ValueError: pass raise UnknownInstructionException board = Board(BOARD_WIDTH, BOARD_HEIGHT) player = RemotePlayer() adversary = RandomAdversary(getenv('SEED'), BLOCK_LIMIT) score = 0 try: for move in board.run(player, adversary): if isinstance(move, Shape): print(f'{PREFIX} {move.value}') if board.score != score: stderr.write(f'{board.score}\n') score = board.score except BlockLimitException: stderr.write('WON\n') print(f'{PREFIX} WON') else: