From c0011f15da39507a1563aeee7f7f414160a0cfb3 Mon Sep 17 00:00:00 2001 From: haozexu Date: Wed, 23 Oct 2024 10:37:20 +0800 Subject: [PATCH 1/3] classDiagram --- classDiagram.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 classDiagram.md diff --git a/classDiagram.md b/classDiagram.md new file mode 100644 index 0000000..f25ad87 --- /dev/null +++ b/classDiagram.md @@ -0,0 +1,55 @@ +# Class Diagram +## Basic +```mermaid +classDiagram +class NARPos{ + x int + y int + z int + nextInX() NARPos + nextInY() NARPos + nextInZ() NARPos +} +class Hook{ + owner Any + handler(**kwargs) Any +} +note for Cell "onMove将在落子时调用\n用于向死亡消息队列\n发送死亡消息" +note for Cell "onConfirm是在移动质询时会调用的" +class Cell{ + pos NARPos + chess AbstractChess + onMove Hook + onConfirm Hook +} +note for AbstractChess "onDeath 是死亡通知\n不只是该棋子的\n onMove if needed" +note for AbstractChess "onCanExecute 被动执行器" +class AbstractChess{ + name string + pos NARPos + onDeath Hook + onConfirm Hook + onCanExecute Hook + register() void + moveRange() list[Cell] + canMoveTo(c:Cell) bool +} +``` +## Chess +```mermaid +classDiagram +class AbstractChess{ + name string + pos NARPos + onDeath Hook + onConfirm Hook + onCanExecute Hook + register() void + moveRange() list[Cell] + canMoveTo(c:Cell) bool +} +class Pond{ + +} +AbstractChess<|--Pond +``` \ No newline at end of file -- Gitee From f6e1fe02606d0e7a58b02d06ba97e4a1f5d2a529 Mon Sep 17 00:00:00 2001 From: haozexu Date: Wed, 23 Oct 2024 10:45:11 +0800 Subject: [PATCH 2/3] classDiagram 2 --- classDiagram.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/classDiagram.md b/classDiagram.md index f25ad87..85ebf4c 100644 --- a/classDiagram.md +++ b/classDiagram.md @@ -21,18 +21,25 @@ class Cell{ chess AbstractChess onMove Hook onConfirm Hook + register() void } note for AbstractChess "onDeath 是死亡通知\n不只是该棋子的\n onMove if needed" note for AbstractChess "onCanExecute 被动执行器" class AbstractChess{ name string - pos NARPos + pos Cell onDeath Hook onConfirm Hook onCanExecute Hook register() void moveRange() list[Cell] - canMoveTo(c:Cell) bool + canMoveTo(c Cell) bool +} +note for Mover "onMove是用来检查 shooter 的" +class Mover{ + onMove Hook + register() void + tryMoveTo(chess AbstractChess,pos Cell) } ``` ## Chess @@ -40,7 +47,7 @@ class AbstractChess{ classDiagram class AbstractChess{ name string - pos NARPos + pos Cell onDeath Hook onConfirm Hook onCanExecute Hook -- Gitee From 4bb47f56600b3c40f6b541cd7792432c39be8b80 Mon Sep 17 00:00:00 2001 From: haozexu Date: Fri, 25 Oct 2024 17:10:47 +0800 Subject: [PATCH 3/3] basic class - board and hooks --- Design - Backend.md | 3 +++ classDiagram.md | 41 ++++++++++++++++++++++++------ core/Board.py | 37 +++++++++++++++++++++++++++ core/Chess/AbstractChess.py | 0 core/Chess/Bishop.py | 0 core/Chess/Pond.py | 0 core/GameState.py | 0 core/Hook.py | 50 +++++++++++++++++++++++++++++++++++++ core/HookMan.py | 0 core/MsgQueue.py | 0 10 files changed, 124 insertions(+), 7 deletions(-) delete mode 100644 core/Chess/AbstractChess.py delete mode 100644 core/Chess/Bishop.py delete mode 100644 core/Chess/Pond.py delete mode 100644 core/GameState.py delete mode 100644 core/HookMan.py delete mode 100644 core/MsgQueue.py diff --git a/Design - Backend.md b/Design - Backend.md index 9d195de..05aa26c 100644 --- a/Design - Backend.md +++ b/Design - Backend.md @@ -64,9 +64,12 @@ 循环执行,被直接吃掉的棋子的死亡广播会播放到死亡监视器并调用所有棋子注册的死亡监视 HOOK,以便执行联动操作,原则上,棋子的死亡回调中只应该监视自己的死亡消息并触发被动,但是不排除会有监视其他棋子的。当消息队列为空时转到下一个阶段。 +注意处理 trap + ##### 3.3.4 技能执行阶段 调用所有棋子注册的被动执行器,例如雇佣兵的,工厂的 +注意,兵的升变也在这里进行 ##### 3.3.5 状态更新阶段 diff --git a/classDiagram.md b/classDiagram.md index 85ebf4c..6a56b54 100644 --- a/classDiagram.md +++ b/classDiagram.md @@ -12,7 +12,27 @@ class NARPos{ } class Hook{ owner Any - handler(**kwargs) Any + handler(args dict) Any +} +class Msg{ + type string + sender Any + args dict +} +class MsgQueue{ + msgs list[Msg] + push(msg Msg) + peek(msg Msg) + get(msg Msg) + remove(msg Msg) + clear(msg Msg) +} +class HookCenter{ + hooks list[Hook] + msgs MsgQueue + register(target Hook) + unregister(target Hook) + filter(owner Any) } note for Cell "onMove将在落子时调用\n用于向死亡消息队列\n发送死亡消息" note for Cell "onConfirm是在移动质询时会调用的" @@ -35,13 +55,18 @@ class AbstractChess{ moveRange() list[Cell] canMoveTo(c Cell) bool } -note for Mover "onMove是用来检查 shooter 的" -class Mover{ - onMove Hook - register() void - tryMoveTo(chess AbstractChess,pos Cell) +``` +## Board +```mermaid +classDiagram +class Board{ + board dict + } ``` +哎呀不画了,反着就是拆成两个棋盘 + +前端对接的时候写个转接口就行了 ## Chess ```mermaid classDiagram @@ -51,6 +76,7 @@ class AbstractChess{ onDeath Hook onConfirm Hook onCanExecute Hook + owner Player register() void moveRange() list[Cell] canMoveTo(c:Cell) bool @@ -59,4 +85,5 @@ class Pond{ } AbstractChess<|--Pond -``` \ No newline at end of file +``` +棋子移动范围由每个棋子计算,@staticmethod \ No newline at end of file diff --git a/core/Board.py b/core/Board.py index e69de29..41e547d 100644 --- a/core/Board.py +++ b/core/Board.py @@ -0,0 +1,37 @@ +class Pos: + def __init__(self,bw:bool,x:int,y:int) -> None: + self.bw=bw + self.x=x + self.y=y + def left(self,det=1): + return Pos(self.x-det) + def right(self,det=1): + return Pos(self.x+det) + def up(self,det=1): + return Pos(self.x-det,self.y+det*2) + def down(self,det=1): + return Pos(self.x+det,self.y-det*2) + def from_nar(): + pass + def from_xy(): + pass + def to_nar(): + pass + def from_xy(): + pass + def real_left(): + pass + def real_right(): + pass + def real_up(): + pass + def real_down(): + pass + +class Cell: + def __init__(self) -> None: + pass + +class Board: + def __init__(self) -> None: + pass diff --git a/core/Chess/AbstractChess.py b/core/Chess/AbstractChess.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/Chess/Bishop.py b/core/Chess/Bishop.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/Chess/Pond.py b/core/Chess/Pond.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/GameState.py b/core/GameState.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/Hook.py b/core/Hook.py index e69de29..c3777cd 100644 --- a/core/Hook.py +++ b/core/Hook.py @@ -0,0 +1,50 @@ +from typing import Any +import queue + +class Hook: + def __init__(self,owner:Any,handler:function) -> None: + self.owner=owner + self.handler=handler + def call(self,args:dict): + self.handler(args) + +class Msg: + def __init__(self,sender:Any,txt:str,arg:dict) -> None: + self.sender=sender + self.type=txt + self.arg=arg + +class HookMan: + def __init__(self) -> None: + self.hooks:list[Hook]=[] + self.msgq=queue.Queue() + def register(self,target:Hook): + self.hooks.append(target) + def unregister(self,target:Hook): + if self.hooks.count(target)>0: + self.hooks.remove(target) + def remove(self,muli:list[Hook]): + for i in muli: + self.unregister(i) + def postmsg(self,msg:Msg): + self.msgq.put_nowait(msg) + def peekmsg(self): + return self.msgq.get_nowait() + def filter(self,owner:Any): + res:list[Hook]=[] + for i in self.hooks: + if i.owner==owner: + res.append(i) + return res + def call(self,arg:dict): + for i in self.hooks: + i.call(args=arg) + def boardcast(self,msg:Msg): + for i in self.hooks: + i.call({'msg':msg}) + def deal_msg(self): + if self.msgq.empty(): + return False + while self.msgq.empty()==False: + self.boardcast(self.peekmsg()) + return True \ No newline at end of file diff --git a/core/HookMan.py b/core/HookMan.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/MsgQueue.py b/core/MsgQueue.py deleted file mode 100644 index e69de29..0000000 -- Gitee