1 Star 0 Fork 0

Liereyy / ccai_ob_feeder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
type_defs.py 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
Liereyy 提交于 2023-09-23 21:34 . 1
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
Python
1
https://gitee.com/princesslaffey/ccai_ob_feeder.git
git@gitee.com:princesslaffey/ccai_ob_feeder.git
princesslaffey
ccai_ob_feeder
ccai_ob_feeder
master

搜索帮助