def __init__(self, size=3, init=None, check=True):
self.size = size
if init:
init = init.replace(' ', '')
if check and not isinstance(init, (str, basestring)):
raise ValueError("Init configuration must be a string")
if check and int(math.sqrt(len(init))) != math.sqrt(len(init)):
raise ValueError(
"Init configuration length must be a power of 2")
self.size = int(math.sqrt(self.size))
self.squares = init
else:
self.squares = '.' * (self.size * self.size)
评论列表
文章目录