代码拉取完成,页面将自动刷新
from config import config
def flip_pos(flip, npos, bias=0):
if flip:
return (8 - npos[0]) * config.intX + bias, (9 - npos[1]) * config.intY + bias
else:
return npos[0] * config.intX + bias, npos[1] * config.intY + bias
class Piece:
def __init__(self, id, npos=None):
self.id = id
self.name = 'pane' if id == 'pane' else id[0:3]
self.pixmap_path = f"./assets/{self.name}.png"
self.visible = False # draw if True
self.nx = None
self.ny = None
self.set_npos(npos)
def x(self):
return self.nx * config.intX if self.nx else 0
def y(self):
return self.ny * config.intY if self.ny else 0
def npos(self):
return self.nx, self.ny
def set_npos(self, npos):
if npos:
self.visible = True
self.nx = npos[0]
self.ny = npos[1]
def __repr__(self):
return self.id
class PieceBoard:
def __init__(self):
self.data: list[list[Piece]] = []
self.pieces = {}
self.initPos = {}
for ny in range(10):
self.data.append([])
for nx in range(9):
self.data[ny].append(None)
if config.initBoard[ny][nx] != '':
self.pieces[config.initBoard[ny][nx]] = Piece(config.initBoard[ny][nx], (nx, ny))
self.initPos[config.initBoard[ny][nx]] = nx, ny
self.init()
def init(self):
for ny in range(10):
for nx in range(9):
self.data[ny][nx] = None
for key in self.pieces:
p = self.pieces[key]
p.visible = True
p.set_npos(self.initPos[p.id])
self.data[p.ny][p.nx] = p
def to_string_board(self):
board = []
for i in range(10):
board.append([])
for j in range(9):
board[i].append(self.data[i][j].name if self.data[i][j] else None)
return board
def __getitem__(self, item):
assert isinstance(item, int)
assert 0 <= int(item) <= 9
return self.data[item]
def __repr__(self):
res = ''
for ny in range(10):
for nx in range(9):
res += self.data[ny][nx].id + ' ' if self.data[ny][nx] else ' '
res += '\n'
return res
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。