add a bag of pieces
parent
d7996f0d4d
commit
af91918e7d
|
@ -1,6 +1,7 @@
|
|||
import curses
|
||||
from _curses import error as CursesException
|
||||
from random import choice
|
||||
from random import random
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
|
@ -21,6 +22,9 @@ def catch(func, default=..., args=[], kwargs={}):
|
|||
else:
|
||||
return default
|
||||
|
||||
def pouch():
|
||||
while True:
|
||||
yield from sorted(PIECES, key=lambda _: random())
|
||||
|
||||
class Afutc:
|
||||
running = True
|
||||
|
@ -32,6 +36,7 @@ class Afutc:
|
|||
self.print = lambda x, color=0: stdscr.addstr(x,
|
||||
curses.color_pair(color))
|
||||
self.input = stdscr.getkey
|
||||
self.pouch = pouch()
|
||||
self.is_paused = False
|
||||
self.board = np.zeros(shape=(HEIGHT, WIDTH))
|
||||
self.current_move = np.zeros(shape=(HEIGHT, WIDTH))
|
||||
|
@ -133,12 +138,14 @@ class Afutc:
|
|||
# Generate a new piece
|
||||
self.current_move.fill(0.)
|
||||
if not isinstance(self.current_piece, np.ndarray):
|
||||
self.current_piece = np.array(choice(PIECES))
|
||||
# self.current_piece = np.array(choice(PIECES))
|
||||
self.current_piece = np.array(next(self.pouch))
|
||||
else:
|
||||
self.current_piece = self.next_piece.copy()
|
||||
new_piece = self.current_piece.copy()
|
||||
|
||||
self.next_piece = np.array(choice(PIECES))
|
||||
# self.next_piece = np.array(choice(PIECES))
|
||||
self.next_piece = np.array(next(self.pouch))
|
||||
|
||||
self.current_piece = new_piece.copy()
|
||||
position = self.board_center - (new_piece.shape[1] // 2)
|
||||
|
|
Loading…
Reference in New Issue