add a bag of pieces

master
kirbylife 2021-04-04 17:18:14 -05:00
parent d7996f0d4d
commit af91918e7d
1 changed files with 9 additions and 2 deletions

View File

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