added to show the next piece
parent
4447e713a6
commit
2e718315a9
|
@ -34,6 +34,7 @@ class Afutc:
|
||||||
self.ghost = np.zeros(shape=(HEIGHT, WIDTH))
|
self.ghost = np.zeros(shape=(HEIGHT, WIDTH))
|
||||||
self.board_center = WIDTH // 2
|
self.board_center = WIDTH // 2
|
||||||
self.current_piece = None
|
self.current_piece = None
|
||||||
|
self.next_piece = None
|
||||||
self.score = 0
|
self.score = 0
|
||||||
self.char = "▣"
|
self.char = "▣"
|
||||||
self.debug = ""
|
self.debug = ""
|
||||||
|
@ -66,7 +67,25 @@ class Afutc:
|
||||||
row_str += self.char
|
row_str += self.char
|
||||||
else:
|
else:
|
||||||
row_str += " "
|
row_str += " "
|
||||||
print(f"║{row_str}║")
|
|
||||||
|
row_str = f"║{row_str}║"
|
||||||
|
|
||||||
|
piece = self.next_piece
|
||||||
|
piece_height, piece_width = piece.shape
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
row_str += " " + " NEXT".center(piece_width + 4)
|
||||||
|
if i == 1:
|
||||||
|
row_str += f" ╔{'═' * (piece_width + 2)}╗"
|
||||||
|
if i >= 2 and (i - 2) < piece_height:
|
||||||
|
row = "".join(self.char if value else " "
|
||||||
|
for value in piece[i - 2])
|
||||||
|
row_str += f" ║ {row} ║"
|
||||||
|
if i == (piece_height + 2):
|
||||||
|
row_str += f" ╚{'═' * (piece_width + 2)}╝"
|
||||||
|
|
||||||
|
print(row_str)
|
||||||
|
|
||||||
row = "═" * (self.board.shape[1])
|
row = "═" * (self.board.shape[1])
|
||||||
print(f"╚{row}╝")
|
print(f"╚{row}╝")
|
||||||
# print(str(self.pivot) + "\t" + self.debug)
|
# print(str(self.pivot) + "\t" + self.debug)
|
||||||
|
@ -99,9 +118,17 @@ class Afutc:
|
||||||
new_row = np.zeros(shape=(1, WIDTH))
|
new_row = np.zeros(shape=(1, WIDTH))
|
||||||
self.board = np.concatenate((new_row, upper, down))
|
self.board = np.concatenate((new_row, upper, down))
|
||||||
self.score += (10 * count) + (5 if count > 3 else 0)
|
self.score += (10 * count) + (5 if count > 3 else 0)
|
||||||
|
|
||||||
# Generate a new piece
|
# Generate a new piece
|
||||||
self.current_move.fill(0.)
|
self.current_move.fill(0.)
|
||||||
new_piece = np.array(choice(PIECES))
|
if not isinstance(self.current_piece, np.ndarray):
|
||||||
|
self.current_piece = np.array(choice(PIECES))
|
||||||
|
else:
|
||||||
|
self.current_piece = self.next_piece.copy()
|
||||||
|
new_piece = self.current_piece.copy()
|
||||||
|
|
||||||
|
self.next_piece = np.array(choice(PIECES))
|
||||||
|
|
||||||
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)
|
||||||
for i, row in enumerate(new_piece):
|
for i, row in enumerate(new_piece):
|
||||||
|
|
Loading…
Reference in New Issue