143 <a class="c2html-lineno" name="l90" href="#l90"> 90 </a> <span class="c2html-comment">/* start by notating the piece character */</span> |
143 <a class="c2html-lineno" name="l90" href="#l90"> 90 </a> <span class="c2html-comment">/* start by notating the piece character */</span> |
144 <a class="c2html-lineno" name="l91" href="#l91"> 91 </a> string[<span class="c2html-macroconst">0</span>] = getpiecechr(move->piece); |
144 <a class="c2html-lineno" name="l91" href="#l91"> 91 </a> string[<span class="c2html-macroconst">0</span>] = getpiecechr(move->piece); |
145 <a class="c2html-lineno" name="l92" href="#l92"> 92 </a> <span class="c2html-keyword">int</span> idx = string[<span class="c2html-macroconst">0</span>] ? <span class="c2html-macroconst">1</span> : <span class="c2html-macroconst">0</span>; |
145 <a class="c2html-lineno" name="l92" href="#l92"> 92 </a> <span class="c2html-keyword">int</span> idx = string[<span class="c2html-macroconst">0</span>] ? <span class="c2html-macroconst">1</span> : <span class="c2html-macroconst">0</span>; |
146 <a class="c2html-lineno" name="l93" href="#l93"> 93 </a> |
146 <a class="c2html-lineno" name="l93" href="#l93"> 93 </a> |
147 <a class="c2html-lineno" name="l94" href="#l94"> 94 </a> <span class="c2html-comment">/* find out how many source information we do need */</span> |
147 <a class="c2html-lineno" name="l94" href="#l94"> 94 </a> <span class="c2html-comment">/* find out how many source information we do need */</span> |
148 <a class="c2html-lineno" name="l95" href="#l95"> 95 </a> <span class="c2html-type">uint8_t</span> piece = move->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
148 <a class="c2html-lineno" name="l95" href="#l95"> 95 </a> <span class="c2html-type">uint8_t</span> piece = move->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
149 <a class="c2html-lineno" name="l96" href="#l96"> 96 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span>) { |
149 <a class="c2html-lineno" name="l96" href="#l96"> 96 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span>) { |
150 <a class="c2html-lineno" name="l97" href="#l97"> 97 </a> <span class="c2html-keyword">if</span> (move->capture) { |
150 <a class="c2html-lineno" name="l97" href="#l97"> 97 </a> <span class="c2html-keyword">if</span> (move->capture) { |
151 <a class="c2html-lineno" name="l98" href="#l98"> 98 </a> string[idx++] = filechr(move->fromfile); |
151 <a class="c2html-lineno" name="l98" href="#l98"> 98 </a> string[idx++] = filechr(move->fromfile); |
152 <a class="c2html-lineno" name="l99" href="#l99"> 99 </a> } |
152 <a class="c2html-lineno" name="l99" href="#l99"> 99 </a> } |
153 <a class="c2html-lineno" name="l100" href="#l100">100 </a> } <span class="c2html-keyword">else</span> <span class="c2html-keyword">if</span> (piece != <span class="c2html-macroconst">KING</span>) { |
153 <a class="c2html-lineno" name="l100" href="#l100">100 </a> } <span class="c2html-keyword">else</span> <span class="c2html-keyword">if</span> (piece != <span class="c2html-macroconst">KING</span>) { |
154 <a class="c2html-lineno" name="l101" href="#l101">101 </a> Move threats[<span class="c2html-macroconst">16</span>]; |
154 <a class="c2html-lineno" name="l101" href="#l101">101 </a> Move threats[<span class="c2html-macroconst">16</span>]; |
155 <a class="c2html-lineno" name="l102" href="#l102">102 </a> <span class="c2html-type">uint8_t</span> threatcount; |
155 <a class="c2html-lineno" name="l102" href="#l102">102 </a> <span class="c2html-type">uint8_t</span> threatcount; |
156 <a class="c2html-lineno" name="l103" href="#l103">103 </a> get_real_threats(gamestate, move->torow, move->tofile, |
156 <a class="c2html-lineno" name="l103" href="#l103">103 </a> get_real_threats(gamestate, move->torow, move->tofile, |
157 <a class="c2html-lineno" name="l104" href="#l104">104 </a> move->piece&<span class="c2html-macroconst">COLOR_MASK</span>, threats, &threatcount); |
157 <a class="c2html-lineno" name="l104" href="#l104">104 </a> move->piece&<span class="c2html-macroconst">COLOR_MASK</span>, threats, &threatcount); |
158 <a class="c2html-lineno" name="l105" href="#l105">105 </a> <span class="c2html-keyword">if</span> (threatcount > <span class="c2html-macroconst">1</span>) { |
158 <a class="c2html-lineno" name="l105" href="#l105">105 </a> <span class="c2html-keyword">if</span> (threatcount > <span class="c2html-macroconst">1</span>) { |
159 <a class="c2html-lineno" name="l106" href="#l106">106 </a> <span class="c2html-keyword">int</span> ambrows = <span class="c2html-macroconst">0</span>, ambfiles = <span class="c2html-macroconst">0</span>; |
159 <a class="c2html-lineno" name="l106" href="#l106">106 </a> <span class="c2html-keyword">int</span> ambrows = <span class="c2html-macroconst">0</span>, ambfiles = <span class="c2html-macroconst">0</span>; |
160 <a class="c2html-lineno" name="l107" href="#l107">107 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> i = <span class="c2html-macroconst">0</span> ; i < threatcount ; i++) { |
160 <a class="c2html-lineno" name="l107" href="#l107">107 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> i = <span class="c2html-macroconst">0</span> ; i < threatcount ; i++) { |
161 <a class="c2html-lineno" name="l108" href="#l108">108 </a> <span class="c2html-keyword">if</span> (threats[i].fromrow == move->fromrow) { |
161 <a class="c2html-lineno" name="l108" href="#l108">108 </a> <span class="c2html-keyword">if</span> (threats[i].fromrow == move->fromrow) { |
162 <a class="c2html-lineno" name="l109" href="#l109">109 </a> ambrows++; |
162 <a class="c2html-lineno" name="l109" href="#l109">109 </a> ambrows++; |
252 <a class="c2html-lineno" name="l199" href="#l199">199 </a> <span class="c2html-keyword">default</span>: <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>; |
252 <a class="c2html-lineno" name="l199" href="#l199">199 </a> <span class="c2html-keyword">default</span>: <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>; |
253 <a class="c2html-lineno" name="l200" href="#l200">200 </a> } |
253 <a class="c2html-lineno" name="l200" href="#l200">200 </a> } |
254 <a class="c2html-lineno" name="l201" href="#l201">201 </a>} |
254 <a class="c2html-lineno" name="l201" href="#l201">201 </a>} |
255 <a class="c2html-lineno" name="l202" href="#l202">202 </a> |
255 <a class="c2html-lineno" name="l202" href="#l202">202 </a> |
256 <a class="c2html-lineno" name="l203" href="#l203">203 </a><span class="c2html-keyword">static</span> <span class="c2html-keyword">void</span> apply_move_impl(GameState *gamestate, Move *move, _Bool simulate) { |
256 <a class="c2html-lineno" name="l203" href="#l203">203 </a><span class="c2html-keyword">static</span> <span class="c2html-keyword">void</span> apply_move_impl(GameState *gamestate, Move *move, _Bool simulate) { |
257 <a class="c2html-lineno" name="l204" href="#l204">204 </a> <span class="c2html-type">uint8_t</span> piece = move->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
257 <a class="c2html-lineno" name="l204" href="#l204">204 </a> <span class="c2html-type">uint8_t</span> piece = move->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
258 <a class="c2html-lineno" name="l205" href="#l205">205 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
258 <a class="c2html-lineno" name="l205" href="#l205">205 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
259 <a class="c2html-lineno" name="l206" href="#l206">206 </a> |
259 <a class="c2html-lineno" name="l206" href="#l206">206 </a> |
260 <a class="c2html-lineno" name="l207" href="#l207">207 </a> <span class="c2html-comment">/* en passant capture */</span> |
260 <a class="c2html-lineno" name="l207" href="#l207">207 </a> <span class="c2html-comment">/* en passant capture */</span> |
261 <a class="c2html-lineno" name="l208" href="#l208">208 </a> <span class="c2html-keyword">if</span> (move->capture && piece == <span class="c2html-macroconst">PAWN</span> && |
261 <a class="c2html-lineno" name="l208" href="#l208">208 </a> <span class="c2html-keyword">if</span> (move->capture && piece == <span class="c2html-macroconst">PAWN</span> && |
262 <a class="c2html-lineno" name="l209" href="#l209">209 </a> mdst(gamestate->board, move) == <span class="c2html-macroconst">0</span>) { |
262 <a class="c2html-lineno" name="l209" href="#l209">209 </a> mdst(gamestate->board, move) == <span class="c2html-macroconst">0</span>) { |
263 <a class="c2html-lineno" name="l210" href="#l210">210 </a> gamestate->board[move->fromrow][move->tofile] = <span class="c2html-macroconst">0</span>; |
263 <a class="c2html-lineno" name="l210" href="#l210">210 </a> gamestate->board[move->fromrow][move->tofile] = <span class="c2html-macroconst">0</span>; |
264 <a class="c2html-lineno" name="l211" href="#l211">211 </a> } |
264 <a class="c2html-lineno" name="l211" href="#l211">211 </a> } |
265 <a class="c2html-lineno" name="l212" href="#l212">212 </a> |
265 <a class="c2html-lineno" name="l212" href="#l212">212 </a> |
266 <a class="c2html-lineno" name="l213" href="#l213">213 </a> <span class="c2html-comment">/* remove old en passant threats */</span> |
266 <a class="c2html-lineno" name="l213" href="#l213">213 </a> <span class="c2html-comment">/* remove old en passant threats */</span> |
267 <a class="c2html-lineno" name="l214" href="#l214">214 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> file = <span class="c2html-macroconst">0</span> ; file < <span class="c2html-macroconst">8</span> ; file++) { |
267 <a class="c2html-lineno" name="l214" href="#l214">214 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> file = <span class="c2html-macroconst">0</span> ; file < <span class="c2html-macroconst">8</span> ; file++) { |
268 <a class="c2html-lineno" name="l215" href="#l215">215 </a> gamestate->board[<span class="c2html-macroconst">3</span>][file] &= ~<span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
268 <a class="c2html-lineno" name="l215" href="#l215">215 </a> gamestate->board[<span class="c2html-macroconst">3</span>][file] &= ~<span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
269 <a class="c2html-lineno" name="l216" href="#l216">216 </a> gamestate->board[<span class="c2html-macroconst">4</span>][file] &= ~<span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
269 <a class="c2html-lineno" name="l216" href="#l216">216 </a> gamestate->board[<span class="c2html-macroconst">4</span>][file] &= ~<span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
270 <a class="c2html-lineno" name="l217" href="#l217">217 </a> } |
270 <a class="c2html-lineno" name="l217" href="#l217">217 </a> } |
271 <a class="c2html-lineno" name="l218" href="#l218">218 </a> |
271 <a class="c2html-lineno" name="l218" href="#l218">218 </a> |
272 <a class="c2html-lineno" name="l219" href="#l219">219 </a> <span class="c2html-comment">/* add new en passant threat */</span> |
272 <a class="c2html-lineno" name="l219" href="#l219">219 </a> <span class="c2html-comment">/* add new en passant threat */</span> |
273 <a class="c2html-lineno" name="l220" href="#l220">220 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span> && ( |
273 <a class="c2html-lineno" name="l220" href="#l220">220 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span> && ( |
274 <a class="c2html-lineno" name="l221" href="#l221">221 </a> (move->fromrow == <span class="c2html-macroconst">1</span> && move->torow == <span class="c2html-macroconst">3</span>) || |
274 <a class="c2html-lineno" name="l221" href="#l221">221 </a> (move->fromrow == <span class="c2html-macroconst">1</span> && move->torow == <span class="c2html-macroconst">3</span>) || |
275 <a class="c2html-lineno" name="l222" href="#l222">222 </a> (move->fromrow == <span class="c2html-macroconst">6</span> && move->torow == <span class="c2html-macroconst">4</span>))) { |
275 <a class="c2html-lineno" name="l222" href="#l222">222 </a> (move->fromrow == <span class="c2html-macroconst">6</span> && move->torow == <span class="c2html-macroconst">4</span>))) { |
276 <a class="c2html-lineno" name="l223" href="#l223">223 </a> move->piece |= <span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
276 <a class="c2html-lineno" name="l223" href="#l223">223 </a> move->piece |= <span class="c2html-macroconst">ENPASSANT_THREAT</span>; |
277 <a class="c2html-lineno" name="l224" href="#l224">224 </a> } |
277 <a class="c2html-lineno" name="l224" href="#l224">224 </a> } |
278 <a class="c2html-lineno" name="l225" href="#l225">225 </a> |
278 <a class="c2html-lineno" name="l225" href="#l225">225 </a> |
279 <a class="c2html-lineno" name="l226" href="#l226">226 </a> <span class="c2html-comment">/* move (and maybe capture or promote) */</span> |
279 <a class="c2html-lineno" name="l226" href="#l226">226 </a> <span class="c2html-comment">/* move (and maybe capture or promote) */</span> |
280 <a class="c2html-lineno" name="l227" href="#l227">227 </a> msrc(gamestate->board, move) = <span class="c2html-macroconst">0</span>; |
280 <a class="c2html-lineno" name="l227" href="#l227">227 </a> msrc(gamestate->board, move) = <span class="c2html-macroconst">0</span>; |
314 <a class="c2html-lineno" name="l261" href="#l261">261 </a> <span class="c2html-keyword">if</span> (!chkidx(move)) { |
314 <a class="c2html-lineno" name="l261" href="#l261">261 </a> <span class="c2html-keyword">if</span> (!chkidx(move)) { |
315 <a class="c2html-lineno" name="l262" href="#l262">262 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_POSITION</span>; |
315 <a class="c2html-lineno" name="l262" href="#l262">262 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_POSITION</span>; |
316 <a class="c2html-lineno" name="l263" href="#l263">263 </a> } |
316 <a class="c2html-lineno" name="l263" href="#l263">263 </a> } |
317 <a class="c2html-lineno" name="l264" href="#l264">264 </a> |
317 <a class="c2html-lineno" name="l264" href="#l264">264 </a> |
318 <a class="c2html-lineno" name="l265" href="#l265">265 </a> <span class="c2html-comment">/* must move */</span> |
318 <a class="c2html-lineno" name="l265" href="#l265">265 </a> <span class="c2html-comment">/* must move */</span> |
319 <a class="c2html-lineno" name="l266" href="#l266">266 </a> <span class="c2html-keyword">if</span> (move->fromfile == move->tofile && move->fromrow == move->torow) { |
319 <a class="c2html-lineno" name="l266" href="#l266">266 </a> <span class="c2html-keyword">if</span> (move->fromfile == move->tofile && move->fromrow == move->torow) { |
320 <a class="c2html-lineno" name="l267" href="#l267">267 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
320 <a class="c2html-lineno" name="l267" href="#l267">267 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
321 <a class="c2html-lineno" name="l268" href="#l268">268 </a> } |
321 <a class="c2html-lineno" name="l268" href="#l268">268 </a> } |
322 <a class="c2html-lineno" name="l269" href="#l269">269 </a> |
322 <a class="c2html-lineno" name="l269" href="#l269">269 </a> |
323 <a class="c2html-lineno" name="l270" href="#l270">270 </a> <span class="c2html-comment">/* does piece exist */</span> |
323 <a class="c2html-lineno" name="l270" href="#l270">270 </a> <span class="c2html-comment">/* does piece exist */</span> |
324 <a class="c2html-lineno" name="l271" href="#l271">271 </a> <span class="c2html-keyword">if</span> ((msrc(gamestate->board, move)&(<span class="c2html-macroconst">PIECE_MASK</span>|<span class="c2html-macroconst">COLOR_MASK</span>)) |
324 <a class="c2html-lineno" name="l271" href="#l271">271 </a> <span class="c2html-keyword">if</span> ((msrc(gamestate->board, move)&(<span class="c2html-macroconst">PIECE_MASK</span>|<span class="c2html-macroconst">COLOR_MASK</span>)) |
325 <a class="c2html-lineno" name="l272" href="#l272">272 </a> != (move->piece&(<span class="c2html-macroconst">PIECE_MASK</span>|<span class="c2html-macroconst">COLOR_MASK</span>))) { |
325 <a class="c2html-lineno" name="l272" href="#l272">272 </a> != (move->piece&(<span class="c2html-macroconst">PIECE_MASK</span>|<span class="c2html-macroconst">COLOR_MASK</span>))) { |
326 <a class="c2html-lineno" name="l273" href="#l273">273 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_POSITION</span>; |
326 <a class="c2html-lineno" name="l273" href="#l273">273 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_POSITION</span>; |
327 <a class="c2html-lineno" name="l274" href="#l274">274 </a> } |
327 <a class="c2html-lineno" name="l274" href="#l274">274 </a> } |
328 <a class="c2html-lineno" name="l275" href="#l275">275 </a> |
328 <a class="c2html-lineno" name="l275" href="#l275">275 </a> |
329 <a class="c2html-lineno" name="l276" href="#l276">276 </a> <span class="c2html-comment">/* can't capture own pieces */</span> |
329 <a class="c2html-lineno" name="l276" href="#l276">276 </a> <span class="c2html-comment">/* can't capture own pieces */</span> |
330 <a class="c2html-lineno" name="l277" href="#l277">277 </a> <span class="c2html-keyword">if</span> ((mdst(gamestate->board, move) & <span class="c2html-macroconst">COLOR_MASK</span>) |
330 <a class="c2html-lineno" name="l277" href="#l277">277 </a> <span class="c2html-keyword">if</span> ((mdst(gamestate->board, move) & <span class="c2html-macroconst">COLOR_MASK</span>) |
331 <a class="c2html-lineno" name="l278" href="#l278">278 </a> == (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>)) { |
331 <a class="c2html-lineno" name="l278" href="#l278">278 </a> == (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>)) { |
332 <a class="c2html-lineno" name="l279" href="#l279">279 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">RULES_VIOLATED</span>; |
332 <a class="c2html-lineno" name="l279" href="#l279">279 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">RULES_VIOLATED</span>; |
333 <a class="c2html-lineno" name="l280" href="#l280">280 </a> } |
333 <a class="c2html-lineno" name="l280" href="#l280">280 </a> } |
334 <a class="c2html-lineno" name="l281" href="#l281">281 </a> |
334 <a class="c2html-lineno" name="l281" href="#l281">281 </a> |
335 <a class="c2html-lineno" name="l282" href="#l282">282 </a> <span class="c2html-comment">/* must capture, if and only if destination is occupied */</span> |
335 <a class="c2html-lineno" name="l282" href="#l282">282 </a> <span class="c2html-comment">/* must capture, if and only if destination is occupied */</span> |
336 <a class="c2html-lineno" name="l283" href="#l283">283 </a> <span class="c2html-keyword">if</span> ((mdst(gamestate->board, move) == <span class="c2html-macroconst">0</span> && move->capture) || |
336 <a class="c2html-lineno" name="l283" href="#l283">283 </a> <span class="c2html-keyword">if</span> ((mdst(gamestate->board, move) == <span class="c2html-macroconst">0</span> && move->capture) || |
337 <a class="c2html-lineno" name="l284" href="#l284">284 </a> (mdst(gamestate->board, move) != <span class="c2html-macroconst">0</span> && !move->capture)) { |
337 <a class="c2html-lineno" name="l284" href="#l284">284 </a> (mdst(gamestate->board, move) != <span class="c2html-macroconst">0</span> && !move->capture)) { |
338 <a class="c2html-lineno" name="l285" href="#l285">285 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
338 <a class="c2html-lineno" name="l285" href="#l285">285 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
339 <a class="c2html-lineno" name="l286" href="#l286">286 </a> } |
339 <a class="c2html-lineno" name="l286" href="#l286">286 </a> } |
340 <a class="c2html-lineno" name="l287" href="#l287">287 </a> |
340 <a class="c2html-lineno" name="l287" href="#l287">287 </a> |
341 <a class="c2html-lineno" name="l288" href="#l288">288 </a> <span class="c2html-comment">/* validate individual rules */</span> |
341 <a class="c2html-lineno" name="l288" href="#l288">288 </a> <span class="c2html-comment">/* validate individual rules */</span> |
342 <a class="c2html-lineno" name="l289" href="#l289">289 </a> _Bool chkrules; |
342 <a class="c2html-lineno" name="l289" href="#l289">289 </a> _Bool chkrules; |
343 <a class="c2html-lineno" name="l290" href="#l290">290 </a> <span class="c2html-keyword">switch</span> (move->piece & <span class="c2html-macroconst">PIECE_MASK</span>) { |
343 <a class="c2html-lineno" name="l290" href="#l290">290 </a> <span class="c2html-keyword">switch</span> (move->piece & <span class="c2html-macroconst">PIECE_MASK</span>) { |
344 <a class="c2html-lineno" name="l291" href="#l291">291 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">PAWN</span>: |
344 <a class="c2html-lineno" name="l291" href="#l291">291 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">PAWN</span>: |
345 <a class="c2html-lineno" name="l292" href="#l292">292 </a> chkrules = pawn_chkrules(gamestate, move) && |
345 <a class="c2html-lineno" name="l292" href="#l292">292 </a> chkrules = pawn_chkrules(gamestate, move) && |
346 <a class="c2html-lineno" name="l293" href="#l293">293 </a> !pawn_isblocked(gamestate, move); |
346 <a class="c2html-lineno" name="l293" href="#l293">293 </a> !pawn_isblocked(gamestate, move); |
347 <a class="c2html-lineno" name="l294" href="#l294">294 </a> <span class="c2html-keyword">break</span>; |
347 <a class="c2html-lineno" name="l294" href="#l294">294 </a> <span class="c2html-keyword">break</span>; |
348 <a class="c2html-lineno" name="l295" href="#l295">295 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">ROOK</span>: |
348 <a class="c2html-lineno" name="l295" href="#l295">295 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">ROOK</span>: |
349 <a class="c2html-lineno" name="l296" href="#l296">296 </a> chkrules = rook_chkrules(move) && |
349 <a class="c2html-lineno" name="l296" href="#l296">296 </a> chkrules = rook_chkrules(move) && |
350 <a class="c2html-lineno" name="l297" href="#l297">297 </a> !rook_isblocked(gamestate, move); |
350 <a class="c2html-lineno" name="l297" href="#l297">297 </a> !rook_isblocked(gamestate, move); |
351 <a class="c2html-lineno" name="l298" href="#l298">298 </a> <span class="c2html-keyword">break</span>; |
351 <a class="c2html-lineno" name="l298" href="#l298">298 </a> <span class="c2html-keyword">break</span>; |
352 <a class="c2html-lineno" name="l299" href="#l299">299 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KNIGHT</span>: |
352 <a class="c2html-lineno" name="l299" href="#l299">299 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KNIGHT</span>: |
353 <a class="c2html-lineno" name="l300" href="#l300">300 </a> chkrules = knight_chkrules(move); <span class="c2html-comment">/* knight is never blocked */</span> |
353 <a class="c2html-lineno" name="l300" href="#l300">300 </a> chkrules = knight_chkrules(move); <span class="c2html-comment">/* knight is never blocked */</span> |
354 <a class="c2html-lineno" name="l301" href="#l301">301 </a> <span class="c2html-keyword">break</span>; |
354 <a class="c2html-lineno" name="l301" href="#l301">301 </a> <span class="c2html-keyword">break</span>; |
355 <a class="c2html-lineno" name="l302" href="#l302">302 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">BISHOP</span>: |
355 <a class="c2html-lineno" name="l302" href="#l302">302 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">BISHOP</span>: |
356 <a class="c2html-lineno" name="l303" href="#l303">303 </a> chkrules = bishop_chkrules(move) && |
356 <a class="c2html-lineno" name="l303" href="#l303">303 </a> chkrules = bishop_chkrules(move) && |
357 <a class="c2html-lineno" name="l304" href="#l304">304 </a> !bishop_isblocked(gamestate, move); |
357 <a class="c2html-lineno" name="l304" href="#l304">304 </a> !bishop_isblocked(gamestate, move); |
358 <a class="c2html-lineno" name="l305" href="#l305">305 </a> <span class="c2html-keyword">break</span>; |
358 <a class="c2html-lineno" name="l305" href="#l305">305 </a> <span class="c2html-keyword">break</span>; |
359 <a class="c2html-lineno" name="l306" href="#l306">306 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">QUEEN</span>: |
359 <a class="c2html-lineno" name="l306" href="#l306">306 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">QUEEN</span>: |
360 <a class="c2html-lineno" name="l307" href="#l307">307 </a> chkrules = queen_chkrules(move) && |
360 <a class="c2html-lineno" name="l307" href="#l307">307 </a> chkrules = queen_chkrules(move) && |
361 <a class="c2html-lineno" name="l308" href="#l308">308 </a> !queen_isblocked(gamestate, move); |
361 <a class="c2html-lineno" name="l308" href="#l308">308 </a> !queen_isblocked(gamestate, move); |
362 <a class="c2html-lineno" name="l309" href="#l309">309 </a> <span class="c2html-keyword">break</span>; |
362 <a class="c2html-lineno" name="l309" href="#l309">309 </a> <span class="c2html-keyword">break</span>; |
363 <a class="c2html-lineno" name="l310" href="#l310">310 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KING</span>: |
363 <a class="c2html-lineno" name="l310" href="#l310">310 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KING</span>: |
364 <a class="c2html-lineno" name="l311" href="#l311">311 </a> chkrules = king_chkrules(gamestate, move) && |
364 <a class="c2html-lineno" name="l311" href="#l311">311 </a> chkrules = king_chkrules(gamestate, move) && |
365 <a class="c2html-lineno" name="l312" href="#l312">312 </a> !king_isblocked(gamestate, move); |
365 <a class="c2html-lineno" name="l312" href="#l312">312 </a> !king_isblocked(gamestate, move); |
366 <a class="c2html-lineno" name="l313" href="#l313">313 </a> <span class="c2html-keyword">break</span>; |
366 <a class="c2html-lineno" name="l313" href="#l313">313 </a> <span class="c2html-keyword">break</span>; |
367 <a class="c2html-lineno" name="l314" href="#l314">314 </a> <span class="c2html-keyword">default</span>: |
367 <a class="c2html-lineno" name="l314" href="#l314">314 </a> <span class="c2html-keyword">default</span>: |
368 <a class="c2html-lineno" name="l315" href="#l315">315 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
368 <a class="c2html-lineno" name="l315" href="#l315">315 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; |
369 <a class="c2html-lineno" name="l316" href="#l316">316 </a> } |
369 <a class="c2html-lineno" name="l316" href="#l316">316 </a> } |
399 <a class="c2html-lineno" name="l346" href="#l346">346 </a> } |
399 <a class="c2html-lineno" name="l346" href="#l346">346 </a> } |
400 <a class="c2html-lineno" name="l347" href="#l347">347 </a> |
400 <a class="c2html-lineno" name="l347" href="#l347">347 </a> |
401 <a class="c2html-lineno" name="l348" href="#l348">348 </a> <span class="c2html-comment">/* simulate move for check validation */</span> |
401 <a class="c2html-lineno" name="l348" href="#l348">348 </a> <span class="c2html-comment">/* simulate move for check validation */</span> |
402 <a class="c2html-lineno" name="l349" href="#l349">349 </a> GameState simulation = gamestate_copy_sim(gamestate); |
402 <a class="c2html-lineno" name="l349" href="#l349">349 </a> GameState simulation = gamestate_copy_sim(gamestate); |
403 <a class="c2html-lineno" name="l350" href="#l350">350 </a> Move simmove = *move; |
403 <a class="c2html-lineno" name="l350" href="#l350">350 </a> Move simmove = *move; |
404 <a class="c2html-lineno" name="l351" href="#l351">351 </a> apply_move_impl(&simulation, &simmove, <span class="c2html-macroconst">1</span>); |
404 <a class="c2html-lineno" name="l351" href="#l351">351 </a> apply_move_impl(&simulation, &simmove, <span class="c2html-macroconst">1</span>); |
405 <a class="c2html-lineno" name="l352" href="#l352">352 </a> |
405 <a class="c2html-lineno" name="l352" href="#l352">352 </a> |
406 <a class="c2html-lineno" name="l353" href="#l353">353 </a> <span class="c2html-comment">/* don't move into or stay in check position */</span> |
406 <a class="c2html-lineno" name="l353" href="#l353">353 </a> <span class="c2html-comment">/* don't move into or stay in check position */</span> |
407 <a class="c2html-lineno" name="l354" href="#l354">354 </a> <span class="c2html-keyword">if</span> (is_covered(&simulation, mykingrow, mykingfile, |
407 <a class="c2html-lineno" name="l354" href="#l354">354 </a> <span class="c2html-keyword">if</span> (is_covered(&simulation, mykingrow, mykingfile, |
408 <a class="c2html-lineno" name="l355" href="#l355">355 </a> opponent_color(piececolor))) { |
408 <a class="c2html-lineno" name="l355" href="#l355">355 </a> opponent_color(piececolor))) { |
409 <a class="c2html-lineno" name="l356" href="#l356">356 </a> |
409 <a class="c2html-lineno" name="l356" href="#l356">356 </a> |
410 <a class="c2html-lineno" name="l357" href="#l357">357 </a> gamestate_cleanup(&simulation); |
410 <a class="c2html-lineno" name="l357" href="#l357">357 </a> gamestate_cleanup(&simulation); |
411 <a class="c2html-lineno" name="l358" href="#l358">358 </a> <span class="c2html-keyword">if</span> ((move->piece & <span class="c2html-macroconst">PIECE_MASK</span>) == <span class="c2html-macroconst">KING</span>) { |
411 <a class="c2html-lineno" name="l358" href="#l358">358 </a> <span class="c2html-keyword">if</span> ((move->piece & <span class="c2html-macroconst">PIECE_MASK</span>) == <span class="c2html-macroconst">KING</span>) { |
412 <a class="c2html-lineno" name="l359" href="#l359">359 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">KING_MOVES_INTO_CHECK</span>; |
412 <a class="c2html-lineno" name="l359" href="#l359">359 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">KING_MOVES_INTO_CHECK</span>; |
413 <a class="c2html-lineno" name="l360" href="#l360">360 </a> } <span class="c2html-keyword">else</span> { |
413 <a class="c2html-lineno" name="l360" href="#l360">360 </a> } <span class="c2html-keyword">else</span> { |
414 <a class="c2html-lineno" name="l361" href="#l361">361 </a> <span class="c2html-comment">/* last move is always not null in this case */</span> |
414 <a class="c2html-lineno" name="l361" href="#l361">361 </a> <span class="c2html-comment">/* last move is always not null in this case */</span> |
415 <a class="c2html-lineno" name="l362" href="#l362">362 </a> <span class="c2html-keyword">return</span> gamestate->lastmove->move.check ? |
415 <a class="c2html-lineno" name="l362" href="#l362">362 </a> <span class="c2html-keyword">return</span> gamestate->lastmove->move.check ? |
416 <a class="c2html-lineno" name="l363" href="#l363">363 </a> <span class="c2html-macroconst">KING_IN_CHECK</span> : <span class="c2html-macroconst">PIECE_PINNED</span>; |
416 <a class="c2html-lineno" name="l363" href="#l363">363 </a> <span class="c2html-macroconst">KING_IN_CHECK</span> : <span class="c2html-macroconst">PIECE_PINNED</span>; |
418 <a class="c2html-lineno" name="l365" href="#l365">365 </a> } |
418 <a class="c2html-lineno" name="l365" href="#l365">365 </a> } |
419 <a class="c2html-lineno" name="l366" href="#l366">366 </a> |
419 <a class="c2html-lineno" name="l366" href="#l366">366 </a> |
420 <a class="c2html-lineno" name="l367" href="#l367">367 </a> <span class="c2html-comment">/* correct check and checkmate flags (move is still valid) */</span> |
420 <a class="c2html-lineno" name="l367" href="#l367">367 </a> <span class="c2html-comment">/* correct check and checkmate flags (move is still valid) */</span> |
421 <a class="c2html-lineno" name="l368" href="#l368">368 </a> Move threats[<span class="c2html-macroconst">16</span>]; |
421 <a class="c2html-lineno" name="l368" href="#l368">368 </a> Move threats[<span class="c2html-macroconst">16</span>]; |
422 <a class="c2html-lineno" name="l369" href="#l369">369 </a> <span class="c2html-type">uint8_t</span> threatcount; |
422 <a class="c2html-lineno" name="l369" href="#l369">369 </a> <span class="c2html-type">uint8_t</span> threatcount; |
423 <a class="c2html-lineno" name="l370" href="#l370">370 </a> move->check = get_threats(&simulation, opkingrow, opkingfile, |
423 <a class="c2html-lineno" name="l370" href="#l370">370 </a> move->check = get_threats(&simulation, opkingrow, opkingfile, |
424 <a class="c2html-lineno" name="l371" href="#l371">371 </a> piececolor, threats, &threatcount); |
424 <a class="c2html-lineno" name="l371" href="#l371">371 </a> piececolor, threats, &threatcount); |
425 <a class="c2html-lineno" name="l372" href="#l372">372 </a> |
425 <a class="c2html-lineno" name="l372" href="#l372">372 </a> |
426 <a class="c2html-lineno" name="l373" href="#l373">373 </a> <span class="c2html-keyword">if</span> (move->check) { |
426 <a class="c2html-lineno" name="l373" href="#l373">373 </a> <span class="c2html-keyword">if</span> (move->check) { |
427 <a class="c2html-lineno" name="l374" href="#l374">374 </a> <span class="c2html-comment">/* determine possible escape fields */</span> |
427 <a class="c2html-lineno" name="l374" href="#l374">374 </a> <span class="c2html-comment">/* determine possible escape fields */</span> |
428 <a class="c2html-lineno" name="l375" href="#l375">375 </a> _Bool canescape = <span class="c2html-macroconst">0</span>; |
428 <a class="c2html-lineno" name="l375" href="#l375">375 </a> _Bool canescape = <span class="c2html-macroconst">0</span>; |
429 <a class="c2html-lineno" name="l376" href="#l376">376 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> dr = -<span class="c2html-macroconst">1</span> ; dr <= <span class="c2html-macroconst">1</span> && !canescape ; dr++) { |
429 <a class="c2html-lineno" name="l376" href="#l376">376 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> dr = -<span class="c2html-macroconst">1</span> ; dr <= <span class="c2html-macroconst">1</span> && !canescape ; dr++) { |
430 <a class="c2html-lineno" name="l377" href="#l377">377 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> df = -<span class="c2html-macroconst">1</span> ; df <= <span class="c2html-macroconst">1</span> && !canescape ; df++) { |
430 <a class="c2html-lineno" name="l377" href="#l377">377 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> df = -<span class="c2html-macroconst">1</span> ; df <= <span class="c2html-macroconst">1</span> && !canescape ; df++) { |
431 <a class="c2html-lineno" name="l378" href="#l378">378 </a> <span class="c2html-keyword">if</span> (!(dr == <span class="c2html-macroconst">0</span> && df == <span class="c2html-macroconst">0</span>) && |
431 <a class="c2html-lineno" name="l378" href="#l378">378 </a> <span class="c2html-keyword">if</span> (!(dr == <span class="c2html-macroconst">0</span> && df == <span class="c2html-macroconst">0</span>) && |
432 <a class="c2html-lineno" name="l379" href="#l379">379 </a> isidx(opkingrow + dr) && isidx(opkingfile + df)) { |
432 <a class="c2html-lineno" name="l379" href="#l379">379 </a> isidx(opkingrow + dr) && isidx(opkingfile + df)) { |
433 <a class="c2html-lineno" name="l380" href="#l380">380 </a> |
433 <a class="c2html-lineno" name="l380" href="#l380">380 </a> |
434 <a class="c2html-lineno" name="l381" href="#l381">381 </a> <span class="c2html-comment">/* escape field neither blocked nor covered */</span> |
434 <a class="c2html-lineno" name="l381" href="#l381">381 </a> <span class="c2html-comment">/* escape field neither blocked nor covered */</span> |
435 <a class="c2html-lineno" name="l382" href="#l382">382 </a> <span class="c2html-keyword">if</span> ((simulation.board[opkingrow + dr][opkingfile + df] |
435 <a class="c2html-lineno" name="l382" href="#l382">382 </a> <span class="c2html-keyword">if</span> ((simulation.board[opkingrow + dr][opkingfile + df] |
436 <a class="c2html-lineno" name="l383" href="#l383">383 </a> & <span class="c2html-macroconst">COLOR_MASK</span>) != opponent_color(piececolor)) { |
436 <a class="c2html-lineno" name="l383" href="#l383">383 </a> & <span class="c2html-macroconst">COLOR_MASK</span>) != opponent_color(piececolor)) { |
437 <a class="c2html-lineno" name="l384" href="#l384">384 </a> canescape |= !is_covered(&simulation, |
437 <a class="c2html-lineno" name="l384" href="#l384">384 </a> canescape |= !is_covered(&simulation, |
438 <a class="c2html-lineno" name="l385" href="#l385">385 </a> opkingrow + dr, opkingfile + df, piececolor); |
438 <a class="c2html-lineno" name="l385" href="#l385">385 </a> opkingrow + dr, opkingfile + df, piececolor); |
439 <a class="c2html-lineno" name="l386" href="#l386">386 </a> } |
439 <a class="c2html-lineno" name="l386" href="#l386">386 </a> } |
440 <a class="c2html-lineno" name="l387" href="#l387">387 </a> } |
440 <a class="c2html-lineno" name="l387" href="#l387">387 </a> } |
441 <a class="c2html-lineno" name="l388" href="#l388">388 </a> } |
441 <a class="c2html-lineno" name="l388" href="#l388">388 </a> } |
442 <a class="c2html-lineno" name="l389" href="#l389">389 </a> } |
442 <a class="c2html-lineno" name="l389" href="#l389">389 </a> } |
443 <a class="c2html-lineno" name="l390" href="#l390">390 </a> <span class="c2html-comment">/* can't escape, can he capture? */</span> |
443 <a class="c2html-lineno" name="l390" href="#l390">390 </a> <span class="c2html-comment">/* can't escape, can he capture? */</span> |
444 <a class="c2html-lineno" name="l391" href="#l391">391 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { |
444 <a class="c2html-lineno" name="l391" href="#l391">391 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { |
445 <a class="c2html-lineno" name="l392" href="#l392">392 </a> canescape = is_attacked(&simulation, threats[<span class="c2html-macroconst">0</span>].fromrow, |
445 <a class="c2html-lineno" name="l392" href="#l392">392 </a> canescape = is_attacked(&simulation, threats[<span class="c2html-macroconst">0</span>].fromrow, |
446 <a class="c2html-lineno" name="l393" href="#l393">393 </a> threats[<span class="c2html-macroconst">0</span>].fromfile, opponent_color(piececolor)); |
446 <a class="c2html-lineno" name="l393" href="#l393">393 </a> threats[<span class="c2html-macroconst">0</span>].fromfile, opponent_color(piececolor)); |
447 <a class="c2html-lineno" name="l394" href="#l394">394 </a> } |
447 <a class="c2html-lineno" name="l394" href="#l394">394 </a> } |
448 <a class="c2html-lineno" name="l395" href="#l395">395 </a> |
448 <a class="c2html-lineno" name="l395" href="#l395">395 </a> |
449 <a class="c2html-lineno" name="l396" href="#l396">396 </a> <span class="c2html-comment">/* can't capture, can he block? */</span> |
449 <a class="c2html-lineno" name="l396" href="#l396">396 </a> <span class="c2html-comment">/* can't capture, can he block? */</span> |
450 <a class="c2html-lineno" name="l397" href="#l397">397 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { |
450 <a class="c2html-lineno" name="l397" href="#l397">397 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { |
451 <a class="c2html-lineno" name="l398" href="#l398">398 </a> Move *threat = &(threats[<span class="c2html-macroconst">0</span>]); |
451 <a class="c2html-lineno" name="l398" href="#l398">398 </a> Move *threat = &(threats[<span class="c2html-macroconst">0</span>]); |
452 <a class="c2html-lineno" name="l399" href="#l399">399 </a> <span class="c2html-type">uint8_t</span> threatpiece = threat->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
452 <a class="c2html-lineno" name="l399" href="#l399">399 </a> <span class="c2html-type">uint8_t</span> threatpiece = threat->piece & <span class="c2html-macroconst">PIECE_MASK</span>; |
453 <a class="c2html-lineno" name="l400" href="#l400">400 </a> |
453 <a class="c2html-lineno" name="l400" href="#l400">400 </a> |
454 <a class="c2html-lineno" name="l401" href="#l401">401 </a> <span class="c2html-comment">/* knight, pawns and the king cannot be blocked */</span> |
454 <a class="c2html-lineno" name="l401" href="#l401">401 </a> <span class="c2html-comment">/* knight, pawns and the king cannot be blocked */</span> |
455 <a class="c2html-lineno" name="l402" href="#l402">402 </a> <span class="c2html-keyword">if</span> (threatpiece == <span class="c2html-macroconst">BISHOP</span> || threatpiece == <span class="c2html-macroconst">ROOK</span> |
455 <a class="c2html-lineno" name="l402" href="#l402">402 </a> <span class="c2html-keyword">if</span> (threatpiece == <span class="c2html-macroconst">BISHOP</span> || threatpiece == <span class="c2html-macroconst">ROOK</span> |
456 <a class="c2html-lineno" name="l403" href="#l403">403 </a> || threatpiece == <span class="c2html-macroconst">QUEEN</span>) { |
456 <a class="c2html-lineno" name="l403" href="#l403">403 </a> || threatpiece == <span class="c2html-macroconst">QUEEN</span>) { |
457 <a class="c2html-lineno" name="l404" href="#l404">404 </a> <span class="c2html-keyword">if</span> (threat->fromrow == threat->torow) { |
457 <a class="c2html-lineno" name="l404" href="#l404">404 </a> <span class="c2html-keyword">if</span> (threat->fromrow == threat->torow) { |
458 <a class="c2html-lineno" name="l405" href="#l405">405 </a> <span class="c2html-comment">/* rook aspect (on row) */</span> |
458 <a class="c2html-lineno" name="l405" href="#l405">405 </a> <span class="c2html-comment">/* rook aspect (on row) */</span> |
459 <a class="c2html-lineno" name="l406" href="#l406">406 </a> <span class="c2html-keyword">int</span> d = threat->tofile > threat->fromfile ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
459 <a class="c2html-lineno" name="l406" href="#l406">406 </a> <span class="c2html-keyword">int</span> d = threat->tofile > threat->fromfile ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
460 <a class="c2html-lineno" name="l407" href="#l407">407 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; |
460 <a class="c2html-lineno" name="l407" href="#l407">407 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; |
461 <a class="c2html-lineno" name="l408" href="#l408">408 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - d) { |
461 <a class="c2html-lineno" name="l408" href="#l408">408 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - d) { |
462 <a class="c2html-lineno" name="l409" href="#l409">409 </a> file += d; |
462 <a class="c2html-lineno" name="l409" href="#l409">409 </a> file += d; |
463 <a class="c2html-lineno" name="l410" href="#l410">410 </a> canescape |= is_protected(&simulation, |
463 <a class="c2html-lineno" name="l410" href="#l410">410 </a> canescape |= is_protected(&simulation, |
464 <a class="c2html-lineno" name="l411" href="#l411">411 </a> threat->torow, file, opponent_color(piececolor)); |
464 <a class="c2html-lineno" name="l411" href="#l411">411 </a> threat->torow, file, opponent_color(piececolor)); |
465 <a class="c2html-lineno" name="l412" href="#l412">412 </a> } |
465 <a class="c2html-lineno" name="l412" href="#l412">412 </a> } |
466 <a class="c2html-lineno" name="l413" href="#l413">413 </a> } <span class="c2html-keyword">else</span> <span class="c2html-keyword">if</span> (threat->fromfile == threat->tofile) { |
466 <a class="c2html-lineno" name="l413" href="#l413">413 </a> } <span class="c2html-keyword">else</span> <span class="c2html-keyword">if</span> (threat->fromfile == threat->tofile) { |
467 <a class="c2html-lineno" name="l414" href="#l414">414 </a> <span class="c2html-comment">/* rook aspect (on file) */</span> |
467 <a class="c2html-lineno" name="l414" href="#l414">414 </a> <span class="c2html-comment">/* rook aspect (on file) */</span> |
468 <a class="c2html-lineno" name="l415" href="#l415">415 </a> <span class="c2html-keyword">int</span> d = threat->torow > threat->fromrow ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
468 <a class="c2html-lineno" name="l415" href="#l415">415 </a> <span class="c2html-keyword">int</span> d = threat->torow > threat->fromrow ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
469 <a class="c2html-lineno" name="l416" href="#l416">416 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; |
469 <a class="c2html-lineno" name="l416" href="#l416">416 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; |
470 <a class="c2html-lineno" name="l417" href="#l417">417 </a> <span class="c2html-keyword">while</span> (!canescape && row != threat->torow - d) { |
470 <a class="c2html-lineno" name="l417" href="#l417">417 </a> <span class="c2html-keyword">while</span> (!canescape && row != threat->torow - d) { |
471 <a class="c2html-lineno" name="l418" href="#l418">418 </a> row += d; |
471 <a class="c2html-lineno" name="l418" href="#l418">418 </a> row += d; |
472 <a class="c2html-lineno" name="l419" href="#l419">419 </a> canescape |= is_protected(&simulation, |
472 <a class="c2html-lineno" name="l419" href="#l419">419 </a> canescape |= is_protected(&simulation, |
473 <a class="c2html-lineno" name="l420" href="#l420">420 </a> row, threat->tofile, opponent_color(piececolor)); |
473 <a class="c2html-lineno" name="l420" href="#l420">420 </a> row, threat->tofile, opponent_color(piececolor)); |
474 <a class="c2html-lineno" name="l421" href="#l421">421 </a> } |
474 <a class="c2html-lineno" name="l421" href="#l421">421 </a> } |
475 <a class="c2html-lineno" name="l422" href="#l422">422 </a> } <span class="c2html-keyword">else</span> { |
475 <a class="c2html-lineno" name="l422" href="#l422">422 </a> } <span class="c2html-keyword">else</span> { |
476 <a class="c2html-lineno" name="l423" href="#l423">423 </a> <span class="c2html-comment">/* bishop aspect */</span> |
476 <a class="c2html-lineno" name="l423" href="#l423">423 </a> <span class="c2html-comment">/* bishop aspect */</span> |
477 <a class="c2html-lineno" name="l424" href="#l424">424 </a> <span class="c2html-keyword">int</span> dr = threat->torow > threat->fromrow ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
477 <a class="c2html-lineno" name="l424" href="#l424">424 </a> <span class="c2html-keyword">int</span> dr = threat->torow > threat->fromrow ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
478 <a class="c2html-lineno" name="l425" href="#l425">425 </a> <span class="c2html-keyword">int</span> df = threat->tofile > threat->fromfile ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
478 <a class="c2html-lineno" name="l425" href="#l425">425 </a> <span class="c2html-keyword">int</span> df = threat->tofile > threat->fromfile ? <span class="c2html-macroconst">1</span> : -<span class="c2html-macroconst">1</span>; |
479 <a class="c2html-lineno" name="l426" href="#l426">426 </a> |
479 <a class="c2html-lineno" name="l426" href="#l426">426 </a> |
480 <a class="c2html-lineno" name="l427" href="#l427">427 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; |
480 <a class="c2html-lineno" name="l427" href="#l427">427 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; |
481 <a class="c2html-lineno" name="l428" href="#l428">428 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; |
481 <a class="c2html-lineno" name="l428" href="#l428">428 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; |
482 <a class="c2html-lineno" name="l429" href="#l429">429 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - df |
482 <a class="c2html-lineno" name="l429" href="#l429">429 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - df |
483 <a class="c2html-lineno" name="l430" href="#l430">430 </a> && row != threat->torow - dr) { |
483 <a class="c2html-lineno" name="l430" href="#l430">430 </a> && row != threat->torow - dr) { |
484 <a class="c2html-lineno" name="l431" href="#l431">431 </a> row += dr; |
484 <a class="c2html-lineno" name="l431" href="#l431">431 </a> row += dr; |
485 <a class="c2html-lineno" name="l432" href="#l432">432 </a> file += df; |
485 <a class="c2html-lineno" name="l432" href="#l432">432 </a> file += df; |
486 <a class="c2html-lineno" name="l433" href="#l433">433 </a> canescape |= is_protected(&simulation, row, file, |
486 <a class="c2html-lineno" name="l433" href="#l433">433 </a> canescape |= is_protected(&simulation, row, file, |
487 <a class="c2html-lineno" name="l434" href="#l434">434 </a> opponent_color(piececolor)); |
487 <a class="c2html-lineno" name="l434" href="#l434">434 </a> opponent_color(piececolor)); |
488 <a class="c2html-lineno" name="l435" href="#l435">435 </a> } |
488 <a class="c2html-lineno" name="l435" href="#l435">435 </a> } |
489 <a class="c2html-lineno" name="l436" href="#l436">436 </a> } |
489 <a class="c2html-lineno" name="l436" href="#l436">436 </a> } |
490 <a class="c2html-lineno" name="l437" href="#l437">437 </a> } |
490 <a class="c2html-lineno" name="l437" href="#l437">437 </a> } |
491 <a class="c2html-lineno" name="l438" href="#l438">438 </a> } |
491 <a class="c2html-lineno" name="l438" href="#l438">438 </a> } |
493 <a class="c2html-lineno" name="l440" href="#l440">440 </a> <span class="c2html-keyword">if</span> (!canescape) { |
493 <a class="c2html-lineno" name="l440" href="#l440">440 </a> <span class="c2html-keyword">if</span> (!canescape) { |
494 <a class="c2html-lineno" name="l441" href="#l441">441 </a> gamestate->checkmate = <span class="c2html-macroconst">1</span>; |
494 <a class="c2html-lineno" name="l441" href="#l441">441 </a> gamestate->checkmate = <span class="c2html-macroconst">1</span>; |
495 <a class="c2html-lineno" name="l442" href="#l442">442 </a> } |
495 <a class="c2html-lineno" name="l442" href="#l442">442 </a> } |
496 <a class="c2html-lineno" name="l443" href="#l443">443 </a> } |
496 <a class="c2html-lineno" name="l443" href="#l443">443 </a> } |
497 <a class="c2html-lineno" name="l444" href="#l444">444 </a> |
497 <a class="c2html-lineno" name="l444" href="#l444">444 </a> |
498 <a class="c2html-lineno" name="l445" href="#l445">445 </a> gamestate_cleanup(&simulation); |
498 <a class="c2html-lineno" name="l445" href="#l445">445 </a> gamestate_cleanup(&simulation); |
499 <a class="c2html-lineno" name="l446" href="#l446">446 </a> |
499 <a class="c2html-lineno" name="l446" href="#l446">446 </a> |
500 <a class="c2html-lineno" name="l447" href="#l447">447 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>; |
500 <a class="c2html-lineno" name="l447" href="#l447">447 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>; |
501 <a class="c2html-lineno" name="l448" href="#l448">448 </a>} |
501 <a class="c2html-lineno" name="l448" href="#l448">448 </a>} |
502 <a class="c2html-lineno" name="l449" href="#l449">449 </a> |
502 <a class="c2html-lineno" name="l449" href="#l449">449 </a> |
503 <a class="c2html-lineno" name="l450" href="#l450">450 </a>_Bool get_threats(GameState *gamestate, <span class="c2html-type">uint8_t</span> row, <span class="c2html-type">uint8_t</span> file, |
503 <a class="c2html-lineno" name="l450" href="#l450">450 </a>_Bool get_threats(GameState *gamestate, <span class="c2html-type">uint8_t</span> row, <span class="c2html-type">uint8_t</span> file, |
504 <a class="c2html-lineno" name="l451" href="#l451">451 </a> <span class="c2html-type">uint8_t</span> color, Move *threats, <span class="c2html-type">uint8_t</span> *threatcount) { |
504 <a class="c2html-lineno" name="l451" href="#l451">451 </a> <span class="c2html-type">uint8_t</span> color, Move *threats, <span class="c2html-type">uint8_t</span> *threatcount) { |
505 <a class="c2html-lineno" name="l452" href="#l452">452 </a> Move candidates[<span class="c2html-macroconst">32</span>]; |
505 <a class="c2html-lineno" name="l452" href="#l452">452 </a> Move candidates[<span class="c2html-macroconst">32</span>]; |
506 <a class="c2html-lineno" name="l453" href="#l453">453 </a> <span class="c2html-keyword">int</span> candidatecount = <span class="c2html-macroconst">0</span>; |
506 <a class="c2html-lineno" name="l453" href="#l453">453 </a> <span class="c2html-keyword">int</span> candidatecount = <span class="c2html-macroconst">0</span>; |
507 <a class="c2html-lineno" name="l454" href="#l454">454 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> r = <span class="c2html-macroconst">0</span> ; r < <span class="c2html-macroconst">8</span> ; r++) { |
507 <a class="c2html-lineno" name="l454" href="#l454">454 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> r = <span class="c2html-macroconst">0</span> ; r < <span class="c2html-macroconst">8</span> ; r++) { |
508 <a class="c2html-lineno" name="l455" href="#l455">455 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> f = <span class="c2html-macroconst">0</span> ; f < <span class="c2html-macroconst">8</span> ; f++) { |
508 <a class="c2html-lineno" name="l455" href="#l455">455 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> f = <span class="c2html-macroconst">0</span> ; f < <span class="c2html-macroconst">8</span> ; f++) { |
509 <a class="c2html-lineno" name="l456" href="#l456">456 </a> <span class="c2html-keyword">if</span> ((gamestate->board[r][f] & <span class="c2html-macroconst">COLOR_MASK</span>) == color) { |
509 <a class="c2html-lineno" name="l456" href="#l456">456 </a> <span class="c2html-keyword">if</span> ((gamestate->board[r][f] & <span class="c2html-macroconst">COLOR_MASK</span>) == color) { |
510 <a class="c2html-lineno" name="l457" href="#l457">457 </a> <span class="c2html-comment">// non-capturing move</span> |
510 <a class="c2html-lineno" name="l457" href="#l457">457 </a> <span class="c2html-comment">// non-capturing move</span> |
511 <a class="c2html-lineno" name="l458" href="#l458">458 </a> memset(&(candidates[candidatecount]), <span class="c2html-macroconst">0</span>, <span class="c2html-keyword">sizeof</span>(Move)); |
511 <a class="c2html-lineno" name="l458" href="#l458">458 </a> memset(&(candidates[candidatecount]), <span class="c2html-macroconst">0</span>, <span class="c2html-keyword">sizeof</span>(Move)); |
512 <a class="c2html-lineno" name="l459" href="#l459">459 </a> candidates[candidatecount].piece = gamestate->board[r][f]; |
512 <a class="c2html-lineno" name="l459" href="#l459">459 </a> candidates[candidatecount].piece = gamestate->board[r][f]; |
513 <a class="c2html-lineno" name="l460" href="#l460">460 </a> candidates[candidatecount].fromrow = r; |
513 <a class="c2html-lineno" name="l460" href="#l460">460 </a> candidates[candidatecount].fromrow = r; |
514 <a class="c2html-lineno" name="l461" href="#l461">461 </a> candidates[candidatecount].fromfile = f; |
514 <a class="c2html-lineno" name="l461" href="#l461">461 </a> candidates[candidatecount].fromfile = f; |
515 <a class="c2html-lineno" name="l462" href="#l462">462 </a> candidates[candidatecount].torow = row; |
515 <a class="c2html-lineno" name="l462" href="#l462">462 </a> candidates[candidatecount].torow = row; |
516 <a class="c2html-lineno" name="l463" href="#l463">463 </a> candidates[candidatecount].tofile = file; |
516 <a class="c2html-lineno" name="l463" href="#l463">463 </a> candidates[candidatecount].tofile = file; |
517 <a class="c2html-lineno" name="l464" href="#l464">464 </a> candidatecount++; |
517 <a class="c2html-lineno" name="l464" href="#l464">464 </a> candidatecount++; |
518 <a class="c2html-lineno" name="l465" href="#l465">465 </a> |
518 <a class="c2html-lineno" name="l465" href="#l465">465 </a> |
519 <a class="c2html-lineno" name="l466" href="#l466">466 </a> <span class="c2html-comment">// capturing move</span> |
519 <a class="c2html-lineno" name="l466" href="#l466">466 </a> <span class="c2html-comment">// capturing move</span> |
520 <a class="c2html-lineno" name="l467" href="#l467">467 </a> memcpy(&(candidates[candidatecount]), |
520 <a class="c2html-lineno" name="l467" href="#l467">467 </a> memcpy(&(candidates[candidatecount]), |
521 <a class="c2html-lineno" name="l468" href="#l468">468 </a> &(candidates[candidatecount-<span class="c2html-macroconst">1</span>]), <span class="c2html-keyword">sizeof</span>(Move)); |
521 <a class="c2html-lineno" name="l468" href="#l468">468 </a> &(candidates[candidatecount-<span class="c2html-macroconst">1</span>]), <span class="c2html-keyword">sizeof</span>(Move)); |
522 <a class="c2html-lineno" name="l469" href="#l469">469 </a> candidates[candidatecount].capture = <span class="c2html-macroconst">1</span>; |
522 <a class="c2html-lineno" name="l469" href="#l469">469 </a> candidates[candidatecount].capture = <span class="c2html-macroconst">1</span>; |
523 <a class="c2html-lineno" name="l470" href="#l470">470 </a> candidatecount++; |
523 <a class="c2html-lineno" name="l470" href="#l470">470 </a> candidatecount++; |
524 <a class="c2html-lineno" name="l471" href="#l471">471 </a> } |
524 <a class="c2html-lineno" name="l471" href="#l471">471 </a> } |
525 <a class="c2html-lineno" name="l472" href="#l472">472 </a> } |
525 <a class="c2html-lineno" name="l472" href="#l472">472 </a> } |
526 <a class="c2html-lineno" name="l473" href="#l473">473 </a> } |
526 <a class="c2html-lineno" name="l473" href="#l473">473 </a> } |
531 <a class="c2html-lineno" name="l478" href="#l478">478 </a> |
531 <a class="c2html-lineno" name="l478" href="#l478">478 </a> |
532 <a class="c2html-lineno" name="l479" href="#l479">479 </a> |
532 <a class="c2html-lineno" name="l479" href="#l479">479 </a> |
533 <a class="c2html-lineno" name="l480" href="#l480">480 </a> _Bool result = <span class="c2html-macroconst">0</span>; |
533 <a class="c2html-lineno" name="l480" href="#l480">480 </a> _Bool result = <span class="c2html-macroconst">0</span>; |
534 <a class="c2html-lineno" name="l481" href="#l481">481 </a> |
534 <a class="c2html-lineno" name="l481" href="#l481">481 </a> |
535 <a class="c2html-lineno" name="l482" href="#l482">482 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> i = <span class="c2html-macroconst">0</span> ; i < candidatecount ; i++) { |
535 <a class="c2html-lineno" name="l482" href="#l482">482 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> i = <span class="c2html-macroconst">0</span> ; i < candidatecount ; i++) { |
536 <a class="c2html-lineno" name="l483" href="#l483">483 </a> <span class="c2html-keyword">if</span> (validate_move_rules(gamestate, &(candidates[i])) |
536 <a class="c2html-lineno" name="l483" href="#l483">483 </a> <span class="c2html-keyword">if</span> (validate_move_rules(gamestate, &(candidates[i])) |
537 <a class="c2html-lineno" name="l484" href="#l484">484 </a> == <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>) { |
537 <a class="c2html-lineno" name="l484" href="#l484">484 </a> == <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>) { |
538 <a class="c2html-lineno" name="l485" href="#l485">485 </a> result = <span class="c2html-macroconst">1</span>; |
538 <a class="c2html-lineno" name="l485" href="#l485">485 </a> result = <span class="c2html-macroconst">1</span>; |
539 <a class="c2html-lineno" name="l486" href="#l486">486 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { |
539 <a class="c2html-lineno" name="l486" href="#l486">486 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { |
540 <a class="c2html-lineno" name="l487" href="#l487">487 </a> threats[(*threatcount)++] = candidates[i]; |
540 <a class="c2html-lineno" name="l487" href="#l487">487 </a> threats[(*threatcount)++] = candidates[i]; |
541 <a class="c2html-lineno" name="l488" href="#l488">488 </a> } |
541 <a class="c2html-lineno" name="l488" href="#l488">488 </a> } |
542 <a class="c2html-lineno" name="l489" href="#l489">489 </a> } |
542 <a class="c2html-lineno" name="l489" href="#l489">489 </a> } |
543 <a class="c2html-lineno" name="l490" href="#l490">490 </a> } |
543 <a class="c2html-lineno" name="l490" href="#l490">490 </a> } |
544 <a class="c2html-lineno" name="l491" href="#l491">491 </a> |
544 <a class="c2html-lineno" name="l491" href="#l491">491 </a> |
545 <a class="c2html-lineno" name="l492" href="#l492">492 </a> <span class="c2html-keyword">return</span> result; |
545 <a class="c2html-lineno" name="l492" href="#l492">492 </a> <span class="c2html-keyword">return</span> result; |
546 <a class="c2html-lineno" name="l493" href="#l493">493 </a>} |
546 <a class="c2html-lineno" name="l493" href="#l493">493 </a>} |
547 <a class="c2html-lineno" name="l494" href="#l494">494 </a> |
547 <a class="c2html-lineno" name="l494" href="#l494">494 </a> |
548 <a class="c2html-lineno" name="l495" href="#l495">495 </a>_Bool is_pinned(GameState *gamestate, Move *move) { |
548 <a class="c2html-lineno" name="l495" href="#l495">495 </a>_Bool is_pinned(GameState *gamestate, Move *move) { |
549 <a class="c2html-lineno" name="l496" href="#l496">496 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
549 <a class="c2html-lineno" name="l496" href="#l496">496 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
550 <a class="c2html-lineno" name="l497" href="#l497">497 </a> |
550 <a class="c2html-lineno" name="l497" href="#l497">497 </a> |
551 <a class="c2html-lineno" name="l498" href="#l498">498 </a> <span class="c2html-type">uint8_t</span> kingfile = <span class="c2html-macroconst">0</span>, kingrow = <span class="c2html-macroconst">0</span>; |
551 <a class="c2html-lineno" name="l498" href="#l498">498 </a> <span class="c2html-type">uint8_t</span> kingfile = <span class="c2html-macroconst">0</span>, kingrow = <span class="c2html-macroconst">0</span>; |
552 <a class="c2html-lineno" name="l499" href="#l499">499 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> row = <span class="c2html-macroconst">0</span> ; row < <span class="c2html-macroconst">8</span> ; row++) { |
552 <a class="c2html-lineno" name="l499" href="#l499">499 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> row = <span class="c2html-macroconst">0</span> ; row < <span class="c2html-macroconst">8</span> ; row++) { |
553 <a class="c2html-lineno" name="l500" href="#l500">500 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> file = <span class="c2html-macroconst">0</span> ; file < <span class="c2html-macroconst">8</span> ; file++) { |
553 <a class="c2html-lineno" name="l500" href="#l500">500 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> file = <span class="c2html-macroconst">0</span> ; file < <span class="c2html-macroconst">8</span> ; file++) { |
554 <a class="c2html-lineno" name="l501" href="#l501">501 </a> <span class="c2html-keyword">if</span> (gamestate->board[row][file] == (color|<span class="c2html-macroconst">KING</span>)) { |
554 <a class="c2html-lineno" name="l501" href="#l501">501 </a> <span class="c2html-keyword">if</span> (gamestate->board[row][file] == (color|<span class="c2html-macroconst">KING</span>)) { |
609 <a class="c2html-lineno" name="l556" href="#l556">556 </a> } |
609 <a class="c2html-lineno" name="l556" href="#l556">556 </a> } |
610 <a class="c2html-lineno" name="l557" href="#l557">557 </a>} |
610 <a class="c2html-lineno" name="l557" href="#l557">557 </a>} |
611 <a class="c2html-lineno" name="l558" href="#l558">558 </a> |
611 <a class="c2html-lineno" name="l558" href="#l558">558 </a> |
612 <a class="c2html-lineno" name="l559" href="#l559">559 </a><span class="c2html-keyword">static</span> <span class="c2html-keyword">int</span> getlocation(GameState *gamestate, Move *move) { |
612 <a class="c2html-lineno" name="l559" href="#l559">559 </a><span class="c2html-keyword">static</span> <span class="c2html-keyword">int</span> getlocation(GameState *gamestate, Move *move) { |
613 <a class="c2html-lineno" name="l560" href="#l560">560 </a> |
613 <a class="c2html-lineno" name="l560" href="#l560">560 </a> |
614 <a class="c2html-lineno" name="l561" href="#l561">561 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
614 <a class="c2html-lineno" name="l561" href="#l561">561 </a> <span class="c2html-type">uint8_t</span> color = move->piece & <span class="c2html-macroconst">COLOR_MASK</span>; |
615 <a class="c2html-lineno" name="l562" href="#l562">562 </a> _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:<span class="c2html-macroconst">0</span>; |
615 <a class="c2html-lineno" name="l562" href="#l562">562 </a> _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:<span class="c2html-macroconst">0</span>; |
616 <a class="c2html-lineno" name="l563" href="#l563">563 </a> |
616 <a class="c2html-lineno" name="l563" href="#l563">563 </a> |
617 <a class="c2html-lineno" name="l564" href="#l564">564 </a> Move threats[<span class="c2html-macroconst">16</span>], *threat = <span class="c2html-macroconst">NULL</span>; |
617 <a class="c2html-lineno" name="l564" href="#l564">564 </a> Move threats[<span class="c2html-macroconst">16</span>], *threat = <span class="c2html-macroconst">NULL</span>; |
618 <a class="c2html-lineno" name="l565" href="#l565">565 </a> <span class="c2html-type">uint8_t</span> threatcount; |
618 <a class="c2html-lineno" name="l565" href="#l565">565 </a> <span class="c2html-type">uint8_t</span> threatcount; |
619 <a class="c2html-lineno" name="l566" href="#l566">566 </a> |
619 <a class="c2html-lineno" name="l566" href="#l566">566 </a> |
620 <a class="c2html-lineno" name="l567" href="#l567">567 </a> <span class="c2html-keyword">if</span> (get_threats(gamestate, move->torow, move->tofile, color, |
620 <a class="c2html-lineno" name="l567" href="#l567">567 </a> <span class="c2html-keyword">if</span> (get_threats(gamestate, move->torow, move->tofile, color, |
621 <a class="c2html-lineno" name="l568" href="#l568">568 </a> threats, &threatcount)) { |
621 <a class="c2html-lineno" name="l568" href="#l568">568 </a> threats, &threatcount)) { |
622 <a class="c2html-lineno" name="l569" href="#l569">569 </a> |
622 <a class="c2html-lineno" name="l569" href="#l569">569 </a> |
623 <a class="c2html-lineno" name="l570" href="#l570">570 </a> <span class="c2html-keyword">int</span> reason = <span class="c2html-macroconst">INVALID_POSITION</span>; |
623 <a class="c2html-lineno" name="l570" href="#l570">570 </a> <span class="c2html-keyword">int</span> reason = <span class="c2html-macroconst">INVALID_POSITION</span>; |
624 <a class="c2html-lineno" name="l571" href="#l571">571 </a> |
624 <a class="c2html-lineno" name="l571" href="#l571">571 </a> |
625 <a class="c2html-lineno" name="l572" href="#l572">572 </a> <span class="c2html-comment">// find threats for the specified position</span> |
625 <a class="c2html-lineno" name="l572" href="#l572">572 </a> <span class="c2html-comment">// find threats for the specified position</span> |
626 <a class="c2html-lineno" name="l573" href="#l573">573 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> i = <span class="c2html-macroconst">0</span> ; i < threatcount ; i++) { |
626 <a class="c2html-lineno" name="l573" href="#l573">573 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> i = <span class="c2html-macroconst">0</span> ; i < threatcount ; i++) { |
627 <a class="c2html-lineno" name="l574" href="#l574">574 </a> <span class="c2html-keyword">if</span> ((threats[i].piece & (<span class="c2html-macroconst">PIECE_MASK</span> | <span class="c2html-macroconst">COLOR_MASK</span>)) |
627 <a class="c2html-lineno" name="l574" href="#l574">574 </a> <span class="c2html-keyword">if</span> ((threats[i].piece & (<span class="c2html-macroconst">PIECE_MASK</span> | <span class="c2html-macroconst">COLOR_MASK</span>)) |
628 <a class="c2html-lineno" name="l575" href="#l575">575 </a> == move->piece && |
628 <a class="c2html-lineno" name="l575" href="#l575">575 </a> == move->piece && |
629 <a class="c2html-lineno" name="l576" href="#l576">576 </a> (move->fromrow == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || |
629 <a class="c2html-lineno" name="l576" href="#l576">576 </a> (move->fromrow == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || |
630 <a class="c2html-lineno" name="l577" href="#l577">577 </a> move->fromrow == threats[i].fromrow) && |
630 <a class="c2html-lineno" name="l577" href="#l577">577 </a> move->fromrow == threats[i].fromrow) && |
631 <a class="c2html-lineno" name="l578" href="#l578">578 </a> (move->fromfile == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || |
631 <a class="c2html-lineno" name="l578" href="#l578">578 </a> (move->fromfile == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || |
632 <a class="c2html-lineno" name="l579" href="#l579">579 </a> move->fromfile == threats[i].fromfile)) { |
632 <a class="c2html-lineno" name="l579" href="#l579">579 </a> move->fromfile == threats[i].fromfile)) { |
633 <a class="c2html-lineno" name="l580" href="#l580">580 </a> |
633 <a class="c2html-lineno" name="l580" href="#l580">580 </a> |
634 <a class="c2html-lineno" name="l581" href="#l581">581 </a> <span class="c2html-keyword">if</span> (threat) { |
634 <a class="c2html-lineno" name="l581" href="#l581">581 </a> <span class="c2html-keyword">if</span> (threat) { |
635 <a class="c2html-lineno" name="l582" href="#l582">582 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">AMBIGUOUS_MOVE</span>; |
635 <a class="c2html-lineno" name="l582" href="#l582">582 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">AMBIGUOUS_MOVE</span>; |
636 <a class="c2html-lineno" name="l583" href="#l583">583 </a> } <span class="c2html-keyword">else</span> { |
636 <a class="c2html-lineno" name="l583" href="#l583">583 </a> } <span class="c2html-keyword">else</span> { |
637 <a class="c2html-lineno" name="l584" href="#l584">584 </a> <span class="c2html-comment">// found threat is no real threat</span> |
637 <a class="c2html-lineno" name="l584" href="#l584">584 </a> <span class="c2html-comment">// found threat is no real threat</span> |
638 <a class="c2html-lineno" name="l585" href="#l585">585 </a> <span class="c2html-keyword">if</span> (is_pinned(gamestate, &(threats[i]))) { |
638 <a class="c2html-lineno" name="l585" href="#l585">585 </a> <span class="c2html-keyword">if</span> (is_pinned(gamestate, &(threats[i]))) { |
639 <a class="c2html-lineno" name="l586" href="#l586">586 </a> reason = incheck?<span class="c2html-macroconst">KING_IN_CHECK</span>:<span class="c2html-macroconst">PIECE_PINNED</span>; |
639 <a class="c2html-lineno" name="l586" href="#l586">586 </a> reason = incheck?<span class="c2html-macroconst">KING_IN_CHECK</span>:<span class="c2html-macroconst">PIECE_PINNED</span>; |
640 <a class="c2html-lineno" name="l587" href="#l587">587 </a> } <span class="c2html-keyword">else</span> { |
640 <a class="c2html-lineno" name="l587" href="#l587">587 </a> } <span class="c2html-keyword">else</span> { |
641 <a class="c2html-lineno" name="l588" href="#l588">588 </a> threat = &(threats[i]); |
641 <a class="c2html-lineno" name="l588" href="#l588">588 </a> threat = &(threats[i]); |
642 <a class="c2html-lineno" name="l589" href="#l589">589 </a> } |
642 <a class="c2html-lineno" name="l589" href="#l589">589 </a> } |
643 <a class="c2html-lineno" name="l590" href="#l590">590 </a> } |
643 <a class="c2html-lineno" name="l590" href="#l590">590 </a> } |
644 <a class="c2html-lineno" name="l591" href="#l591">591 </a> } |
644 <a class="c2html-lineno" name="l591" href="#l591">591 </a> } |
645 <a class="c2html-lineno" name="l592" href="#l592">592 </a> } |
645 <a class="c2html-lineno" name="l592" href="#l592">592 </a> } |
646 <a class="c2html-lineno" name="l593" href="#l593">593 </a> |
646 <a class="c2html-lineno" name="l593" href="#l593">593 </a> |