--- a/test/gs/bigtest.html Thu Jul 11 19:41:06 2024 +0200 +++ b/test/gs/bigtest.html Thu Jul 11 20:05:21 2024 +0200 @@ -131,7 +131,7 @@ <a class="c2html-lineno" name="l78" href="#l78"> 78 </a> memset(string, <span class="c2html-macroconst">0</span>, <span class="c2html-macroconst">8</span>); <a class="c2html-lineno" name="l79" href="#l79"> 79 </a> <a class="c2html-lineno" name="l80" href="#l80"> 80 </a> <span class="c2html-comment">/* special formats for castling */</span> -<a class="c2html-lineno" name="l81" href="#l81"> 81 </a> <span class="c2html-keyword">if</span> ((move->piece&<span class="c2html-macroconst">PIECE_MASK</span>) == <span class="c2html-macroconst">KING</span> && +<a class="c2html-lineno" name="l81" href="#l81"> 81 </a> <span class="c2html-keyword">if</span> ((move->piece&<span class="c2html-macroconst">PIECE_MASK</span>) == <span class="c2html-macroconst">KING</span> && <a class="c2html-lineno" name="l82" href="#l82"> 82 </a> abs(move->tofile-move->fromfile) == <span class="c2html-macroconst">2</span>) { <a class="c2html-lineno" name="l83" href="#l83"> 83 </a> <span class="c2html-keyword">if</span> (move->tofile==fileidx(<span class="c2html-string">'c'</span>)) { <a class="c2html-lineno" name="l84" href="#l84"> 84 </a> memcpy(string, <span class="c2html-string">"O-O-O"</span>, <span class="c2html-macroconst">5</span>); @@ -145,7 +145,7 @@ <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>; <a class="c2html-lineno" name="l93" href="#l93"> 93 </a> <a class="c2html-lineno" name="l94" href="#l94"> 94 </a> <span class="c2html-comment">/* find out how many source information we do need */</span> -<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>; +<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>; <a class="c2html-lineno" name="l96" href="#l96"> 96 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span>) { <a class="c2html-lineno" name="l97" href="#l97"> 97 </a> <span class="c2html-keyword">if</span> (move->capture) { <a class="c2html-lineno" name="l98" href="#l98"> 98 </a> string[idx++] = filechr(move->fromfile); @@ -154,7 +154,7 @@ <a class="c2html-lineno" name="l101" href="#l101">101 </a> Move threats[<span class="c2html-macroconst">16</span>]; <a class="c2html-lineno" name="l102" href="#l102">102 </a> <span class="c2html-type">uint8_t</span> threatcount; <a class="c2html-lineno" name="l103" href="#l103">103 </a> get_real_threats(gamestate, move->torow, move->tofile, -<a class="c2html-lineno" name="l104" href="#l104">104 </a> move->piece&<span class="c2html-macroconst">COLOR_MASK</span>, threats, &threatcount); +<a class="c2html-lineno" name="l104" href="#l104">104 </a> move->piece&<span class="c2html-macroconst">COLOR_MASK</span>, threats, &threatcount); <a class="c2html-lineno" name="l105" href="#l105">105 </a> <span class="c2html-keyword">if</span> (threatcount > <span class="c2html-macroconst">1</span>) { <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>; <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++) { @@ -204,12 +204,12 @@ <a class="c2html-lineno" name="l151" href="#l151">151 </a> elem->move = *move; <a class="c2html-lineno" name="l152" href="#l152">152 </a> <a class="c2html-lineno" name="l153" href="#l153">153 </a> <span class="c2html-keyword">struct</span> timeval curtimestamp; -<a class="c2html-lineno" name="l154" href="#l154">154 </a> gettimeofday(&curtimestamp, <span class="c2html-macroconst">NULL</span>); +<a class="c2html-lineno" name="l154" href="#l154">154 </a> gettimeofday(&curtimestamp, <span class="c2html-macroconst">NULL</span>); <a class="c2html-lineno" name="l155" href="#l155">155 </a> elem->move.timestamp.tv_sec = curtimestamp.tv_sec; <a class="c2html-lineno" name="l156" href="#l156">156 </a> elem->move.timestamp.tv_usec = curtimestamp.tv_usec; <a class="c2html-lineno" name="l157" href="#l157">157 </a> <a class="c2html-lineno" name="l158" href="#l158">158 </a> <span class="c2html-keyword">if</span> (gamestate->lastmove) { -<a class="c2html-lineno" name="l159" href="#l159">159 </a> <span class="c2html-keyword">struct</span> movetimeval *lasttstamp = &(gamestate->lastmove->move.timestamp); +<a class="c2html-lineno" name="l159" href="#l159">159 </a> <span class="c2html-keyword">struct</span> movetimeval *lasttstamp = &(gamestate->lastmove->move.timestamp); <a class="c2html-lineno" name="l160" href="#l160">160 </a> <span class="c2html-type">uint64_t</span> sec = curtimestamp.tv_sec - lasttstamp->tv_sec; <a class="c2html-lineno" name="l161" href="#l161">161 </a> <span class="c2html-type">suseconds_t</span> micros; <a class="c2html-lineno" name="l162" href="#l162">162 </a> <span class="c2html-keyword">if</span> (curtimestamp.tv_usec < lasttstamp->tv_usec) { @@ -232,7 +232,7 @@ <a class="c2html-lineno" name="l179" href="#l179">179 </a>} <a class="c2html-lineno" name="l180" href="#l180">180 </a> <a class="c2html-lineno" name="l181" href="#l181">181 </a><span class="c2html-keyword">char</span> getpiecechr(<span class="c2html-type">uint8_t</span> piece) { -<a class="c2html-lineno" name="l182" href="#l182">182 </a> <span class="c2html-keyword">switch</span> (piece & <span class="c2html-macroconst">PIECE_MASK</span>) { +<a class="c2html-lineno" name="l182" href="#l182">182 </a> <span class="c2html-keyword">switch</span> (piece & <span class="c2html-macroconst">PIECE_MASK</span>) { <a class="c2html-lineno" name="l183" href="#l183">183 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">ROOK</span>: <span class="c2html-keyword">return</span> <span class="c2html-string">'R'</span>; <a class="c2html-lineno" name="l184" href="#l184">184 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KNIGHT</span>: <span class="c2html-keyword">return</span> <span class="c2html-string">'N'</span>; <a class="c2html-lineno" name="l185" href="#l185">185 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">BISHOP</span>: <span class="c2html-keyword">return</span> <span class="c2html-string">'B'</span>; @@ -254,25 +254,25 @@ <a class="c2html-lineno" name="l201" href="#l201">201 </a>} <a class="c2html-lineno" name="l202" href="#l202">202 </a> <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) { -<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>; -<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>; +<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>; +<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>; <a class="c2html-lineno" name="l206" href="#l206">206 </a> <a class="c2html-lineno" name="l207" href="#l207">207 </a> <span class="c2html-comment">/* en passant capture */</span> -<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> && +<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> && <a class="c2html-lineno" name="l209" href="#l209">209 </a> mdst(gamestate->board, move) == <span class="c2html-macroconst">0</span>) { <a class="c2html-lineno" name="l210" href="#l210">210 </a> gamestate->board[move->fromrow][move->tofile] = <span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l211" href="#l211">211 </a> } <a class="c2html-lineno" name="l212" href="#l212">212 </a> <a class="c2html-lineno" name="l213" href="#l213">213 </a> <span class="c2html-comment">/* remove old en passant threats */</span> <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++) { -<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>; -<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>; +<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>; +<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>; <a class="c2html-lineno" name="l217" href="#l217">217 </a> } <a class="c2html-lineno" name="l218" href="#l218">218 </a> <a class="c2html-lineno" name="l219" href="#l219">219 </a> <span class="c2html-comment">/* add new en passant threat */</span> -<a class="c2html-lineno" name="l220" href="#l220">220 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span> && ( -<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>) || -<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>))) { +<a class="c2html-lineno" name="l220" href="#l220">220 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">PAWN</span> && ( +<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>) || +<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>))) { <a class="c2html-lineno" name="l223" href="#l223">223 </a> move->piece |= <span class="c2html-macroconst">ENPASSANT_THREAT</span>; <a class="c2html-lineno" name="l224" href="#l224">224 </a> } <a class="c2html-lineno" name="l225" href="#l225">225 </a> @@ -285,7 +285,7 @@ <a class="c2html-lineno" name="l232" href="#l232">232 </a> } <a class="c2html-lineno" name="l233" href="#l233">233 </a> <a class="c2html-lineno" name="l234" href="#l234">234 </a> <span class="c2html-comment">/* castling */</span> -<a class="c2html-lineno" name="l235" href="#l235">235 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">KING</span> && move->fromfile == fileidx(<span class="c2html-string">'e'</span>)) { +<a class="c2html-lineno" name="l235" href="#l235">235 </a> <span class="c2html-keyword">if</span> (piece == <span class="c2html-macroconst">KING</span> && move->fromfile == fileidx(<span class="c2html-string">'e'</span>)) { <a class="c2html-lineno" name="l236" href="#l236">236 </a> <a class="c2html-lineno" name="l237" href="#l237">237 </a> <span class="c2html-keyword">if</span> (move->tofile == fileidx(<span class="c2html-string">'g'</span>)) { <a class="c2html-lineno" name="l238" href="#l238">238 </a> gamestate->board[move->torow][fileidx(<span class="c2html-string">'h'</span>)] = <span class="c2html-macroconst">0</span>; @@ -316,52 +316,52 @@ <a class="c2html-lineno" name="l263" href="#l263">263 </a> } <a class="c2html-lineno" name="l264" href="#l264">264 </a> <a class="c2html-lineno" name="l265" href="#l265">265 </a> <span class="c2html-comment">/* must move */</span> -<a class="c2html-lineno" name="l266" href="#l266">266 </a> <span class="c2html-keyword">if</span> (move->fromfile == move->tofile && move->fromrow == move->torow) { +<a class="c2html-lineno" name="l266" href="#l266">266 </a> <span class="c2html-keyword">if</span> (move->fromfile == move->tofile && move->fromrow == move->torow) { <a class="c2html-lineno" name="l267" href="#l267">267 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; <a class="c2html-lineno" name="l268" href="#l268">268 </a> } <a class="c2html-lineno" name="l269" href="#l269">269 </a> <a class="c2html-lineno" name="l270" href="#l270">270 </a> <span class="c2html-comment">/* does piece exist */</span> -<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>)) -<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>))) { +<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>)) +<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>))) { <a class="c2html-lineno" name="l273" href="#l273">273 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_POSITION</span>; <a class="c2html-lineno" name="l274" href="#l274">274 </a> } <a class="c2html-lineno" name="l275" href="#l275">275 </a> <a class="c2html-lineno" name="l276" href="#l276">276 </a> <span class="c2html-comment">/* can't capture own pieces */</span> -<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>) -<a class="c2html-lineno" name="l278" href="#l278">278 </a> == (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>)) { +<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>) +<a class="c2html-lineno" name="l278" href="#l278">278 </a> == (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>)) { <a class="c2html-lineno" name="l279" href="#l279">279 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">RULES_VIOLATED</span>; <a class="c2html-lineno" name="l280" href="#l280">280 </a> } <a class="c2html-lineno" name="l281" href="#l281">281 </a> <a class="c2html-lineno" name="l282" href="#l282">282 </a> <span class="c2html-comment">/* must capture, if and only if destination is occupied */</span> -<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) || -<a class="c2html-lineno" name="l284" href="#l284">284 </a> (mdst(gamestate->board, move) != <span class="c2html-macroconst">0</span> && !move->capture)) { +<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) || +<a class="c2html-lineno" name="l284" href="#l284">284 </a> (mdst(gamestate->board, move) != <span class="c2html-macroconst">0</span> && !move->capture)) { <a class="c2html-lineno" name="l285" href="#l285">285 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; <a class="c2html-lineno" name="l286" href="#l286">286 </a> } <a class="c2html-lineno" name="l287" href="#l287">287 </a> <a class="c2html-lineno" name="l288" href="#l288">288 </a> <span class="c2html-comment">/* validate individual rules */</span> <a class="c2html-lineno" name="l289" href="#l289">289 </a> _Bool chkrules; -<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>) { +<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>) { <a class="c2html-lineno" name="l291" href="#l291">291 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">PAWN</span>: -<a class="c2html-lineno" name="l292" href="#l292">292 </a> chkrules = pawn_chkrules(gamestate, move) && +<a class="c2html-lineno" name="l292" href="#l292">292 </a> chkrules = pawn_chkrules(gamestate, move) && <a class="c2html-lineno" name="l293" href="#l293">293 </a> !pawn_isblocked(gamestate, move); <a class="c2html-lineno" name="l294" href="#l294">294 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l295" href="#l295">295 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">ROOK</span>: -<a class="c2html-lineno" name="l296" href="#l296">296 </a> chkrules = rook_chkrules(move) && +<a class="c2html-lineno" name="l296" href="#l296">296 </a> chkrules = rook_chkrules(move) && <a class="c2html-lineno" name="l297" href="#l297">297 </a> !rook_isblocked(gamestate, move); <a class="c2html-lineno" name="l298" href="#l298">298 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l299" href="#l299">299 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KNIGHT</span>: <a class="c2html-lineno" name="l300" href="#l300">300 </a> chkrules = knight_chkrules(move); <span class="c2html-comment">/* knight is never blocked */</span> <a class="c2html-lineno" name="l301" href="#l301">301 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l302" href="#l302">302 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">BISHOP</span>: -<a class="c2html-lineno" name="l303" href="#l303">303 </a> chkrules = bishop_chkrules(move) && +<a class="c2html-lineno" name="l303" href="#l303">303 </a> chkrules = bishop_chkrules(move) && <a class="c2html-lineno" name="l304" href="#l304">304 </a> !bishop_isblocked(gamestate, move); <a class="c2html-lineno" name="l305" href="#l305">305 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l306" href="#l306">306 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">QUEEN</span>: -<a class="c2html-lineno" name="l307" href="#l307">307 </a> chkrules = queen_chkrules(move) && +<a class="c2html-lineno" name="l307" href="#l307">307 </a> chkrules = queen_chkrules(move) && <a class="c2html-lineno" name="l308" href="#l308">308 </a> !queen_isblocked(gamestate, move); <a class="c2html-lineno" name="l309" href="#l309">309 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l310" href="#l310">310 </a> <span class="c2html-keyword">case</span> <span class="c2html-macroconst">KING</span>: -<a class="c2html-lineno" name="l311" href="#l311">311 </a> chkrules = king_chkrules(gamestate, move) && +<a class="c2html-lineno" name="l311" href="#l311">311 </a> chkrules = king_chkrules(gamestate, move) && <a class="c2html-lineno" name="l312" href="#l312">312 </a> !king_isblocked(gamestate, move); <a class="c2html-lineno" name="l313" href="#l313">313 </a> <span class="c2html-keyword">break</span>; <a class="c2html-lineno" name="l314" href="#l314">314 </a> <span class="c2html-keyword">default</span>: @@ -381,7 +381,7 @@ <a class="c2html-lineno" name="l328" href="#l328">328 </a> } <a class="c2html-lineno" name="l329" href="#l329">329 </a> <a class="c2html-lineno" name="l330" href="#l330">330 </a> <span class="c2html-comment">/* find kings for check validation */</span> -<a class="c2html-lineno" name="l331" href="#l331">331 </a> <span class="c2html-type">uint8_t</span> piececolor = (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>); +<a class="c2html-lineno" name="l331" href="#l331">331 </a> <span class="c2html-type">uint8_t</span> piececolor = (move->piece & <span class="c2html-macroconst">COLOR_MASK</span>); <a class="c2html-lineno" name="l332" href="#l332">332 </a> <a class="c2html-lineno" name="l333" href="#l333">333 </a> <span class="c2html-type">uint8_t</span> mykingfile = <span class="c2html-macroconst">0</span>, mykingrow = <span class="c2html-macroconst">0</span>, opkingfile = <span class="c2html-macroconst">0</span>, opkingrow = <span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l334" href="#l334">334 </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++) { @@ -401,14 +401,14 @@ <a class="c2html-lineno" name="l348" href="#l348">348 </a> <span class="c2html-comment">/* simulate move for check validation */</span> <a class="c2html-lineno" name="l349" href="#l349">349 </a> GameState simulation = gamestate_copy_sim(gamestate); <a class="c2html-lineno" name="l350" href="#l350">350 </a> Move simmove = *move; -<a class="c2html-lineno" name="l351" href="#l351">351 </a> apply_move_impl(&simulation, &simmove, <span class="c2html-macroconst">1</span>); +<a class="c2html-lineno" name="l351" href="#l351">351 </a> apply_move_impl(&simulation, &simmove, <span class="c2html-macroconst">1</span>); <a class="c2html-lineno" name="l352" href="#l352">352 </a> <a class="c2html-lineno" name="l353" href="#l353">353 </a> <span class="c2html-comment">/* don't move into or stay in check position */</span> -<a class="c2html-lineno" name="l354" href="#l354">354 </a> <span class="c2html-keyword">if</span> (is_covered(&simulation, mykingrow, mykingfile, +<a class="c2html-lineno" name="l354" href="#l354">354 </a> <span class="c2html-keyword">if</span> (is_covered(&simulation, mykingrow, mykingfile, <a class="c2html-lineno" name="l355" href="#l355">355 </a> opponent_color(piececolor))) { <a class="c2html-lineno" name="l356" href="#l356">356 </a> -<a class="c2html-lineno" name="l357" href="#l357">357 </a> gamestate_cleanup(&simulation); -<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>) { +<a class="c2html-lineno" name="l357" href="#l357">357 </a> gamestate_cleanup(&simulation); +<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>) { <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>; <a class="c2html-lineno" name="l360" href="#l360">360 </a> } <span class="c2html-keyword">else</span> { <a class="c2html-lineno" name="l361" href="#l361">361 </a> <span class="c2html-comment">/* last move is always not null in this case */</span> @@ -420,36 +420,36 @@ <a class="c2html-lineno" name="l367" href="#l367">367 </a> <span class="c2html-comment">/* correct check and checkmate flags (move is still valid) */</span> <a class="c2html-lineno" name="l368" href="#l368">368 </a> Move threats[<span class="c2html-macroconst">16</span>]; <a class="c2html-lineno" name="l369" href="#l369">369 </a> <span class="c2html-type">uint8_t</span> threatcount; -<a class="c2html-lineno" name="l370" href="#l370">370 </a> move->check = get_threats(&simulation, opkingrow, opkingfile, -<a class="c2html-lineno" name="l371" href="#l371">371 </a> piececolor, threats, &threatcount); +<a class="c2html-lineno" name="l370" href="#l370">370 </a> move->check = get_threats(&simulation, opkingrow, opkingfile, +<a class="c2html-lineno" name="l371" href="#l371">371 </a> piececolor, threats, &threatcount); <a class="c2html-lineno" name="l372" href="#l372">372 </a> <a class="c2html-lineno" name="l373" href="#l373">373 </a> <span class="c2html-keyword">if</span> (move->check) { <a class="c2html-lineno" name="l374" href="#l374">374 </a> <span class="c2html-comment">/* determine possible escape fields */</span> <a class="c2html-lineno" name="l375" href="#l375">375 </a> _Bool canescape = <span class="c2html-macroconst">0</span>; -<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++) { -<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++) { -<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>) && -<a class="c2html-lineno" name="l379" href="#l379">379 </a> isidx(opkingrow + dr) && isidx(opkingfile + df)) { +<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++) { +<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++) { +<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>) && +<a class="c2html-lineno" name="l379" href="#l379">379 </a> isidx(opkingrow + dr) && isidx(opkingfile + df)) { <a class="c2html-lineno" name="l380" href="#l380">380 </a> <a class="c2html-lineno" name="l381" href="#l381">381 </a> <span class="c2html-comment">/* escape field neither blocked nor covered */</span> <a class="c2html-lineno" name="l382" href="#l382">382 </a> <span class="c2html-keyword">if</span> ((simulation.board[opkingrow + dr][opkingfile + df] -<a class="c2html-lineno" name="l383" href="#l383">383 </a> & <span class="c2html-macroconst">COLOR_MASK</span>) != opponent_color(piececolor)) { -<a class="c2html-lineno" name="l384" href="#l384">384 </a> canescape |= !is_covered(&simulation, +<a class="c2html-lineno" name="l383" href="#l383">383 </a> & <span class="c2html-macroconst">COLOR_MASK</span>) != opponent_color(piececolor)) { +<a class="c2html-lineno" name="l384" href="#l384">384 </a> canescape |= !is_covered(&simulation, <a class="c2html-lineno" name="l385" href="#l385">385 </a> opkingrow + dr, opkingfile + df, piececolor); <a class="c2html-lineno" name="l386" href="#l386">386 </a> } <a class="c2html-lineno" name="l387" href="#l387">387 </a> } <a class="c2html-lineno" name="l388" href="#l388">388 </a> } <a class="c2html-lineno" name="l389" href="#l389">389 </a> } <a class="c2html-lineno" name="l390" href="#l390">390 </a> <span class="c2html-comment">/* can't escape, can he capture? */</span> -<a class="c2html-lineno" name="l391" href="#l391">391 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { -<a class="c2html-lineno" name="l392" href="#l392">392 </a> canescape = is_attacked(&simulation, threats[<span class="c2html-macroconst">0</span>].fromrow, +<a class="c2html-lineno" name="l391" href="#l391">391 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { +<a class="c2html-lineno" name="l392" href="#l392">392 </a> canescape = is_attacked(&simulation, threats[<span class="c2html-macroconst">0</span>].fromrow, <a class="c2html-lineno" name="l393" href="#l393">393 </a> threats[<span class="c2html-macroconst">0</span>].fromfile, opponent_color(piececolor)); <a class="c2html-lineno" name="l394" href="#l394">394 </a> } <a class="c2html-lineno" name="l395" href="#l395">395 </a> <a class="c2html-lineno" name="l396" href="#l396">396 </a> <span class="c2html-comment">/* can't capture, can he block? */</span> -<a class="c2html-lineno" name="l397" href="#l397">397 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { -<a class="c2html-lineno" name="l398" href="#l398">398 </a> Move *threat = &(threats[<span class="c2html-macroconst">0</span>]); -<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>; +<a class="c2html-lineno" name="l397" href="#l397">397 </a> <span class="c2html-keyword">if</span> (!canescape && threatcount == <span class="c2html-macroconst">1</span>) { +<a class="c2html-lineno" name="l398" href="#l398">398 </a> Move *threat = &(threats[<span class="c2html-macroconst">0</span>]); +<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>; <a class="c2html-lineno" name="l400" href="#l400">400 </a> <a class="c2html-lineno" name="l401" href="#l401">401 </a> <span class="c2html-comment">/* knight, pawns and the king cannot be blocked */</span> <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> @@ -458,18 +458,18 @@ <a class="c2html-lineno" name="l405" href="#l405">405 </a> <span class="c2html-comment">/* rook aspect (on row) */</span> <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>; <a class="c2html-lineno" name="l407" href="#l407">407 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; -<a class="c2html-lineno" name="l408" href="#l408">408 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - d) { +<a class="c2html-lineno" name="l408" href="#l408">408 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - d) { <a class="c2html-lineno" name="l409" href="#l409">409 </a> file += d; -<a class="c2html-lineno" name="l410" href="#l410">410 </a> canescape |= is_protected(&simulation, +<a class="c2html-lineno" name="l410" href="#l410">410 </a> canescape |= is_protected(&simulation, <a class="c2html-lineno" name="l411" href="#l411">411 </a> threat->torow, file, opponent_color(piececolor)); <a class="c2html-lineno" name="l412" href="#l412">412 </a> } <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) { <a class="c2html-lineno" name="l414" href="#l414">414 </a> <span class="c2html-comment">/* rook aspect (on file) */</span> <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>; <a class="c2html-lineno" name="l416" href="#l416">416 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; -<a class="c2html-lineno" name="l417" href="#l417">417 </a> <span class="c2html-keyword">while</span> (!canescape && row != threat->torow - d) { +<a class="c2html-lineno" name="l417" href="#l417">417 </a> <span class="c2html-keyword">while</span> (!canescape && row != threat->torow - d) { <a class="c2html-lineno" name="l418" href="#l418">418 </a> row += d; -<a class="c2html-lineno" name="l419" href="#l419">419 </a> canescape |= is_protected(&simulation, +<a class="c2html-lineno" name="l419" href="#l419">419 </a> canescape |= is_protected(&simulation, <a class="c2html-lineno" name="l420" href="#l420">420 </a> row, threat->tofile, opponent_color(piececolor)); <a class="c2html-lineno" name="l421" href="#l421">421 </a> } <a class="c2html-lineno" name="l422" href="#l422">422 </a> } <span class="c2html-keyword">else</span> { @@ -479,11 +479,11 @@ <a class="c2html-lineno" name="l426" href="#l426">426 </a> <a class="c2html-lineno" name="l427" href="#l427">427 </a> <span class="c2html-type">uint8_t</span> row = threat->fromrow; <a class="c2html-lineno" name="l428" href="#l428">428 </a> <span class="c2html-type">uint8_t</span> file = threat->fromfile; -<a class="c2html-lineno" name="l429" href="#l429">429 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - df -<a class="c2html-lineno" name="l430" href="#l430">430 </a> && row != threat->torow - dr) { +<a class="c2html-lineno" name="l429" href="#l429">429 </a> <span class="c2html-keyword">while</span> (!canescape && file != threat->tofile - df +<a class="c2html-lineno" name="l430" href="#l430">430 </a> && row != threat->torow - dr) { <a class="c2html-lineno" name="l431" href="#l431">431 </a> row += dr; <a class="c2html-lineno" name="l432" href="#l432">432 </a> file += df; -<a class="c2html-lineno" name="l433" href="#l433">433 </a> canescape |= is_protected(&simulation, row, file, +<a class="c2html-lineno" name="l433" href="#l433">433 </a> canescape |= is_protected(&simulation, row, file, <a class="c2html-lineno" name="l434" href="#l434">434 </a> opponent_color(piececolor)); <a class="c2html-lineno" name="l435" href="#l435">435 </a> } <a class="c2html-lineno" name="l436" href="#l436">436 </a> } @@ -495,7 +495,7 @@ <a class="c2html-lineno" name="l442" href="#l442">442 </a> } <a class="c2html-lineno" name="l443" href="#l443">443 </a> } <a class="c2html-lineno" name="l444" href="#l444">444 </a> -<a class="c2html-lineno" name="l445" href="#l445">445 </a> gamestate_cleanup(&simulation); +<a class="c2html-lineno" name="l445" href="#l445">445 </a> gamestate_cleanup(&simulation); <a class="c2html-lineno" name="l446" href="#l446">446 </a> <a class="c2html-lineno" name="l447" href="#l447">447 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>; <a class="c2html-lineno" name="l448" href="#l448">448 </a>} @@ -506,9 +506,9 @@ <a class="c2html-lineno" name="l453" href="#l453">453 </a> <span class="c2html-keyword">int</span> candidatecount = <span class="c2html-macroconst">0</span>; <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++) { <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++) { -<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) { +<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) { <a class="c2html-lineno" name="l457" href="#l457">457 </a> <span class="c2html-comment">// non-capturing move</span> -<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)); +<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)); <a class="c2html-lineno" name="l459" href="#l459">459 </a> candidates[candidatecount].piece = gamestate->board[r][f]; <a class="c2html-lineno" name="l460" href="#l460">460 </a> candidates[candidatecount].fromrow = r; <a class="c2html-lineno" name="l461" href="#l461">461 </a> candidates[candidatecount].fromfile = f; @@ -517,8 +517,8 @@ <a class="c2html-lineno" name="l464" href="#l464">464 </a> candidatecount++; <a class="c2html-lineno" name="l465" href="#l465">465 </a> <a class="c2html-lineno" name="l466" href="#l466">466 </a> <span class="c2html-comment">// capturing move</span> -<a class="c2html-lineno" name="l467" href="#l467">467 </a> memcpy(&(candidates[candidatecount]), -<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)); +<a class="c2html-lineno" name="l467" href="#l467">467 </a> memcpy(&(candidates[candidatecount]), +<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)); <a class="c2html-lineno" name="l469" href="#l469">469 </a> candidates[candidatecount].capture = <span class="c2html-macroconst">1</span>; <a class="c2html-lineno" name="l470" href="#l470">470 </a> candidatecount++; <a class="c2html-lineno" name="l471" href="#l471">471 </a> } @@ -533,10 +533,10 @@ <a class="c2html-lineno" name="l480" href="#l480">480 </a> _Bool result = <span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l481" href="#l481">481 </a> <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++) { -<a class="c2html-lineno" name="l483" href="#l483">483 </a> <span class="c2html-keyword">if</span> (validate_move_rules(gamestate, &(candidates[i])) +<a class="c2html-lineno" name="l483" href="#l483">483 </a> <span class="c2html-keyword">if</span> (validate_move_rules(gamestate, &(candidates[i])) <a class="c2html-lineno" name="l484" href="#l484">484 </a> == <span class="c2html-macroconst">VALID_MOVE_SEMANTICS</span>) { <a class="c2html-lineno" name="l485" href="#l485">485 </a> result = <span class="c2html-macroconst">1</span>; -<a class="c2html-lineno" name="l486" href="#l486">486 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { +<a class="c2html-lineno" name="l486" href="#l486">486 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { <a class="c2html-lineno" name="l487" href="#l487">487 </a> threats[(*threatcount)++] = candidates[i]; <a class="c2html-lineno" name="l488" href="#l488">488 </a> } <a class="c2html-lineno" name="l489" href="#l489">489 </a> } @@ -546,7 +546,7 @@ <a class="c2html-lineno" name="l493" href="#l493">493 </a>} <a class="c2html-lineno" name="l494" href="#l494">494 </a> <a class="c2html-lineno" name="l495" href="#l495">495 </a>_Bool is_pinned(GameState *gamestate, Move *move) { -<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>; +<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>; <a class="c2html-lineno" name="l497" href="#l497">497 </a> <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>; <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++) { @@ -560,10 +560,10 @@ <a class="c2html-lineno" name="l507" href="#l507">507 </a> <a class="c2html-lineno" name="l508" href="#l508">508 </a> GameState simulation = gamestate_copy_sim(gamestate); <a class="c2html-lineno" name="l509" href="#l509">509 </a> Move simmove = *move; -<a class="c2html-lineno" name="l510" href="#l510">510 </a> apply_move(&simulation, &simmove); -<a class="c2html-lineno" name="l511" href="#l511">511 </a> _Bool covered = is_covered(&simulation, +<a class="c2html-lineno" name="l510" href="#l510">510 </a> apply_move(&simulation, &simmove); +<a class="c2html-lineno" name="l511" href="#l511">511 </a> _Bool covered = is_covered(&simulation, <a class="c2html-lineno" name="l512" href="#l512">512 </a> kingrow, kingfile, opponent_color(color)); -<a class="c2html-lineno" name="l513" href="#l513">513 </a> gamestate_cleanup(&simulation); +<a class="c2html-lineno" name="l513" href="#l513">513 </a> gamestate_cleanup(&simulation); <a class="c2html-lineno" name="l514" href="#l514">514 </a> <a class="c2html-lineno" name="l515" href="#l515">515 </a> <span class="c2html-keyword">return</span> covered; <a class="c2html-lineno" name="l516" href="#l516">516 </a>} @@ -577,7 +577,7 @@ <a class="c2html-lineno" name="l524" href="#l524">524 </a> <a class="c2html-lineno" name="l525" href="#l525">525 </a> Move candidates[<span class="c2html-macroconst">16</span>]; <a class="c2html-lineno" name="l526" href="#l526">526 </a> <span class="c2html-type">uint8_t</span> candidatecount; -<a class="c2html-lineno" name="l527" href="#l527">527 </a> <span class="c2html-keyword">if</span> (get_threats(gamestate, row, file, color, candidates, &candidatecount)) { +<a class="c2html-lineno" name="l527" href="#l527">527 </a> <span class="c2html-keyword">if</span> (get_threats(gamestate, row, file, color, candidates, &candidatecount)) { <a class="c2html-lineno" name="l528" href="#l528">528 </a> <a class="c2html-lineno" name="l529" href="#l529">529 </a> _Bool result = <span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l530" href="#l530">530 </a> <span class="c2html-type">uint8_t</span> kingfile = <span class="c2html-macroconst">0</span>, kingrow = <span class="c2html-macroconst">0</span>; @@ -593,11 +593,11 @@ <a class="c2html-lineno" name="l540" href="#l540">540 </a> <span class="c2html-keyword">for</span> (<span class="c2html-type">uint8_t</span> i = <span class="c2html-macroconst">0</span> ; i < candidatecount ; i++) { <a class="c2html-lineno" name="l541" href="#l541">541 </a> GameState simulation = gamestate_copy_sim(gamestate); <a class="c2html-lineno" name="l542" href="#l542">542 </a> Move simmove = candidates[i]; -<a class="c2html-lineno" name="l543" href="#l543">543 </a> apply_move(&simulation, &simmove); -<a class="c2html-lineno" name="l544" href="#l544">544 </a> <span class="c2html-keyword">if</span> (!is_covered(&simulation, kingrow, kingfile, +<a class="c2html-lineno" name="l543" href="#l543">543 </a> apply_move(&simulation, &simmove); +<a class="c2html-lineno" name="l544" href="#l544">544 </a> <span class="c2html-keyword">if</span> (!is_covered(&simulation, kingrow, kingfile, <a class="c2html-lineno" name="l545" href="#l545">545 </a> opponent_color(color))) { <a class="c2html-lineno" name="l546" href="#l546">546 </a> result = <span class="c2html-macroconst">1</span>; -<a class="c2html-lineno" name="l547" href="#l547">547 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { +<a class="c2html-lineno" name="l547" href="#l547">547 </a> <span class="c2html-keyword">if</span> (threats && threatcount) { <a class="c2html-lineno" name="l548" href="#l548">548 </a> threats[(*threatcount)++] = candidates[i]; <a class="c2html-lineno" name="l549" href="#l549">549 </a> } <a class="c2html-lineno" name="l550" href="#l550">550 </a> } @@ -611,23 +611,23 @@ <a class="c2html-lineno" name="l558" href="#l558">558 </a> <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) { <a class="c2html-lineno" name="l560" href="#l560">560 </a> -<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>; +<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>; <a class="c2html-lineno" name="l562" href="#l562">562 </a> _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:<span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l563" href="#l563">563 </a> <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>; <a class="c2html-lineno" name="l565" href="#l565">565 </a> <span class="c2html-type">uint8_t</span> threatcount; <a class="c2html-lineno" name="l566" href="#l566">566 </a> <a class="c2html-lineno" name="l567" href="#l567">567 </a> <span class="c2html-keyword">if</span> (get_threats(gamestate, move->torow, move->tofile, color, -<a class="c2html-lineno" name="l568" href="#l568">568 </a> threats, &threatcount)) { +<a class="c2html-lineno" name="l568" href="#l568">568 </a> threats, &threatcount)) { <a class="c2html-lineno" name="l569" href="#l569">569 </a> <a class="c2html-lineno" name="l570" href="#l570">570 </a> <span class="c2html-keyword">int</span> reason = <span class="c2html-macroconst">INVALID_POSITION</span>; <a class="c2html-lineno" name="l571" href="#l571">571 </a> <a class="c2html-lineno" name="l572" href="#l572">572 </a> <span class="c2html-comment">// find threats for the specified position</span> <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++) { -<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>)) -<a class="c2html-lineno" name="l575" href="#l575">575 </a> == move->piece && +<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>)) +<a class="c2html-lineno" name="l575" href="#l575">575 </a> == move->piece && <a class="c2html-lineno" name="l576" href="#l576">576 </a> (move->fromrow == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || -<a class="c2html-lineno" name="l577" href="#l577">577 </a> move->fromrow == threats[i].fromrow) && +<a class="c2html-lineno" name="l577" href="#l577">577 </a> move->fromrow == threats[i].fromrow) && <a class="c2html-lineno" name="l578" href="#l578">578 </a> (move->fromfile == <span class="c2html-macroconst">POS_UNSPECIFIED</span> || <a class="c2html-lineno" name="l579" href="#l579">579 </a> move->fromfile == threats[i].fromfile)) { <a class="c2html-lineno" name="l580" href="#l580">580 </a> @@ -635,10 +635,10 @@ <a class="c2html-lineno" name="l582" href="#l582">582 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">AMBIGUOUS_MOVE</span>; <a class="c2html-lineno" name="l583" href="#l583">583 </a> } <span class="c2html-keyword">else</span> { <a class="c2html-lineno" name="l584" href="#l584">584 </a> <span class="c2html-comment">// found threat is no real threat</span> -<a class="c2html-lineno" name="l585" href="#l585">585 </a> <span class="c2html-keyword">if</span> (is_pinned(gamestate, &(threats[i]))) { +<a class="c2html-lineno" name="l585" href="#l585">585 </a> <span class="c2html-keyword">if</span> (is_pinned(gamestate, &(threats[i]))) { <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>; <a class="c2html-lineno" name="l587" href="#l587">587 </a> } <span class="c2html-keyword">else</span> { -<a class="c2html-lineno" name="l588" href="#l588">588 </a> threat = &(threats[i]); +<a class="c2html-lineno" name="l588" href="#l588">588 </a> threat = &(threats[i]); <a class="c2html-lineno" name="l589" href="#l589">589 </a> } <a class="c2html-lineno" name="l590" href="#l590">590 </a> } <a class="c2html-lineno" name="l591" href="#l591">591 </a> } @@ -676,7 +676,7 @@ <a class="c2html-lineno" name="l623" href="#l623">623 </a> } <a class="c2html-lineno" name="l624" href="#l624">624 </a> <a class="c2html-lineno" name="l625" href="#l625">625 </a> <span class="c2html-comment">/* evaluate promotion */</span> -<a class="c2html-lineno" name="l626" href="#l626">626 </a> <span class="c2html-keyword">if</span> (len > <span class="c2html-macroconst">3</span> && mstr[len-<span class="c2html-macroconst">2</span>] == <span class="c2html-string">'='</span>) { +<a class="c2html-lineno" name="l626" href="#l626">626 </a> <span class="c2html-keyword">if</span> (len > <span class="c2html-macroconst">3</span> && mstr[len-<span class="c2html-macroconst">2</span>] == <span class="c2html-string">'='</span>) { <a class="c2html-lineno" name="l627" href="#l627">627 </a> move->promotion = getpiece(mstr[len-<span class="c2html-macroconst">1</span>]); <a class="c2html-lineno" name="l628" href="#l628">628 </a> <span class="c2html-keyword">if</span> (!move->promotion) { <a class="c2html-lineno" name="l629" href="#l629">629 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">INVALID_MOVE_SYNTAX</span>; @@ -770,8 +770,8 @@ <a class="c2html-lineno" name="l717" href="#l717">717 </a> <a class="c2html-lineno" name="l718" href="#l718">718 </a> <span class="c2html-keyword">if</span> (move->piece) { <a class="c2html-lineno" name="l719" href="#l719">719 </a> <span class="c2html-keyword">if</span> (move->piece == <span class="c2html-macroconst">PAWN</span> -<a class="c2html-lineno" name="l720" href="#l720">720 </a> && move->torow == (color==<span class="c2html-macroconst">WHITE</span>?<span class="c2html-macroconst">7</span>:<span class="c2html-macroconst">0</span>) -<a class="c2html-lineno" name="l721" href="#l721">721 </a> && !move->promotion) { +<a class="c2html-lineno" name="l720" href="#l720">720 </a> && move->torow == (color==<span class="c2html-macroconst">WHITE</span>?<span class="c2html-macroconst">7</span>:<span class="c2html-macroconst">0</span>) +<a class="c2html-lineno" name="l721" href="#l721">721 </a> && !move->promotion) { <a class="c2html-lineno" name="l722" href="#l722">722 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">NEED_PROMOTION</span>; <a class="c2html-lineno" name="l723" href="#l723">723 </a> } <a class="c2html-lineno" name="l724" href="#l724">724 </a> @@ -792,7 +792,7 @@ <a class="c2html-lineno" name="l739" href="#l739">739 </a> <a class="c2html-lineno" name="l740" href="#l740">740 </a> Move threats[<span class="c2html-macroconst">16</span>]; <a class="c2html-lineno" name="l741" href="#l741">741 </a> <span class="c2html-type">uint8_t</span> threatcount; -<a class="c2html-lineno" name="l742" href="#l742">742 </a> <span class="c2html-keyword">if</span> (get_real_threats(gamestate, row, file, color, threats, &threatcount)) { +<a class="c2html-lineno" name="l742" href="#l742">742 </a> <span class="c2html-keyword">if</span> (get_real_threats(gamestate, row, file, color, threats, &threatcount)) { <a class="c2html-lineno" name="l743" href="#l743">743 </a> <span class="c2html-keyword">for</span> (<span class="c2html-keyword">int</span> i = <span class="c2html-macroconst">0</span> ; i < threatcount ; i++) { <a class="c2html-lineno" name="l744" href="#l744">744 </a> <span class="c2html-keyword">if</span> (threats[i].piece != (color|<span class="c2html-macroconst">KING</span>)) { <a class="c2html-lineno" name="l745" href="#l745">745 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">1</span>; @@ -820,7 +820,7 @@ <a class="c2html-lineno" name="l767" href="#l767">767 </a> <span class="c2html-keyword">while</span> (movelist) { <a class="c2html-lineno" name="l768" href="#l768">768 </a> time += gameinfo->addtime; <a class="c2html-lineno" name="l769" href="#l769">769 </a> -<a class="c2html-lineno" name="l770" href="#l770">770 </a> <span class="c2html-keyword">struct</span> movetimeval *movetime = &(movelist->move.movetime); +<a class="c2html-lineno" name="l770" href="#l770">770 </a> <span class="c2html-keyword">struct</span> movetimeval *movetime = &(movelist->move.movetime); <a class="c2html-lineno" name="l771" href="#l771">771 </a> <span class="c2html-keyword">if</span> (movetime->tv_sec >= time) { <a class="c2html-lineno" name="l772" href="#l772">772 </a> <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>; <a class="c2html-lineno" name="l773" href="#l773">773 </a> } @@ -833,10 +833,10 @@ <a class="c2html-lineno" name="l780" href="#l780">780 </a> <a class="c2html-lineno" name="l781" href="#l781">781 </a> <span class="c2html-type">time_t</span> sec; <a class="c2html-lineno" name="l782" href="#l782">782 </a> movelist = gamestate->lastmove; -<a class="c2html-lineno" name="l783" href="#l783">783 </a> <span class="c2html-keyword">if</span> ((movelist->move.piece & <span class="c2html-macroconst">COLOR_MASK</span>) != color) { -<a class="c2html-lineno" name="l784" href="#l784">784 </a> <span class="c2html-keyword">struct</span> movetimeval *lastmovetstamp = &(movelist->move.timestamp); +<a class="c2html-lineno" name="l783" href="#l783">783 </a> <span class="c2html-keyword">if</span> ((movelist->move.piece & <span class="c2html-macroconst">COLOR_MASK</span>) != color) { +<a class="c2html-lineno" name="l784" href="#l784">784 </a> <span class="c2html-keyword">struct</span> movetimeval *lastmovetstamp = &(movelist->move.timestamp); <a class="c2html-lineno" name="l785" href="#l785">785 </a> <span class="c2html-keyword">struct</span> timeval currenttstamp; -<a class="c2html-lineno" name="l786" href="#l786">786 </a> gettimeofday(¤ttstamp, <span class="c2html-macroconst">NULL</span>); +<a class="c2html-lineno" name="l786" href="#l786">786 </a> gettimeofday(&currenttstamp, <span class="c2html-macroconst">NULL</span>); <a class="c2html-lineno" name="l787" href="#l787">787 </a> micros += currenttstamp.tv_usec - lastmovetstamp->tv_usec; <a class="c2html-lineno" name="l788" href="#l788">788 </a> sec = currenttstamp.tv_sec - lastmovetstamp->tv_sec; <a class="c2html-lineno" name="l789" href="#l789">789 </a> <span class="c2html-keyword">if</span> (sec >= time) {