Skip to content

Commit dec3972

Browse files
committed
update
1 parent 7d375e3 commit dec3972

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
## 下一步
44

5-
- [ ] 嗅探双方相的行进路线
5+
- [ ] 过滤炮和车的可行性路线
66

77
## 已完成
88

9+
- [x] 嗅探炮和车的行进路线
10+
- [x] 嗅探双方相的行进路线
911
- [x] 士的进行日志
1012
- [x] 兵/卒 横向移动的日志
1113
- [x] 嗅探兵和卒过河之后的行进路线

src/App.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function App() {
1212
const moved = useRef<[number, number] | null>(null);
1313
const loading = useRef(false);
1414
const lossedChessItem = useRef<ChessItem | null>(null);
15+
const debug = location.search.indexOf("debug") !== -1;
1516

1617
const selectChess = (item: ChessItem) => {
1718
if (item.currPostion === selected) return;
@@ -63,6 +64,59 @@ function App() {
6364
setNext(steps);
6465
break;
6566
}
67+
case "相": {
68+
const newPosition = [position - 16, position + 16, position - 20, position + 20]
69+
.filter((item) => item > 46 && item < 88)
70+
.filter((item) => item !== 79 && item !== 73 && item !== 55);
71+
setNext(newPosition);
72+
break;
73+
}
74+
case "象": {
75+
const newPosition = [position - 16, position + 16, position - 20, position + 20]
76+
.filter((item) => item > 1 && item < 43)
77+
.filter((item) => item !== 10 && item !== 34);
78+
setNext(newPosition);
79+
break;
80+
}
81+
case "炮":
82+
case "車": {
83+
const currPosition = position % 9;
84+
const next: number[] = [];
85+
86+
let markLeftPosition = position;
87+
let markRightPosition = position;
88+
let markTopPosition = position;
89+
let markBottomPosition = position;
90+
91+
let left = currPosition;
92+
let right = currPosition;
93+
94+
while (left > 0) {
95+
next.push(markLeftPosition - 1);
96+
markLeftPosition--;
97+
left--;
98+
}
99+
100+
while (right < 8) {
101+
next.push(markRightPosition + 1);
102+
markRightPosition++;
103+
right++;
104+
}
105+
106+
while (markTopPosition - 9 > 0) {
107+
next.push(markTopPosition - 9);
108+
markTopPosition -= 9;
109+
}
110+
111+
while (markBottomPosition + 9 < 90) {
112+
next.push(markBottomPosition + 9);
113+
markBottomPosition += 9;
114+
}
115+
116+
setNext(next);
117+
118+
break;
119+
}
66120
}
67121
};
68122

@@ -151,8 +205,9 @@ function App() {
151205
return (
152206
<Checkerboard>
153207
<VirtualChessBoard ref={containerRef} onTransitionEnd={debounce(onTransition)}>
154-
{batchRender(90).map((item) => (
208+
{batchRender(90).map((item, i) => (
155209
<VirtualItem key={item}>
210+
{debug && <span>{i}</span>}
156211
<RenderChess
157212
position={item}
158213
selected={selected}

0 commit comments

Comments
 (0)