From e0c04e2cbfc94cecc0bf50f6841e30c65606095d Mon Sep 17 00:00:00 2001 From: PCwqyy Date: Tue, 8 Apr 2025 17:28:17 +0800 Subject: [PATCH 1/3] Rook --- .gitignore | 4 +++ core/BuiltinChess/Rook.py | 30 +++++++++++++++++++++++ core/BuiltinChess/Universal.py | 3 +++ core/Pos.py | 17 ++++++++++--- tempory note.md | 15 +++++++++++- "\347\211\271\346\256\212\347\202\271.md" | 2 +- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 core/BuiltinChess/Rook.py diff --git a/.gitignore b/.gitignore index d87ca8a..c33bba6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Add by PCwqyy + +.vscode/ + # Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,django,windows # Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,django,windows diff --git a/core/BuiltinChess/Rook.py b/core/BuiltinChess/Rook.py new file mode 100644 index 0000000..9f88819 --- /dev/null +++ b/core/BuiltinChess/Rook.py @@ -0,0 +1,30 @@ +from ..Chess import ChessBase +from ..Death import DeathBase +from ..Move import MoveBase +from ..Pos import Pos, PosSet +from ..Skill import SkillBase +from .Universal import * + +ROOK_DIRECTIONS=['left','right','left_up','left_down','right_up','right_down'] + +class RookMove(MoveBase): + def __init__(self, chess: ChessBase): + super().__init__(chess=chess) + def get_movable(self): + res=PosSet() + for dir in ROOK_DIRECTIONS: + now=self.owner.pos + while True: + now.go(dir) + if(not now.valid()): + break + res.add(now) + if(self.owner.board.has_chess(now)): + break + return res + def get_movable(self) -> "PosSet": + return PosSet() + def get_eatable(self) -> "PosSet": + return PosSet() + def on_moved(self): + pass \ No newline at end of file diff --git a/core/BuiltinChess/Universal.py b/core/BuiltinChess/Universal.py index c1228ad..d677a3e 100644 --- a/core/BuiltinChess/Universal.py +++ b/core/BuiltinChess/Universal.py @@ -5,8 +5,11 @@ from typing import TYPE_CHECKING, Callable, Optional if TYPE_CHECKING: from ..Chess import ChessBase TOP = 2 +'''顶角''' LEFT = 1 +'''左下角''' RIGHT = 3 +'''右下角''' # 这里还没有 Transferer... # 都是以 LEFT 为参考,重新写的相对方向函数 diff --git a/core/Pos.py b/core/Pos.py index 9b3513b..9dd95fd 100644 --- a/core/Pos.py +++ b/core/Pos.py @@ -3,10 +3,13 @@ romeNumber = {1: 'i', 2: 'ii', 3: 'iii', 4: 'iv', 5: 'v', 6: 'vi', 7: 'vii', 8: 'viii', 9: 'ix', 10: 'x', 11: 'xi', 12: 'xii', 13: 'xiii', 14: 'xiv'} numRome = {'i': 1, 'ii': 2, 'iii': 3, 'iv': 4, 'v': 5, 'vi': 6, 'vii': 7, 'viii': 8, 'ix': 9, 'x': 10, 'xi': 11, 'xii': 12, 'xiii': 13, 'xiv': 14} +directions=['left','right','right_down','right_up','left_up','left_'] from typing import TYPE_CHECKING if TYPE_CHECKING: from .Chess import ChessBase +BOARDSIZE=12 + class Pos: def __init__(self, bw: bool, x: int, y: int) -> None: self.bw = bw @@ -131,6 +134,11 @@ class Pos: return next_pos def go(self, method="left", det=1): + ''' + 走多步 + `method` 方向 + `det` 步数 + ''' res = Pos(self.bw, self.x, self.y) for i in range(det): getattr(res, method)() @@ -146,13 +154,14 @@ class Pos: return (self.bw, self.x, self.y) def valid(self): - if self.bw == 1: - return 1 <= self.x and self.x <= 11 and 1 <= self.y and self.y <= 11 - else: - return 1 <= self.x and self.x <= 12 and 1 <= self.y and self.y <= 12 + '''是否超出棋盘''' + delta = 1 if self.bw==1 else 0 + return 1 <= self.x and self.x <= BOARDSIZE-delta and \ + 1 <= self.y and self.y <= BOARDSIZE-delta @staticmethod def checkValid(bw: int, x: int, y: int): + '''是否超出棋盘''' return Pos(bw, x, y).valid() def toNAR(self): diff --git a/tempory note.md b/tempory note.md index ca86e88..6de1173 100644 --- a/tempory note.md +++ b/tempory note.md @@ -1,3 +1,16 @@ 1 左下角 2 顶角 -3 右下角 \ No newline at end of file +3 右下角 + +棋盘表示方法:~~想象一个苦读代码的PC~~ + +- 黑白格拆开为两个棋盘 + 每个棋盘都是半个正方形 + 所以白格棋盘边长12,黑格棋盘边长11 +- Python 字典存储棋子 `tuple(bw,x,y)->chess` +- 左下角为 0,0 +- 三个方向被表示为 + 0°: `left` `right` + 60°: `left_down` `right_up` + 120°: `left_up` `right_down` +- 对于对角方向,在前面加 `x_` \ No newline at end of file diff --git "a/\347\211\271\346\256\212\347\202\271.md" "b/\347\211\271\346\256\212\347\202\271.md" index f625fa4..01d9534 100644 --- "a/\347\211\271\346\256\212\347\202\271.md" +++ "b/\347\211\271\346\256\212\347\202\271.md" @@ -20,7 +20,7 @@ #### 5. factory -可以给自己旁边空余格子加一个 shell,要花分数。 +可以给自己旁边空余格子加一个 product,要花分数。 #### 6. scoring -- Gitee From bc1c4395c4c48aac808df1eb5e22c3db826ec4ec Mon Sep 17 00:00:00 2001 From: PCwqyy Date: Tue, 8 Apr 2025 17:45:51 +0800 Subject: [PATCH 2/3] Rubbish line delete --- core/Pos.py | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Pos.py b/core/Pos.py index 9dd95fd..f2ac0a2 100644 --- a/core/Pos.py +++ b/core/Pos.py @@ -3,7 +3,6 @@ romeNumber = {1: 'i', 2: 'ii', 3: 'iii', 4: 'iv', 5: 'v', 6: 'vi', 7: 'vii', 8: 'viii', 9: 'ix', 10: 'x', 11: 'xi', 12: 'xii', 13: 'xiii', 14: 'xiv'} numRome = {'i': 1, 'ii': 2, 'iii': 3, 'iv': 4, 'v': 5, 'vi': 6, 'vii': 7, 'viii': 8, 'ix': 9, 'x': 10, 'xi': 11, 'xii': 12, 'xiii': 13, 'xiv': 14} -directions=['left','right','right_down','right_up','left_up','left_'] from typing import TYPE_CHECKING if TYPE_CHECKING: from .Chess import ChessBase -- Gitee From 5fe1275fbee2bad17a3c21f4432ef777a701bcfb Mon Sep 17 00:00:00 2001 From: PCwqyy Date: Tue, 22 Apr 2025 10:50:17 +0800 Subject: [PATCH 3/3] gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c33bba6..bb81600 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Add by PCwqyy .vscode/ +ignore/ # Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,django,windows # Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,django,windows -- Gitee