@@ -12,6 +12,7 @@ function App() {
12
12
const moved = useRef < [ number , number ] | null > ( null ) ;
13
13
const loading = useRef ( false ) ;
14
14
const lossedChessItem = useRef < ChessItem | null > ( null ) ;
15
+ const debug = location . search . indexOf ( "debug" ) !== - 1 ;
15
16
16
17
const selectChess = ( item : ChessItem ) => {
17
18
if ( item . currPostion === selected ) return ;
@@ -63,6 +64,59 @@ function App() {
63
64
setNext ( steps ) ;
64
65
break ;
65
66
}
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
+ }
66
120
}
67
121
} ;
68
122
@@ -151,8 +205,9 @@ function App() {
151
205
return (
152
206
< Checkerboard >
153
207
< VirtualChessBoard ref = { containerRef } onTransitionEnd = { debounce ( onTransition ) } >
154
- { batchRender ( 90 ) . map ( ( item ) => (
208
+ { batchRender ( 90 ) . map ( ( item , i ) => (
155
209
< VirtualItem key = { item } >
210
+ { debug && < span > { i } </ span > }
156
211
< RenderChess
157
212
position = { item }
158
213
selected = { selected }
0 commit comments