|
|
@@ -1,4 +1,6 @@
|
|
|
+import io
|
|
|
import time
|
|
|
+from contextlib import redirect_stdout
|
|
|
from itertools import combinations, islice
|
|
|
from parse import COLUMNS, NOBLOCK, detect_blocks, detect_exa, \
|
|
|
detect_held, print_board, is_basic, is_bomb, bomb_to_basic
|
|
|
@@ -45,8 +47,8 @@ class State:
|
|
|
yield gen_col(col)
|
|
|
|
|
|
@classmethod
|
|
|
- def detect(cls, board):
|
|
|
- blocks = [NOBLOCK] * (COLUMNS * 2) + list(detect_blocks(board))
|
|
|
+ def detect(cls, board, pad=2):
|
|
|
+ blocks = [NOBLOCK] * (COLUMNS * pad) + list(detect_blocks(board))
|
|
|
exa = detect_exa(board)
|
|
|
held = detect_held(board, exa)
|
|
|
return cls(blocks, exa, held)
|
|
|
@@ -325,6 +327,12 @@ class State:
|
|
|
def print(self):
|
|
|
print_board(self.blocks, self.exa, self.held)
|
|
|
|
|
|
+ def tostring(self):
|
|
|
+ stream = io.StringIO()
|
|
|
+ with redirect_stdout(stream):
|
|
|
+ self.print()
|
|
|
+ return stream.getvalue()
|
|
|
+
|
|
|
def nrows(self):
|
|
|
return len(self.blocks) // COLUMNS
|
|
|
|