ZealOS/docs/Demo/Games/Chess.CC.html
2021-12-04 05:03:02 -05:00

1259 lines
125 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.06">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>
<a name="l2"></a>
<a name="l3"></a></span><span class=cFA>
<a name="l4"></a>wpawn/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a>
<a name="l7"></a></span><span class=cFA>
<a name="l8"></a>wcastle/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l9"></a>
<a name="l10"></a>
<a name="l11"></a>
<a name="l12"></a></span><span class=cFA>
<a name="l13"></a>wknight/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l14"></a>
<a name="l15"></a>
<a name="l16"></a>
<a name="l17"></a>
<a name="l18"></a></span><span class=cFA>
<a name="l19"></a>wbishop/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l20"></a>
<a name="l21"></a>
<a name="l22"></a>
<a name="l23"></a>
<a name="l24"></a></span><span class=cFA>
<a name="l25"></a>wqueen/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l26"></a>
<a name="l27"></a>
<a name="l28"></a>
<a name="l29"></a>
<a name="l30"></a></span><span class=cFA>
<a name="l31"></a>wking/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l32"></a>
<a name="l33"></a>
<a name="l34"></a>
<a name="l35"></a></span><span class=cFA>
<a name="l36"></a>bpawn/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l37"></a>
<a name="l38"></a>
<a name="l39"></a></span><span class=cFA>
<a name="l40"></a>bcastle/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l41"></a>
<a name="l42"></a>
<a name="l43"></a>
<a name="l44"></a></span><span class=cFA>
<a name="l45"></a>bknight/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l46"></a>
<a name="l47"></a>
<a name="l48"></a>
<a name="l49"></a>
<a name="l50"></a></span><span class=cFA>
<a name="l51"></a>bbishop/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l52"></a>
<a name="l53"></a>
<a name="l54"></a>
<a name="l55"></a>
<a name="l56"></a></span><span class=cFA>
<a name="l57"></a>bqueen/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l58"></a>
<a name="l59"></a>
<a name="l60"></a>
<a name="l61"></a>
<a name="l62"></a>
<a name="l63"></a></span><span class=cFA>
<a name="l64"></a>bking/* Graphics Not Rendered in HTML */</span><span class=cF0>
<a name="l65"></a>
<a name="l66"></a></span><span class=cF2>//These are weights for scoring positions.</span><span class=cF0>
<a name="l67"></a>#</span><span class=cF1>define</span><span class=cF0> SHIFT_PIECE_SCORE </span><span class=cFE>4</span><span class=cF0>
<a name="l68"></a>#</span><span class=cF1>define</span><span class=cF0> SHIFT_POSSIBLE_MOVES </span><span class=cFE>0</span><span class=cF0>
<a name="l69"></a>
<a name="l70"></a>#</span><span class=cF1>define</span><span class=cF0> P_PAWN </span><span class=cFE>0</span><span class=cF0>
<a name="l71"></a>#</span><span class=cF1>define</span><span class=cF0> P_ROOK </span><span class=cFE>1</span><span class=cF0>
<a name="l72"></a>#</span><span class=cF1>define</span><span class=cF0> P_KNIGHT </span><span class=cFE>2</span><span class=cF0>
<a name="l73"></a>#</span><span class=cF1>define</span><span class=cF0> P_BISHOP </span><span class=cFE>3</span><span class=cF0>
<a name="l74"></a>#</span><span class=cF1>define</span><span class=cF0> P_QUEEN </span><span class=cFE>4</span><span class=cF0>
<a name="l75"></a>#</span><span class=cF1>define</span><span class=cF0> P_KING </span><span class=cFE>5</span><span class=cF0>
<a name="l76"></a>
<a name="l77"></a></span><span class=cF1>U8</span><span class=cF0> *imgs[</span><span class=cFE>12</span><span class=cF0>] = {</span><span class=cFA>&lt;1&gt;</span><span class=cF0>, </span><span class=cFA>&lt;7&gt;</span><span class=cF0>, </span><span class=cFA>&lt;2&gt;</span><span class=cF0>, </span><span class=cFA>&lt;8&gt;</span><span class=cF0>, </span><span class=cFA>&lt;3&gt;</span><span class=cF0>, </span><span class=cFA>&lt;9&gt;</span><span class=cF0>, </span><span class=cFA>&lt;4&gt;</span><span class=cF0>, </span><span class=cFA>&lt;10&gt;</span><span class=cF0>, </span><span class=cFA>&lt;5&gt;</span><span class=cF0>, </span><span class=cFA>&lt;11&gt;</span><span class=cF0>, </span><span class=cFA>&lt;6&gt;</span><span class=cF0>, </span><span class=cFA>&lt;12&gt;</span><span class=cF0>};
<a name="l78"></a>
<a name="l79"></a></span><span class=cF9>I64</span><span class=cF0> piece_scores[</span><span class=cFE>6</span><span class=cF0>] = {
<a name="l80"></a>
<a name="l81"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE,
<a name="l82"></a> </span><span class=cFE>5</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE,
<a name="l83"></a> </span><span class=cFE>3</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE,
<a name="l84"></a> </span><span class=cFE>3</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE,
<a name="l85"></a> </span><span class=cFE>9</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE,
<a name="l86"></a> </span><span class=cFE>100</span><span class=cF0> &lt;&lt; SHIFT_PIECE_SCORE
<a name="l87"></a>};
<a name="l88"></a>
<a name="l89"></a></span><span class=cF1>U8</span><span class=cF0> piece_letters[] = </span><span class=cF6>&quot;PRNBQK&quot;</span><span class=cF0>;
<a name="l90"></a>
<a name="l91"></a></span><span class=cF1>class</span><span class=cF0> </span><span class=cF5>Move</span><span class=cF0>
<a name="l92"></a>{
<a name="l93"></a> </span><span class=cF1>I8</span><span class=cF0> piece, x, y, pad;
<a name="l94"></a> </span><span class=cF9>I32</span><span class=cF0> score;
<a name="l95"></a>};
<a name="l96"></a>
<a name="l97"></a></span><span class=cF1>class</span><span class=cF0> PieceState
<a name="l98"></a>{
<a name="l99"></a> </span><span class=cF1>I8</span><span class=cF0> player, type, x, y;
<a name="l100"></a>};
<a name="l101"></a>
<a name="l102"></a></span><span class=cF1>class</span><span class=cF0> GameState
<a name="l103"></a>{
<a name="l104"></a> GameState *next, *last, *parent;
<a name="l105"></a> PieceState pieces[</span><span class=cFE>32</span><span class=cF0>];
<a name="l106"></a> </span><span class=cF9>I64</span><span class=cF0> cur_player,
<a name="l107"></a> mv_num,
<a name="l108"></a> moved_mask,
<a name="l109"></a> raw_score; </span><span class=cF2>//Positive favors player#0</span><span class=cF0>
<a name="l110"></a> </span><span class=cF1>Bool</span><span class=cF0> is_human[</span><span class=cFE>2</span><span class=cF0>];
<a name="l111"></a> </span><span class=cF5>Move</span><span class=cF0> potential_en_passant_victim;
<a name="l112"></a>};
<a name="l113"></a>
<a name="l114"></a>GameState setup_state = {
<a name="l115"></a>
<a name="l116"></a> </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF3>NULL</span><span class=cF0>,
<a name="l117"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l118"></a> {</span><span class=cFE>0</span><span class=cF0>, P_KING, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0>},
<a name="l119"></a> {</span><span class=cFE>0</span><span class=cF0>, P_QUEEN, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF0>},
<a name="l120"></a> {</span><span class=cFE>0</span><span class=cF0>, P_BISHOP, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>},
<a name="l121"></a> {</span><span class=cFE>0</span><span class=cF0>, P_BISHOP, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>},
<a name="l122"></a> {</span><span class=cFE>0</span><span class=cF0>, P_KNIGHT, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l123"></a> {</span><span class=cFE>0</span><span class=cF0>, P_KNIGHT, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF0>},
<a name="l124"></a> {</span><span class=cFE>0</span><span class=cF0>, P_ROOK, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>},
<a name="l125"></a> {</span><span class=cFE>0</span><span class=cF0>, P_ROOK, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>},
<a name="l126"></a>
<a name="l127"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>},
<a name="l128"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l129"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>},
<a name="l130"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF0>},
<a name="l131"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0>},
<a name="l132"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>},
<a name="l133"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF0>},
<a name="l134"></a> {</span><span class=cFE>0</span><span class=cF0>, P_PAWN, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>},
<a name="l135"></a>
<a name="l136"></a> {</span><span class=cFE>1</span><span class=cF0>, P_KING, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0>},
<a name="l137"></a> {</span><span class=cFE>1</span><span class=cF0>, P_QUEEN, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF0>},
<a name="l138"></a> {</span><span class=cFE>1</span><span class=cF0>, P_BISHOP, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>},
<a name="l139"></a> {</span><span class=cFE>1</span><span class=cF0>, P_BISHOP, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>},
<a name="l140"></a> {</span><span class=cFE>1</span><span class=cF0>, P_KNIGHT, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l141"></a> {</span><span class=cFE>1</span><span class=cF0>, P_KNIGHT, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF0>},
<a name="l142"></a> {</span><span class=cFE>1</span><span class=cF0>, P_ROOK, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>},
<a name="l143"></a> {</span><span class=cFE>1</span><span class=cF0>, P_ROOK, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>},
<a name="l144"></a>
<a name="l145"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>},
<a name="l146"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l147"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>},
<a name="l148"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF0>},
<a name="l149"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0>},
<a name="l150"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF0>},
<a name="l151"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF0>},
<a name="l152"></a> {</span><span class=cFE>1</span><span class=cF0>, P_PAWN, </span><span class=cFE>6</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>},
<a name="l153"></a> </span><span class=cF7>}</span><span class=cF0>,
<a name="l154"></a> </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>,
<a name="l155"></a> </span><span class=cF7>{</span><span class=cF3>TRUE</span><span class=cF0>, </span><span class=cF3>FALSE</span><span class=cF7>}</span><span class=cF0>,
<a name="l156"></a> </span><span class=cF7>{</span><span class=cFE>0</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF7>}</span><span class=cF0>};
<a name="l157"></a>
<a name="l158"></a>GameState cur_state;
<a name="l159"></a></span><span class=cF9>CDoc</span><span class=cF0> *chess_doc;
<a name="l160"></a>
<a name="l161"></a></span><span class=cF1>U0</span><span class=cF0> GameSnapShot()
<a name="l162"></a>{
<a name="l163"></a> GameState *tmpg = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>GameState</span><span class=cF7>)</span><span class=cF0>);
<a name="l164"></a>
<a name="l165"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(tmpg, &amp;cur_state, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>GameState</span><span class=cF7>)</span><span class=cF0>);
<a name="l166"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpg, cur_state.last);
<a name="l167"></a>}
<a name="l168"></a>
<a name="l169"></a></span><span class=cF9>I64</span><span class=cF0> PieceFind(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF9>I64</span><span class=cF0> player)
<a name="l170"></a>{
<a name="l171"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l172"></a>
<a name="l173"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l174"></a> </span><span class=cF1>if</span><span class=cF0> (cur_state.pieces[i].player == player &amp;&amp; cur_state.pieces[i].x == x &amp;&amp; cur_state.pieces[i].y == y)
<a name="l175"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l178"></a>}
<a name="l179"></a>
<a name="l180"></a>
<a name="l181"></a>#</span><span class=cF1>define</span><span class=cF0> BD_BORDER </span><span class=cFE>4</span><span class=cF0>
<a name="l182"></a>#</span><span class=cF1>define</span><span class=cF0> BD_SIDE (BD_BORDER + </span><span class=cFE>8</span><span class=cF0> + BD_BORDER)
<a name="l183"></a>#</span><span class=cF1>define</span><span class=cF0> T_BLKED -</span><span class=cFE>1</span><span class=cF0>
<a name="l184"></a>#</span><span class=cF1>define</span><span class=cF0> T_PLAYER0 </span><span class=cFE>0</span><span class=cF0>
<a name="l185"></a>#</span><span class=cF1>define</span><span class=cF0> T_PLAYER1 </span><span class=cFE>1</span><span class=cF0>
<a name="l186"></a>#</span><span class=cF1>define</span><span class=cF0> T_CLR </span><span class=cFE>2</span><span class=cF0>
<a name="l187"></a>
<a name="l188"></a></span><span class=cF1>U0</span><span class=cF0> BrdFill(</span><span class=cF1>I8</span><span class=cF0> *brd, PieceState *pieces)
<a name="l189"></a>{
<a name="l190"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l191"></a>
<a name="l192"></a> </span><span class=cF5>MemSet</span><span class=cF0>(brd, T_BLKED, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>I8</span><span class=cF7>)</span><span class=cF0> * BD_SIDE * BD_SIDE);
<a name="l193"></a>
<a name="l194"></a> </span><span class=cF1>for</span><span class=cF0> (i = BD_BORDER; i &lt; </span><span class=cFE>8</span><span class=cF0> + BD_BORDER; i++)
<a name="l195"></a> brd[BD_SIDE * i + BD_BORDER](</span><span class=cF9>I64</span><span class=cF0>) = </span><span class=cFE>0x0202020202020202</span><span class=cF0>;
<a name="l196"></a>#</span><span class=cF1>assert</span><span class=cF0> T_CLR == </span><span class=cFE>2</span><span class=cF0>
<a name="l197"></a>
<a name="l198"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l199"></a> </span><span class=cF1>if</span><span class=cF0> (!pieces[i].player)
<a name="l200"></a> brd[BD_SIDE * (BD_BORDER + pieces[i].y) + BD_BORDER + pieces[i].x] = T_PLAYER0;
<a name="l201"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (pieces[i].player == </span><span class=cFE>1</span><span class=cF0>)
<a name="l202"></a> brd[BD_SIDE * (BD_BORDER + pieces[i].y) + BD_BORDER + pieces[i].x] = T_PLAYER1;
<a name="l203"></a>}
<a name="l204"></a>
<a name="l205"></a></span><span class=cF1>I8</span><span class=cF0> BrdPeek(</span><span class=cF1>I8</span><span class=cF0> *brd, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l206"></a>{
<a name="l207"></a> </span><span class=cF1>return</span><span class=cF0> brd[(y + BD_BORDER) * BD_SIDE + BD_BORDER + x];
<a name="l208"></a>}
<a name="l209"></a>
<a name="l210"></a>
<a name="l211"></a></span><span class=cF9>I64</span><span class=cF0> knight_x_offsets[</span><span class=cFE>8</span><span class=cF0>] = {-</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>, -</span><span class=cFE>2</span><span class=cF0>, -</span><span class=cFE>2</span><span class=cF0>},
<a name="l212"></a> knight_y_offsets[</span><span class=cFE>8</span><span class=cF0>] = {-</span><span class=cFE>2</span><span class=cF0>, -</span><span class=cFE>2</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l213"></a> bishop_x_offsets3[</span><span class=cFE>4</span><span class=cF0>] = {-</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>},
<a name="l214"></a> bishop_y_offsets3[</span><span class=cFE>4</span><span class=cF0>] = {-</span><span class=cFE>1</span><span class=cF0>, -</span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>};
<a name="l215"></a>
<a name="l216"></a></span><span class=cF9>I64</span><span class=cF0> PieceMoves(GameState *state, </span><span class=cF9>I64</span><span class=cF0> piece_num, </span><span class=cF5>Move</span><span class=cF0> *mvs)
<a name="l217"></a>{
<a name="l218"></a> PieceState *p = state-&gt;pieces, *cur_p = &amp;p[piece_num];
<a name="l219"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>, i, j, k, x, y, xx = cur_p-&gt;x, yy = cur_p-&gt;y;
<a name="l220"></a> </span><span class=cF1>I8</span><span class=cF0> brd[BD_SIDE * BD_SIDE * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF1>I8</span><span class=cF0>)];
<a name="l221"></a>
<a name="l222"></a> BrdFill(brd, p);
<a name="l223"></a> </span><span class=cF1>switch</span><span class=cF0> [state-&gt;pieces[piece_num].type]
<a name="l224"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l225"></a> </span><span class=cF1>case</span><span class=cF0> P_PAWN:
<a name="l226"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;cur_player)
<a name="l227"></a> {
<a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx + </span><span class=cFE>1</span><span class=cF0>, yy</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l229"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l230"></a> mvs[res].x = xx + </span><span class=cFE>1</span><span class=cF0>;
<a name="l231"></a> mvs[res].y = yy;
<a name="l232"></a> res++;
<a name="l233"></a> </span><span class=cF1>if</span><span class=cF0> (xx == </span><span class=cFE>1</span><span class=cF0> &amp;&amp; BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx + </span><span class=cFE>2</span><span class=cF0>, yy</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l234"></a> {
<a name="l235"></a> mvs[res].x = xx + </span><span class=cFE>2</span><span class=cF0>;
<a name="l236"></a> mvs[res].y = yy;
<a name="l237"></a> res++;
<a name="l238"></a> }
<a name="l239"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l240"></a> </span><span class=cF1>if</span><span class=cF0> (BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx + </span><span class=cFE>1</span><span class=cF0>, yy - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> == T_PLAYER1 ||
<a name="l241"></a> state-&gt;potential_en_passant_victim.x == xx &amp;&amp;
<a name="l242"></a> state-&gt;potential_en_passant_victim.y == yy - </span><span class=cFE>1</span><span class=cF0>)
<a name="l243"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l244"></a> mvs[res].x = xx + </span><span class=cFE>1</span><span class=cF0>;
<a name="l245"></a> mvs[res].y = yy - </span><span class=cFE>1</span><span class=cF0>;
<a name="l246"></a> res++;
<a name="l247"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l248"></a> </span><span class=cF1>if</span><span class=cF0> (BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx + </span><span class=cFE>1</span><span class=cF0>, yy + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> == T_PLAYER1 ||
<a name="l249"></a> state-&gt;potential_en_passant_victim.x == xx &amp;&amp;
<a name="l250"></a> state-&gt;potential_en_passant_victim.y == yy + </span><span class=cFE>1</span><span class=cF0>)
<a name="l251"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l252"></a> mvs[res].x = xx + </span><span class=cFE>1</span><span class=cF0>;
<a name="l253"></a> mvs[res].y = yy + </span><span class=cFE>1</span><span class=cF0>;
<a name="l254"></a> res++;
<a name="l255"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l256"></a> }
<a name="l257"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l258"></a> {
<a name="l259"></a> </span><span class=cF1>if</span><span class=cF0> (BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx - </span><span class=cFE>1</span><span class=cF0>, yy</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l260"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l261"></a> mvs[res].x = xx - </span><span class=cFE>1</span><span class=cF0>;
<a name="l262"></a> mvs[res].y = yy;
<a name="l263"></a> res++;
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (xx == </span><span class=cFE>6</span><span class=cF0> &amp;&amp; BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx - </span><span class=cFE>2</span><span class=cF0>, yy</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l265"></a> {
<a name="l266"></a> mvs[res].x = xx - </span><span class=cFE>2</span><span class=cF0>;
<a name="l267"></a> mvs[res].y = yy;
<a name="l268"></a> res++;
<a name="l269"></a> }
<a name="l270"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l271"></a> </span><span class=cF1>if</span><span class=cF0> (!BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, xx - </span><span class=cFE>1</span><span class=cF0>, yy - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> ||
<a name="l272"></a> state-&gt;potential_en_passant_victim.x == xx &amp;&amp;
<a name="l273"></a> state-&gt;potential_en_passant_victim.y == yy - </span><span class=cFE>1</span><span class=cF0>)
<a name="l274"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l275"></a> mvs[res].x = xx - </span><span class=cFE>1</span><span class=cF0>;
<a name="l276"></a> mvs[res].y = yy - </span><span class=cFE>1</span><span class=cF0>;
<a name="l277"></a> res++;
<a name="l278"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l279"></a> </span><span class=cF1>if</span><span class=cF0> (!BrdPeek</span><span class=cF7>(</span><span class=cF0>brd,xx-</span><span class=cFE>1</span><span class=cF0>,yy+</span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> ||
<a name="l280"></a> state-&gt;potential_en_passant_victim.x==xx &amp;&amp;
<a name="l281"></a> state-&gt;potential_en_passant_victim.y==yy+</span><span class=cFE>1</span><span class=cF0>)
<a name="l282"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l283"></a> mvs[res].x = xx - </span><span class=cFE>1</span><span class=cF0>;
<a name="l284"></a> mvs[res].y = yy + </span><span class=cFE>1</span><span class=cF0>;
<a name="l285"></a> res++;
<a name="l286"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l287"></a> }
<a name="l288"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l289"></a>
<a name="l290"></a> </span><span class=cF1>case</span><span class=cF0> P_ROOK:
<a name="l291"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>4</span><span class=cF0>; j++)
<a name="l292"></a> {
<a name="l293"></a> x = xx;
<a name="l294"></a> y = yy;
<a name="l295"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt; </span><span class=cFE>8</span><span class=cF0>; i++)
<a name="l296"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l297"></a> x += </span><span class=cFB>gr_x_offsets2</span><span class=cF0>[j];
<a name="l298"></a> y += </span><span class=cFB>gr_y_offsets2</span><span class=cF0>[j];
<a name="l299"></a> k = BrdPeek(brd, x, y);
<a name="l300"></a> </span><span class=cF1>if</span><span class=cF0> (k == T_CLR || k == cur_p-&gt;player ^ </span><span class=cFE>1</span><span class=cF0>)
<a name="l301"></a> {
<a name="l302"></a> mvs[res].x = x;
<a name="l303"></a> mvs[res].y = y;
<a name="l304"></a> res++;
<a name="l305"></a> </span><span class=cF1>if</span><span class=cF0> (k != T_CLR)
<a name="l306"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l307"></a> }
<a name="l308"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l309"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l310"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l311"></a> }
<a name="l312"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l313"></a>
<a name="l314"></a> </span><span class=cF1>case</span><span class=cF0> P_KNIGHT:
<a name="l315"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>8</span><span class=cF0>; j++)
<a name="l316"></a> {
<a name="l317"></a> x = xx + knight_x_offsets[j];
<a name="l318"></a> y = yy + knight_y_offsets[j];
<a name="l319"></a> k = BrdPeek(brd, x, y);
<a name="l320"></a> </span><span class=cF1>if</span><span class=cF0> (k == T_CLR || k == cur_p-&gt;player ^ </span><span class=cFE>1</span><span class=cF0>)
<a name="l321"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l322"></a> mvs[res].x = x;
<a name="l323"></a> mvs[res].y = y;
<a name="l324"></a> res++;
<a name="l325"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l326"></a> }
<a name="l327"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l328"></a>
<a name="l329"></a> </span><span class=cF1>case</span><span class=cF0> P_BISHOP:
<a name="l330"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>4</span><span class=cF0>; j++)
<a name="l331"></a> {
<a name="l332"></a> x = xx;
<a name="l333"></a> y = yy;
<a name="l334"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt; </span><span class=cFE>8</span><span class=cF0>; i++)
<a name="l335"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l336"></a> x += bishop_x_offsets3[j];
<a name="l337"></a> y += bishop_y_offsets3[j];
<a name="l338"></a> k = BrdPeek(brd, x, y);
<a name="l339"></a> </span><span class=cF1>if</span><span class=cF0> (k == T_CLR || k == cur_p-&gt;player ^ </span><span class=cFE>1</span><span class=cF0>)
<a name="l340"></a> {
<a name="l341"></a> mvs[res].x = x;
<a name="l342"></a> mvs[res].y = y;
<a name="l343"></a> res++;
<a name="l344"></a> </span><span class=cF1>if</span><span class=cF0> (k != T_CLR)
<a name="l345"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l346"></a> }
<a name="l347"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l348"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l349"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l350"></a> }
<a name="l351"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l352"></a>
<a name="l353"></a> </span><span class=cF1>case</span><span class=cF0> P_QUEEN:
<a name="l354"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>8</span><span class=cF0>; j++)
<a name="l355"></a> {
<a name="l356"></a> x = xx;
<a name="l357"></a> y = yy;
<a name="l358"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt; </span><span class=cFE>8</span><span class=cF0>; i++)
<a name="l359"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l360"></a> x += </span><span class=cFB>gr_x_offsets</span><span class=cF0>[j];
<a name="l361"></a> y += </span><span class=cFB>gr_y_offsets</span><span class=cF0>[j];
<a name="l362"></a> k = BrdPeek(brd, x, y);
<a name="l363"></a> </span><span class=cF1>if</span><span class=cF0> (k == T_CLR || k == cur_p-&gt;player ^ </span><span class=cFE>1</span><span class=cF0>)
<a name="l364"></a> {
<a name="l365"></a> mvs[res].x = x;
<a name="l366"></a> mvs[res].y = y;
<a name="l367"></a> res++;
<a name="l368"></a> </span><span class=cF1>if</span><span class=cF0> (k != T_CLR)
<a name="l369"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l370"></a> }
<a name="l371"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l372"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l373"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l374"></a> }
<a name="l375"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l376"></a>
<a name="l377"></a> </span><span class=cF1>case</span><span class=cF0> P_KING:
<a name="l378"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>8</span><span class=cF0>; j++)
<a name="l379"></a> {
<a name="l380"></a> x = xx + </span><span class=cFB>gr_x_offsets</span><span class=cF0>[j];
<a name="l381"></a> y = yy + </span><span class=cFB>gr_y_offsets</span><span class=cF0>[j];
<a name="l382"></a> k = BrdPeek(brd, x, y);
<a name="l383"></a> </span><span class=cF1>if</span><span class=cF0> (k == T_CLR || k == cur_p-&gt;player ^ </span><span class=cFE>1</span><span class=cF0>)
<a name="l384"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l385"></a> mvs[res].x = x;
<a name="l386"></a> mvs[res].y = y;
<a name="l387"></a> res++;
<a name="l388"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l389"></a> }
<a name="l390"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;state-&gt;moved_mask, piece_num</span><span class=cF7>)</span><span class=cF0>)
<a name="l391"></a> {
<a name="l392"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;cur_player)
<a name="l393"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l394"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[</span><span class=cFE>0</span><span class=cF0>].player &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp;
<a name="l395"></a> !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;state-&gt;moved_mask, </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l396"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l397"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l398"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l399"></a> {
<a name="l400"></a> mvs[res].x = </span><span class=cFE>0</span><span class=cF0>;
<a name="l401"></a> mvs[res].y = </span><span class=cFE>2</span><span class=cF0>;
<a name="l402"></a> res++;
<a name="l403"></a> }
<a name="l404"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[</span><span class=cFE>7</span><span class=cF0>].player &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp;
<a name="l405"></a> !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;state-&gt;moved_mask, </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l406"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l407"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l408"></a> {
<a name="l409"></a> mvs[res].x = </span><span class=cFE>0</span><span class=cF0>;
<a name="l410"></a> mvs[res].y = </span><span class=cFE>6</span><span class=cF0>;
<a name="l411"></a> res++;
<a name="l412"></a> }
<a name="l413"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l414"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l415"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l416"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[</span><span class=cFE>24</span><span class=cF0>].player &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp;
<a name="l417"></a> !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;state-&gt;moved_mask, </span><span class=cFE>24</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l418"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l419"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l420"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l421"></a> {
<a name="l422"></a> mvs[res].x = </span><span class=cFE>7</span><span class=cF0>;
<a name="l423"></a> mvs[res].y = </span><span class=cFE>2</span><span class=cF0>;
<a name="l424"></a> res++;
<a name="l425"></a> }
<a name="l426"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[</span><span class=cFE>31</span><span class=cF0>].player &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp;
<a name="l427"></a> !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;state-&gt;moved_mask, </span><span class=cFE>31</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l428"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>6</span><span class=cF7>)</span><span class=cF0> == T_CLR &amp;&amp;
<a name="l429"></a> BrdPeek</span><span class=cF7>(</span><span class=cF0>brd, </span><span class=cFE>7</span><span class=cF0>, </span><span class=cFE>5</span><span class=cF7>)</span><span class=cF0> == T_CLR)
<a name="l430"></a> {
<a name="l431"></a> mvs[res].x = </span><span class=cFE>7</span><span class=cF0>;
<a name="l432"></a> mvs[res].y = </span><span class=cFE>6</span><span class=cF0>;
<a name="l433"></a> res++;
<a name="l434"></a> }
<a name="l435"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l436"></a> }
<a name="l437"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l438"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l439"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; res; i++)
<a name="l440"></a> mvs[i].piece = piece_num;
<a name="l441"></a>
<a name="l442"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l443"></a>}
<a name="l444"></a>
<a name="l445"></a></span><span class=cF1>Bool</span><span class=cF0> SqrInChk(GameState *state, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l446"></a>{
<a name="l447"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, mv_cnt;
<a name="l448"></a>
<a name="l449"></a> </span><span class=cF5>Move</span><span class=cF0> mvs[</span><span class=cFE>32</span><span class=cF0>];
<a name="l450"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l451"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[i].player == state-&gt;cur_player)
<a name="l452"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l453"></a> mv_cnt = PieceMoves(state, i, mvs);
<a name="l454"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; mv_cnt; j++)
<a name="l455"></a> </span><span class=cF1>if</span><span class=cF0> (mvs[j].x == x &amp;&amp; mvs[j].y == y)
<a name="l456"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l457"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l458"></a>
<a name="l459"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l460"></a>}
<a name="l461"></a>
<a name="l462"></a></span><span class=cF9>I64</span><span class=cF0> PopUpPiece(</span><span class=cF9>I64</span><span class=cF0> player)
<a name="l463"></a>{
<a name="l464"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cF3>STR_LEN</span><span class=cF0>];
<a name="l465"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l466"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc;
<a name="l467"></a>
<a name="l468"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l469"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l470"></a> doc = </span><span class=cF5>DocNew</span><span class=cF0>;
<a name="l471"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;\n\n\n\n\n...&quot;</span><span class=cF0>);
<a name="l472"></a> </span><span class=cF1>for</span><span class=cF0> (i = P_ROOK; i &lt;= P_QUEEN; i++)
<a name="l473"></a> {
<a name="l474"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(buf, </span><span class=cF6>&quot;$SP+LE+X,\&quot;\&quot;,%d,%%d$....&quot;</span><span class=cF0>, i);
<a name="l475"></a> </span><span class=cF5>DocSprite</span><span class=cF0>(doc, imgs[</span><span class=cFE>2</span><span class=cF0> * i + player], buf);
<a name="l476"></a> }
<a name="l477"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc, </span><span class=cF6>&quot;\n\n\n&quot;</span><span class=cF0>);
<a name="l478"></a> i = </span><span class=cF5>PopUpMenu</span><span class=cF0>(doc);
<a name="l479"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l480"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l481"></a> </span><span class=cF1>while</span><span class=cF0> (i &lt; </span><span class=cFE>0</span><span class=cF0>);
<a name="l482"></a>
<a name="l483"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l484"></a>}
<a name="l485"></a>
<a name="l486"></a></span><span class=cF9>CDC</span><span class=cF0> *brd_dc;
<a name="l487"></a></span><span class=cF9>I64</span><span class=cF0> cx, cy, cx2, cy2, g, cursor_x, cursor_y, cur_mv_cnt, *s2w, *w2s;
<a name="l488"></a></span><span class=cF5>Move</span><span class=cF0> cur_mvs[</span><span class=cFE>32</span><span class=cF0>], last_mv;
<a name="l489"></a></span><span class=cF1>Bool</span><span class=cF0> ai_thinking, game_over;
<a name="l490"></a>
<a name="l491"></a></span><span class=cF1>extern</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> MoveCnt(GameState *state);
<a name="l492"></a>
<a name="l493"></a></span><span class=cF1>Bool</span><span class=cF0> MoveDo(GameState *state, </span><span class=cF9>I64</span><span class=cF0> piece_num, </span><span class=cF9>I64</span><span class=cF0> x2, </span><span class=cF9>I64</span><span class=cF0> y2, </span><span class=cF1>Bool</span><span class=cF0> final)
<a name="l494"></a>{ </span><span class=cF2>//returns TRUE if killed a piece.</span><span class=cF0>
<a name="l495"></a> PieceState *p = &amp;state-&gt;pieces[piece_num];
<a name="l496"></a> </span><span class=cF9>I64</span><span class=cF0> j, ty = -</span><span class=cFE>1</span><span class=cF0>, score_adjust = </span><span class=cFE>0</span><span class=cF0>, x1 = p-&gt;x, y1 = p-&gt;y;
<a name="l497"></a>
<a name="l498"></a> j = PieceFind(x2, y2, state-&gt;cur_player ^ </span><span class=cFE>1</span><span class=cF0>);
<a name="l499"></a> </span><span class=cF1>if</span><span class=cF0> (j &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l500"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l501"></a> state-&gt;pieces[j].player -= </span><span class=cFE>2</span><span class=cF0>; </span><span class=cF2>//dead</span><span class=cF0>
<a name="l502"></a> ty = state-&gt;pieces[j].type;
<a name="l503"></a> score_adjust = piece_scores[ty];
<a name="l504"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l505"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (p-&gt;type == P_PAWN &amp;&amp; </span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>y1 - y2</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>1</span><span class=cF0>)
<a name="l506"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//en passant?</span><span class=cF0>
<a name="l507"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;cur_player)
<a name="l508"></a> j = PieceFind(x2 - </span><span class=cFE>1</span><span class=cF0>, y2, </span><span class=cFE>1</span><span class=cF0>);
<a name="l509"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l510"></a> j = PieceFind(x2 + </span><span class=cFE>1</span><span class=cF0>, y2, </span><span class=cFE>0</span><span class=cF0>);
<a name="l511"></a> </span><span class=cF1>if</span><span class=cF0> (j &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l512"></a> {
<a name="l513"></a> state-&gt;pieces[j].player -= </span><span class=cFE>2</span><span class=cF0>; </span><span class=cF2>//dead</span><span class=cF0>
<a name="l514"></a> ty = state-&gt;pieces[j].type;
<a name="l515"></a> score_adjust = piece_scores[ty];
<a name="l516"></a> }
<a name="l517"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l518"></a> </span><span class=cF1>if</span><span class=cF0> (p-&gt;type == P_PAWN &amp;&amp; </span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>x1 - x2</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>2</span><span class=cF0>)
<a name="l519"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l520"></a> state-&gt;potential_en_passant_victim.x = x2;
<a name="l521"></a> state-&gt;potential_en_passant_victim.y = y2;
<a name="l522"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l523"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l524"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l525"></a> state-&gt;potential_en_passant_victim.x = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l526"></a> state-&gt;potential_en_passant_victim.y = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l527"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l528"></a> </span><span class=cF1>if</span><span class=cF0> (p-&gt;type == P_PAWN &amp;&amp; </span><span class=cF7>(</span><span class=cF0>!x2 || x2 == </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0>)
<a name="l529"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l530"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;is_human[state-&gt;cur_player] || !final)
<a name="l531"></a> p-&gt;type = P_QUEEN;
<a name="l532"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l533"></a> p-&gt;type = PopUpPiece(state-&gt;cur_player);
<a name="l534"></a> score_adjust += piece_scores[p-&gt;type] - piece_scores[P_PAWN];
<a name="l535"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l536"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (p-&gt;type == P_KING &amp;&amp; </span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>y1 - y2</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>2</span><span class=cF0>)
<a name="l537"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//castling?</span><span class=cF0>
<a name="l538"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;cur_player)
<a name="l539"></a> {
<a name="l540"></a> </span><span class=cF1>if</span><span class=cF0> (y2 - y1 &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l541"></a> state-&gt;pieces[</span><span class=cFE>6</span><span class=cF0>].y = y2 + </span><span class=cFE>1</span><span class=cF0>;
<a name="l542"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l543"></a> state-&gt;pieces[</span><span class=cFE>7</span><span class=cF0>].y = y2 - </span><span class=cFE>1</span><span class=cF0>;
<a name="l544"></a> }
<a name="l545"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l546"></a> {
<a name="l547"></a> </span><span class=cF1>if</span><span class=cF0> (y2 - y1 &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l548"></a> state-&gt;pieces[</span><span class=cFE>22</span><span class=cF0>].y = y2 + </span><span class=cFE>1</span><span class=cF0>;
<a name="l549"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l550"></a> state-&gt;pieces[</span><span class=cFE>23</span><span class=cF0>].y = y2 - </span><span class=cFE>1</span><span class=cF0>;
<a name="l551"></a> }
<a name="l552"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l553"></a> p-&gt;x = x2;
<a name="l554"></a> p-&gt;y = y2;
<a name="l555"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;state-&gt;moved_mask, piece_num);
<a name="l556"></a> </span><span class=cF1>if</span><span class=cF0> (!state-&gt;cur_player)
<a name="l557"></a> state-&gt;raw_score += score_adjust;
<a name="l558"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l559"></a> state-&gt;raw_score -= score_adjust;
<a name="l560"></a> state-&gt;cur_player ^= </span><span class=cFE>1</span><span class=cF0>;
<a name="l561"></a> state-&gt;mv_num++;
<a name="l562"></a> </span><span class=cF1>if</span><span class=cF0> (final)
<a name="l563"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l564"></a> last_mv.x = x2;
<a name="l565"></a> last_mv.y = y2;
<a name="l566"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;%02d)&quot;</span><span class=cF0>, state-&gt;mv_num);
<a name="l567"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;cur_player)
<a name="l568"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG,LTGRAY$&quot;</span><span class=cF0>);
<a name="l569"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l570"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG,BLACK&quot;</span><span class=cF0>);
<a name="l571"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;%c:%c%c-%c%c&quot;</span><span class=cF0>, piece_letters[p-&gt;type], y1 + </span><span class=cF6>'A'</span><span class=cF0>, x1 + </span><span class=cF6>'1'</span><span class=cF0>, y2 + </span><span class=cF6>'A'</span><span class=cF0>, x2 + </span><span class=cF6>'1'</span><span class=cF0>);
<a name="l572"></a> </span><span class=cF1>if</span><span class=cF0> (ty &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l573"></a> {
<a name="l574"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;cur_player)
<a name="l575"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG$*$FG,BLACK$&quot;</span><span class=cF0>);
<a name="l576"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l577"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG$*$FG,LTGRAY$&quot;</span><span class=cF0>);
<a name="l578"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;%c&quot;</span><span class=cF0>, piece_letters[ty]);
<a name="l579"></a> }
<a name="l580"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG$\n&quot;</span><span class=cF0>);
<a name="l581"></a> </span><span class=cF1>if</span><span class=cF0> (!MoveCnt</span><span class=cF7>(</span><span class=cF0>&amp;cur_state</span><span class=cF7>)</span><span class=cF0>)
<a name="l582"></a> {
<a name="l583"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;$FG,RED$Game Over$FG$\n&quot;</span><span class=cF0>);
<a name="l584"></a> game_over = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l585"></a> }
<a name="l586"></a> GameSnapShot;
<a name="l587"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l588"></a>
<a name="l589"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ToBool</span><span class=cF0>(score_adjust);
<a name="l590"></a>}
<a name="l591"></a>
<a name="l592"></a></span><span class=cF9>I64</span><span class=cF0> MoveFind(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF5>Move</span><span class=cF0> *mvs, </span><span class=cF9>I64</span><span class=cF0> mv_cnt)
<a name="l593"></a>{
<a name="l594"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l595"></a>
<a name="l596"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; mv_cnt; i++)
<a name="l597"></a> </span><span class=cF1>if</span><span class=cF0> (mvs[i].x == x &amp;&amp; mvs[i].y == y)
<a name="l598"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l599"></a>
<a name="l600"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l601"></a>}
<a name="l602"></a>
<a name="l603"></a></span><span class=cF1>Bool</span><span class=cF0> HumanMove(GameState *state, </span><span class=cF9>I64</span><span class=cF0> piece_num, </span><span class=cF5>Move</span><span class=cF0> *mvs, </span><span class=cF9>I64</span><span class=cF0> mv_cnt, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l604"></a>{
<a name="l605"></a> </span><span class=cF1>if</span><span class=cF0> (piece_num &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp; MoveFind</span><span class=cF7>(</span><span class=cF0>x, y, mvs, mv_cnt</span><span class=cF7>)</span><span class=cF0> &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l606"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l607"></a> MoveDo(state, piece_num, x, y, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l608"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l609"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l610"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l611"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l612"></a>}
<a name="l613"></a>
<a name="l614"></a></span><span class=cF9>I64</span><span class=cF0> ChkPieceMoves(GameState *state, </span><span class=cF9>I64</span><span class=cF0> piece_num, </span><span class=cF5>Move</span><span class=cF0> *src, </span><span class=cF9>I64</span><span class=cF0> mv_cnt)
<a name="l615"></a>{ </span><span class=cF2>//Goes through moves lst for one piece, eliminating invalid moves.</span><span class=cF0>
<a name="l616"></a> </span><span class=cF9>I64</span><span class=cF0> k, cnt = mv_cnt, res = </span><span class=cFE>0</span><span class=cF0>, x, y, dy;
<a name="l617"></a> GameState state2, *tmpg;
<a name="l618"></a> </span><span class=cF5>Move</span><span class=cF0> *dst = src;
<a name="l619"></a>
<a name="l620"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;cur_player) </span><span class=cF2>//Find King</span><span class=cF0>
<a name="l621"></a> k = </span><span class=cFE>16</span><span class=cF0>;
<a name="l622"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l623"></a> k = </span><span class=cFE>0</span><span class=cF0>;
<a name="l624"></a> </span><span class=cF1>while</span><span class=cF0> (cnt--)
<a name="l625"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l626"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;state2, state, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>GameState</span><span class=cF7>)</span><span class=cF0>);
<a name="l627"></a> MoveDo(&amp;state2, piece_num, src-&gt;x, src-&gt;y, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l628"></a>
<a name="l629"></a> </span><span class=cF2>//Don't repeat board position</span><span class=cF0>
<a name="l630"></a> tmpg = cur_state.next;
<a name="l631"></a> </span><span class=cF1>while</span><span class=cF0> (tmpg != &amp;cur_state)
<a name="l632"></a> {
<a name="l633"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>MemCompare</span><span class=cF7>(</span><span class=cF0>tmpg-&gt;pieces, state2.pieces, </span><span class=cF1>sizeof</span><span class=cF0>(PieceState) * </span><span class=cFE>32</span><span class=cF7>)</span><span class=cF0>)
<a name="l634"></a> </span><span class=cF1>goto</span><span class=cF0> cm_skip;
<a name="l635"></a> tmpg = tmpg-&gt;next;
<a name="l636"></a> }
<a name="l637"></a>
<a name="l638"></a> </span><span class=cF1>if</span><span class=cF0> (piece_num == k)
<a name="l639"></a> { </span><span class=cF2>//If king is moving, check his new location.</span><span class=cF0>
<a name="l640"></a> x = state2.pieces[k].x;
<a name="l641"></a> y = state2.pieces[k].y;
<a name="l642"></a> dy = y - state-&gt;pieces[k].y;
<a name="l643"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>dy</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>2</span><span class=cF0> &amp;&amp; </span><span class=cF2>/*castling?*/</span><span class=cF0> </span><span class=cF7>(</span><span class=cF0>SqrInChk(&amp;state2, x, y - dy) || SqrInChk(&amp;state2, x, y - </span><span class=cF5>SignI64</span><span class=cF7>(</span><span class=cF0>dy</span><span class=cF7>)</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>)
<a name="l644"></a> </span><span class=cF1>goto</span><span class=cF0> cm_skip; </span><span class=cF2>// This really needs to go into PieceMoves</span><span class=cF0>
<a name="l645"></a> }
<a name="l646"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l647"></a> {
<a name="l648"></a> x = state-&gt;pieces[k].x;
<a name="l649"></a> y = state-&gt;pieces[k].y;
<a name="l650"></a> }
<a name="l651"></a> </span><span class=cF1>if</span><span class=cF0> (!SqrInChk</span><span class=cF7>(</span><span class=cF0>&amp;state2, x, y</span><span class=cF7>)</span><span class=cF0>)
<a name="l652"></a> {
<a name="l653"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(dst++, src, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF5>Move</span><span class=cF7>)</span><span class=cF0>);
<a name="l654"></a> res++;
<a name="l655"></a> }
<a name="l656"></a>cm_skip:
<a name="l657"></a> src++;
<a name="l658"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l659"></a>
<a name="l660"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l661"></a>}
<a name="l662"></a>
<a name="l663"></a></span><span class=cF9>I64</span><span class=cF0> MoveCnt(GameState *state)
<a name="l664"></a>{
<a name="l665"></a> </span><span class=cF9>I64</span><span class=cF0> i, res = </span><span class=cFE>0</span><span class=cF0>, mv_cnt;
<a name="l666"></a> </span><span class=cF5>Move</span><span class=cF0> mvs[</span><span class=cFE>32</span><span class=cF0>];
<a name="l667"></a>
<a name="l668"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l669"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[i].player == state-&gt;cur_player)
<a name="l670"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l671"></a> mv_cnt = PieceMoves(state, i, mvs);
<a name="l672"></a> mv_cnt = ChkPieceMoves(state, i, mvs,mv_cnt);
<a name="l673"></a> res += mv_cnt;
<a name="l674"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l675"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l676"></a>}
<a name="l677"></a>
<a name="l678"></a>
<a name="l679"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task, </span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l680"></a>{
<a name="l681"></a> </span><span class=cF9>I64</span><span class=cF0> i, x, y, z, k0, k1;
<a name="l682"></a> PieceState *s = cur_state.pieces;
<a name="l683"></a>
<a name="l684"></a> brd_dc-&gt;flags |= </span><span class=cF3>DCF_NO_TRANSPARENTS</span><span class=cF0>;
<a name="l685"></a> </span><span class=cF5>GrBlot</span><span class=cF0>(dc, cx - cx2, cy - cy2, brd_dc);
<a name="l686"></a>
<a name="l687"></a> task-&gt;text_attr = </span><span class=cF3>YELLOW</span><span class=cF0> &lt;&lt; </span><span class=cFE>4</span><span class=cF0>;
<a name="l688"></a> dc-&gt;x = cx;
<a name="l689"></a> dc-&gt;y = cy;
<a name="l690"></a>
<a name="l691"></a> dc-&gt;flags |= </span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l692"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(dc-&gt;r, w2s, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0> * </span><span class=cFE>16</span><span class=cF0>);
<a name="l693"></a>
<a name="l694"></a> </span><span class=cF1>if</span><span class=cF0> (ai_thinking)
<a name="l695"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l696"></a> </span><span class=cF1>if</span><span class=cF0> (cur_state.cur_player)
<a name="l697"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l698"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l699"></a> dc-&gt;color = </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l700"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Blink</span><span class=cF0>)
<a name="l701"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, -</span><span class=cFE>11</span><span class=cF0> * </span><span class=cF3>FONT_WIDTH</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> - cy, </span><span class=cF6>&quot;Thinking...&quot;</span><span class=cF0>);
<a name="l702"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l703"></a>
<a name="l704"></a> dc-&gt;color = </span><span class=cF3>RED</span><span class=cF0>;
<a name="l705"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; cur_mv_cnt; i++)
<a name="l706"></a> </span><span class=cF5>GrRect3</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF0>cur_mvs[i].x - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * g + g / </span><span class=cFE>4</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>cur_mvs[i].y - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * g + g / </span><span class=cFE>4</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, g / </span><span class=cFE>2</span><span class=cF0>, g / </span><span class=cFE>2</span><span class=cF0>);
<a name="l707"></a>
<a name="l708"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l709"></a> dc-&gt;thick = </span><span class=cFE>2</span><span class=cF0>;
<a name="l710"></a> </span><span class=cF5>GrBorder</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF0>cursor_x - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * g + </span><span class=cFE>2</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>cursor_y - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * g + </span><span class=cFE>2</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>cursor_x - </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0> * g - </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>cursor_y - </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0> * g - </span><span class=cFE>1</span><span class=cF0>);
<a name="l711"></a>
<a name="l712"></a> </span><span class=cF5>DCDepthBufAlloc</span><span class=cF0>(dc);
<a name="l713"></a> k0 = k1 = </span><span class=cFE>0</span><span class=cF0>;
<a name="l714"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++,s++)
<a name="l715"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l716"></a> </span><span class=cF1>if</span><span class=cF0> (s-&gt;player &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l717"></a> { </span><span class=cF2>//Alive?</span><span class=cF0>
<a name="l718"></a> </span><span class=cF1>if</span><span class=cF0> (s-&gt;x != last_mv.x || s-&gt;y != last_mv.y || </span><span class=cF5>Blink</span><span class=cF0>)
<a name="l719"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l720"></a> x = g / </span><span class=cFE>2</span><span class=cF0> + (s-&gt;x - </span><span class=cFE>4</span><span class=cF0>) * g;
<a name="l721"></a> y = g / </span><span class=cFE>2</span><span class=cF0> + (s-&gt;y - </span><span class=cFE>4</span><span class=cF0>) * g;
<a name="l722"></a> z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l723"></a> </span><span class=cF5>DCTransform</span><span class=cF0>(dc, &amp;x, &amp;y, &amp;z);
<a name="l724"></a> z = </span><span class=cF3>GR_Z_ALL</span><span class=cF0> + s-&gt;x - s-&gt;y;
<a name="l725"></a>
<a name="l726"></a> dc-&gt;flags &amp;= ~</span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l727"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, x, y, z, imgs[s-&gt;type * </span><span class=cFE>2</span><span class=cF0> + s-&gt;player]);
<a name="l728"></a> dc-&gt;flags |= </span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l729"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l730"></a> }
<a name="l731"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l732"></a> { </span><span class=cF2>//Dead</span><span class=cF0>
<a name="l733"></a> </span><span class=cF1>if</span><span class=cF0> (s-&gt;player == -</span><span class=cFE>2</span><span class=cF0>)
<a name="l734"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l735"></a> </span><span class=cF1>if</span><span class=cF0> (k1 &lt; </span><span class=cFE>8</span><span class=cF0>)
<a name="l736"></a> {
<a name="l737"></a> x = cx + </span><span class=cFE>100</span><span class=cF0> + k1++ * g / </span><span class=cFE>2</span><span class=cF0>;
<a name="l738"></a> y = cy - </span><span class=cFE>180</span><span class=cF0>;
<a name="l739"></a> }
<a name="l740"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l741"></a> {
<a name="l742"></a> x = cx + </span><span class=cFE>100</span><span class=cF0> + (k1++ - </span><span class=cFE>8</span><span class=cF0>) * g / </span><span class=cFE>2</span><span class=cF0>;
<a name="l743"></a> y = cy - </span><span class=cFE>130</span><span class=cF0>;
<a name="l744"></a> }
<a name="l745"></a> z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l746"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l747"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l748"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l749"></a> </span><span class=cF1>if</span><span class=cF0> (k0 &lt; </span><span class=cFE>8</span><span class=cF0>)
<a name="l750"></a> {
<a name="l751"></a> x = cx + </span><span class=cFE>100</span><span class=cF0> + k0++ * g / </span><span class=cFE>2</span><span class=cF0>;
<a name="l752"></a> y = cy + </span><span class=cFE>220</span><span class=cF0>;
<a name="l753"></a> }
<a name="l754"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l755"></a> {
<a name="l756"></a> x = cx + </span><span class=cFE>100</span><span class=cF0> + (k0++ - </span><span class=cFE>8</span><span class=cF0>) * g / </span><span class=cFE>2</span><span class=cF0>;
<a name="l757"></a> y = cy + </span><span class=cFE>170</span><span class=cF0>;
<a name="l758"></a> }
<a name="l759"></a> z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l760"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l761"></a> dc-&gt;flags &amp;= ~</span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l762"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc, x, y, z, imgs[s-&gt;type * </span><span class=cFE>2</span><span class=cF0> + s-&gt;player + </span><span class=cFE>2</span><span class=cF0>]);
<a name="l763"></a> dc-&gt;flags |= </span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l764"></a> }
<a name="l765"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l766"></a> </span><span class=cF1>if</span><span class=cF0> (game_over &amp;&amp; </span><span class=cF5>Blink</span><span class=cF0>)
<a name="l767"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l768"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l769"></a> </span><span class=cF5>GrPrint3</span><span class=cF0>(dc, -</span><span class=cFE>9</span><span class=cF0> * </span><span class=cF3>FONT_WIDTH</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, -</span><span class=cF3>FONT_HEIGHT</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;Game Over&quot;</span><span class=cF0>);
<a name="l770"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l771"></a>}
<a name="l772"></a>
<a name="l773"></a>#</span><span class=cF1>define</span><span class=cF0> DEPTH -</span><span class=cFE>5</span><span class=cF0>
<a name="l774"></a>
<a name="l775"></a></span><span class=cF9>CDC</span><span class=cF0> *BrdNew()
<a name="l776"></a>{
<a name="l777"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, k, w = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width, h = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height;
<a name="l778"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc;
<a name="l779"></a>
<a name="l780"></a> g = </span><span class=cFE>42</span><span class=cF0>;
<a name="l781"></a> cx = w / </span><span class=cFE>2</span><span class=cF0> + </span><span class=cFE>40</span><span class=cF0>;
<a name="l782"></a> cy = h / </span><span class=cFE>2</span><span class=cF0>;
<a name="l783"></a>
<a name="l784"></a> w = </span><span class=cF5>Sqrt</span><span class=cF0>(</span><span class=cFE>2</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>) * (</span><span class=cFE>8</span><span class=cF0> * g + </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>FONT_WIDTH</span><span class=cF0>);
<a name="l785"></a> h = </span><span class=cFE>8</span><span class=cF0> * g + </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>;
<a name="l786"></a> cx2 = w / </span><span class=cFE>2</span><span class=cF0>;
<a name="l787"></a> cy2 = h / </span><span class=cFE>2</span><span class=cF0>;
<a name="l788"></a>
<a name="l789"></a> dc = </span><span class=cF5>DCNew</span><span class=cF0>(w, h);
<a name="l790"></a> dc-&gt;x = cx2;
<a name="l791"></a> dc-&gt;y = cy2;
<a name="l792"></a>
<a name="l793"></a> dc-&gt;flags |= </span><span class=cF3>DCF_TRANSFORMATION</span><span class=cF0>;
<a name="l794"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(dc-&gt;r, w2s, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0> * </span><span class=cFE>16</span><span class=cF0>);
<a name="l795"></a>
<a name="l796"></a> dc-&gt;color = </span><span class=cF3>YELLOW</span><span class=cF0>;
<a name="l797"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, w, h);
<a name="l798"></a>
<a name="l799"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l800"></a> </span><span class=cF1>for</span><span class=cF0> (i = -</span><span class=cFE>4</span><span class=cF0>; i &lt; </span><span class=cFE>4</span><span class=cF0>; i++)
<a name="l801"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l802"></a> </span><span class=cF5>GrPrint3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g - </span><span class=cFE>4</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0>, i * g + g / </span><span class=cFE>2</span><span class=cF0> - </span><span class=cFE>4</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;%C&quot;</span><span class=cF0>, i + </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF6>'A'</span><span class=cF0>);
<a name="l803"></a> </span><span class=cF5>GrPrint3</span><span class=cF0>(dc, </span><span class=cFE>4</span><span class=cF0> * g + </span><span class=cFE>14</span><span class=cF0>, i * g + g / </span><span class=cFE>2</span><span class=cF0> - </span><span class=cFE>4</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;%C&quot;</span><span class=cF0>, i + </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF6>'A'</span><span class=cF0>);
<a name="l804"></a> </span><span class=cF5>GrPrint3</span><span class=cF0>(dc, i * g + g / </span><span class=cFE>2</span><span class=cF0> + </span><span class=cFE>6</span><span class=cF0>, -</span><span class=cFE>4</span><span class=cF0> * g - </span><span class=cFE>12</span><span class=cF0> - </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;%C&quot;</span><span class=cF0>, i + </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF6>'1'</span><span class=cF0>);
<a name="l805"></a> </span><span class=cF5>GrPrint3</span><span class=cF0>(dc, i * g + g / </span><span class=cFE>2</span><span class=cF0> - </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0> * g + </span><span class=cFE>9</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF6>&quot;%C&quot;</span><span class=cF0>, i + </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF6>'1'</span><span class=cF0>);
<a name="l806"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l807"></a>
<a name="l808"></a> dc-&gt;thick = </span><span class=cFE>1</span><span class=cF0>;
<a name="l809"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l810"></a> </span><span class=cF1>for</span><span class=cF0> (i = -</span><span class=cFE>4</span><span class=cF0>; i &lt;= </span><span class=cFE>4</span><span class=cF0>; i++)
<a name="l811"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l812"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g, i * g, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0> * g, i * g, </span><span class=cFE>0</span><span class=cF0>);
<a name="l813"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, i * g, -</span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>0</span><span class=cF0>, i * g, </span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>0</span><span class=cF0>);
<a name="l814"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g, i * g, </span><span class=cFE>0</span><span class=cF0>, -</span><span class=cFE>4</span><span class=cF0> * g, i * g, DEPTH);
<a name="l815"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, i * g, </span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>0</span><span class=cF0>, i * g, </span><span class=cFE>4</span><span class=cF0> * g, DEPTH);
<a name="l816"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l817"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>4</span><span class=cF0> * g, DEPTH, -</span><span class=cFE>4</span><span class=cF0> * g, -</span><span class=cFE>4</span><span class=cF0> * g, DEPTH);
<a name="l818"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>4</span><span class=cF0>* g, DEPTH, </span><span class=cFE>4</span><span class=cF0> * g, </span><span class=cFE>4</span><span class=cF0> * g, DEPTH);
<a name="l819"></a>
<a name="l820"></a> k = </span><span class=cFE>0</span><span class=cF0>;
<a name="l821"></a> </span><span class=cF1>for</span><span class=cF0> (j = -</span><span class=cFE>4</span><span class=cF0>; j &lt; </span><span class=cFE>4</span><span class=cF0>; j++)
<a name="l822"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l823"></a> </span><span class=cF1>for</span><span class=cF0> (i = -</span><span class=cFE>4</span><span class=cF0>; i &lt; </span><span class=cFE>4</span><span class=cF0>; i++)
<a name="l824"></a> {
<a name="l825"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>i + j</span><span class=cF7>)</span><span class=cF0> &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l826"></a> dc-&gt;color = </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l827"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l828"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l829"></a> </span><span class=cF5>GrFloodFill3</span><span class=cF0>(dc, i * g + g / </span><span class=cFE>2</span><span class=cF0>, j * g + g / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l830"></a> }
<a name="l831"></a> </span><span class=cF1>if</span><span class=cF0> (j &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l832"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l833"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l834"></a> dc-&gt;color = </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l835"></a> </span><span class=cF5>GrFloodFill3</span><span class=cF0>(dc, -</span><span class=cFE>4</span><span class=cF0> * g, j * g + g / </span><span class=cFE>2</span><span class=cF0>, DEPTH / </span><span class=cFE>2</span><span class=cF0>);
<a name="l836"></a> </span><span class=cF1>if</span><span class=cF0> (j &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l837"></a> dc-&gt;color = </span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l838"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l839"></a> dc-&gt;color = </span><span class=cF3>DKGRAY</span><span class=cF0>;
<a name="l840"></a> </span><span class=cF5>GrFloodFill3</span><span class=cF0>(dc, j * g + g / </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>4</span><span class=cF0> * g, DEPTH / </span><span class=cFE>2</span><span class=cF0>);
<a name="l841"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l842"></a>
<a name="l843"></a> </span><span class=cF1>return</span><span class=cF0> dc;
<a name="l844"></a>}
<a name="l845"></a>
<a name="l846"></a></span><span class=cF9>I64</span><span class=cF0> AIStateScore(GameState *state, </span><span class=cF9>I64</span><span class=cF0> player)
<a name="l847"></a>{
<a name="l848"></a> </span><span class=cF1>if</span><span class=cF0> (player)
<a name="l849"></a> </span><span class=cF1>return</span><span class=cF0> -state-&gt;raw_score;
<a name="l850"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l851"></a> </span><span class=cF1>return</span><span class=cF0> state-&gt;raw_score;
<a name="l852"></a>}
<a name="l853"></a>
<a name="l854"></a></span><span class=cF9>I64</span><span class=cF0> move_depth, kill_depth;
<a name="l855"></a>
<a name="l856"></a></span><span class=cF9>I64</span><span class=cF0> AIMove2(GameState *state, </span><span class=cF9>I64</span><span class=cF0> depth)
<a name="l857"></a>{
<a name="l858"></a> </span><span class=cF9>I64</span><span class=cF0> i, possible_moves = </span><span class=cFE>0</span><span class=cF0>, best_piece, score,
<a name="l859"></a> best_score = </span><span class=cF3>I64_MIN</span><span class=cF0>, mv_cnt, score_adjust;
<a name="l860"></a> </span><span class=cF5>Move</span><span class=cF0> best_mv, mvs[</span><span class=cFE>32</span><span class=cF0>],*ptr;
<a name="l861"></a> GameState state2;
<a name="l862"></a> </span><span class=cF1>Bool</span><span class=cF0> first = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l863"></a>
<a name="l864"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>UnusedStack</span><span class=cF0> &lt; </span><span class=cFE>0x1000</span><span class=cF0>)
<a name="l865"></a> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//Shouldn't happen</span><span class=cF0>
<a name="l866"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(chess_doc, </span><span class=cF6>&quot;StkOverflow\n&quot;</span><span class=cF0>);
<a name="l867"></a> </span><span class=cF1>return</span><span class=cF0> AIStateScore(state, state-&gt;cur_player);
<a name="l868"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l869"></a>
<a name="l870"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l871"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[i].player == state-&gt;cur_player)
<a name="l872"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l873"></a> mv_cnt = PieceMoves(state, i, mvs);
<a name="l874"></a> possible_moves += mv_cnt;
<a name="l875"></a> ptr = mvs;
<a name="l876"></a> </span><span class=cF1>while</span><span class=cF0> (mv_cnt--)
<a name="l877"></a> {
<a name="l878"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;state2, state, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>GameState</span><span class=cF7>)</span><span class=cF0>);
<a name="l879"></a> state2.parent = state;
<a name="l880"></a> </span><span class=cF1>if</span><span class=cF0> (MoveDo</span><span class=cF7>(</span><span class=cF0>&amp;state2, i, ptr-&gt;x, ptr-&gt;y, </span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0> &amp;&amp; depth &lt; kill_depth || depth &lt; move_depth)
<a name="l881"></a> score =-AIMove2(&amp;state2, depth + </span><span class=cFE>1</span><span class=cF0>);
<a name="l882"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l883"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l884"></a> score = AIStateScore(&amp;state2, state-&gt;cur_player);
<a name="l885"></a> </span><span class=cF1>if</span><span class=cF0> (score_adjust = </span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cF0>state2.raw_score - state-&gt;raw_score</span><span class=cF7>)</span><span class=cF0>)
<a name="l886"></a> score += score_adjust - piece_scores[state-&gt;pieces[i].type];
<a name="l887"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l888"></a> </span><span class=cF1>if</span><span class=cF0> (first || score&gt;best_score)
<a name="l889"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l890"></a> best_score = score;
<a name="l891"></a> best_piece = i;
<a name="l892"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;best_mv, ptr, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF5>Move</span><span class=cF7>)</span><span class=cF0>);
<a name="l893"></a> first = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l894"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l895"></a> ptr++;
<a name="l896"></a> }
<a name="l897"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l898"></a> </span><span class=cF1>if</span><span class=cF0> (!first)
<a name="l899"></a> MoveDo(state, best_piece, best_mv.x, best_mv.y, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l900"></a>
<a name="l901"></a> </span><span class=cF1>return</span><span class=cF0> best_score + possible_moves &lt;&lt; SHIFT_POSSIBLE_MOVES;
<a name="l902"></a>}
<a name="l903"></a>
<a name="l904"></a></span><span class=cF1>class</span><span class=cF0> ChessJob
<a name="l905"></a>{
<a name="l906"></a> GameState *state;
<a name="l907"></a> </span><span class=cF5>Move</span><span class=cF0> *mv;
<a name="l908"></a>};
<a name="l909"></a>
<a name="l910"></a></span><span class=cF1>U0</span><span class=cF0> AIMove1(ChessJob *cj)
<a name="l911"></a>{
<a name="l912"></a> GameState state2;
<a name="l913"></a> </span><span class=cF5>Move</span><span class=cF0> *ptr = cj-&gt;mv;
<a name="l914"></a>
<a name="l915"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;state2, cj-&gt;state, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>GameState</span><span class=cF7>)</span><span class=cF0>);
<a name="l916"></a> state2.parent = cj-&gt;state;
<a name="l917"></a> MoveDo(&amp;state2, ptr-&gt;piece, ptr-&gt;x, ptr-&gt;y, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l918"></a> ptr-&gt;score = -AIMove2(&amp;state2, </span><span class=cFE>1</span><span class=cF0>);
<a name="l919"></a> </span><span class=cF5>Free</span><span class=cF0>(cj);
<a name="l920"></a>}
<a name="l921"></a>
<a name="l922"></a></span><span class=cF9>I64</span><span class=cF0> MoveCmp(</span><span class=cF5>Move</span><span class=cF0> *e1, </span><span class=cF5>Move</span><span class=cF0> *e2)
<a name="l923"></a>{
<a name="l924"></a> </span><span class=cF1>if</span><span class=cF0> (e1-&gt;score &lt; e2-&gt;score)
<a name="l925"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>1</span><span class=cF0>;
<a name="l926"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (e1-&gt;score == e2-&gt;score)
<a name="l927"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l928"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l929"></a> </span><span class=cF1>return</span><span class=cF0> -</span><span class=cFE>1</span><span class=cF0>;
<a name="l930"></a>}
<a name="l931"></a>
<a name="l932"></a></span><span class=cF1>U0</span><span class=cF0> AIMove(GameState *state)
<a name="l933"></a>{
<a name="l934"></a> </span><span class=cF9>I64</span><span class=cF0> i, cnt = </span><span class=cFE>0</span><span class=cF0>, mv_cnt, best_score;
<a name="l935"></a> </span><span class=cF5>Move</span><span class=cF0> mvs[</span><span class=cFE>32</span><span class=cF0>], *ptr, *ptr2;
<a name="l936"></a> ChessJob *cj;
<a name="l937"></a>
<a name="l938"></a> </span><span class=cF1>if</span><span class=cF0> (cnt = MoveCnt</span><span class=cF7>(</span><span class=cF0>state</span><span class=cF7>)</span><span class=cF0>)
<a name="l939"></a> </span><span class=cF7>{</span><span class=cF2>//Collect AI possible valid moves</span><span class=cF0>
<a name="l940"></a> ptr = ptr2 = </span><span class=cF5>MAlloc</span><span class=cF0>(cnt * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF5>Move</span><span class=cF7>)</span><span class=cF0>);
<a name="l941"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>32</span><span class=cF0>; i++)
<a name="l942"></a> </span><span class=cF1>if</span><span class=cF0> (state-&gt;pieces[i].player == state-&gt;cur_player)
<a name="l943"></a> {
<a name="l944"></a> mv_cnt = PieceMoves(state, i, mvs);
<a name="l945"></a> mv_cnt = ChkPieceMoves(state, i, mvs, mv_cnt);
<a name="l946"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(ptr, mvs, mv_cnt * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF5>Move</span><span class=cF7>)</span><span class=cF0>);
<a name="l947"></a> ptr += mv_cnt;
<a name="l948"></a> }
<a name="l949"></a>
<a name="l950"></a> </span><span class=cF2>//Dispatch to MP scoring all moves</span><span class=cF0>
<a name="l951"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, ptr = ptr2; i &lt; cnt; i++, ptr++)
<a name="l952"></a> {
<a name="l953"></a> ptr-&gt;score = -</span><span class=cF3>I32_MAX</span><span class=cF0>;
<a name="l954"></a> cj = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>ChessJob</span><span class=cF7>)</span><span class=cF0>);
<a name="l955"></a> cj-&gt;state = state;
<a name="l956"></a> cj-&gt;mv = ptr;
<a name="l957"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mp_count</span><span class=cF0> &gt; </span><span class=cFE>1</span><span class=cF0>)
<a name="l958"></a> </span><span class=cF5>JobQueue</span><span class=cF0>(&amp;AIMove1, cj, i % </span><span class=cF7>(</span><span class=cFB>mp_count</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l959"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l960"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l961"></a> AIMove1(cj);
<a name="l962"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l963"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l964"></a> }
<a name="l965"></a>
<a name="l966"></a> </span><span class=cF2>//Wait for finish</span><span class=cF0>
<a name="l967"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>, ptr = ptr2; i &lt; cnt; i++, ptr++)
<a name="l968"></a> </span><span class=cF1>while</span><span class=cF0> (ptr-&gt;score == -</span><span class=cF3>I32_MAX</span><span class=cF0>)
<a name="l969"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l970"></a> </span><span class=cF5>QuickSort</span><span class=cF0>(ptr2, cnt, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF5>Move</span><span class=cF7>)</span><span class=cF0>, &amp;MoveCmp);
<a name="l971"></a>
<a name="l972"></a> </span><span class=cF2>//Cnt ties for first</span><span class=cF0>
<a name="l973"></a> best_score = ptr2-&gt;score;
<a name="l974"></a> mv_cnt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l975"></a> ptr = ptr2;
<a name="l976"></a> </span><span class=cF1>while</span><span class=cF0> (mv_cnt &lt; cnt &amp;&amp; ptr-&gt;score == best_score)
<a name="l977"></a> {
<a name="l978"></a> mv_cnt++;
<a name="l979"></a> ptr++;
<a name="l980"></a> }
<a name="l981"></a>
<a name="l982"></a> ptr = ptr2 + </span><span class=cF5>RandU16</span><span class=cF0> % mv_cnt;
<a name="l983"></a> MoveDo(state, ptr-&gt;piece, ptr-&gt;x, ptr-&gt;y, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l984"></a> </span><span class=cF5>Free</span><span class=cF0>(ptr2);
<a name="l985"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l986"></a>}
<a name="l987"></a>
<a name="l988"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l989"></a>{
<a name="l990"></a> chess_doc = </span><span class=cF5>DocPut</span><span class=cF0>;
<a name="l991"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l992"></a> </span><span class=cF6>&quot;$FD,BLACK$$BG,YELLOW$&quot;</span><span class=cF0>;
<a name="l993"></a> game_over = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l994"></a> ai_thinking = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l995"></a> move_depth = </span><span class=cFE>3</span><span class=cF0>;
<a name="l996"></a> kill_depth = </span><span class=cFE>5</span><span class=cF0>;
<a name="l997"></a> cur_mv_cnt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l998"></a> last_mv.x = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l999"></a> last_mv.y = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1000"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;cur_state, &amp;setup_state, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>cur_state</span><span class=cF7>)</span><span class=cF0>);
<a name="l1001"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(&amp;cur_state);
<a name="l1002"></a> cur_state.is_human[</span><span class=cFE>0</span><span class=cF0>] = </span><span class=cF5>PopUpNoYes</span><span class=cF0>(</span><span class=cF6>&quot;$FG,BLACK$WHITE is human?&quot;</span><span class=cF0>);
<a name="l1003"></a> cur_state.is_human[</span><span class=cFE>1</span><span class=cF0>] = </span><span class=cF5>PopUpNoYes</span><span class=cF0>(</span><span class=cF6>&quot;$FG,BLACK$BLACK is human?&quot;</span><span class=cF0>);
<a name="l1004"></a>
<a name="l1005"></a> GameSnapShot;
<a name="l1006"></a>}
<a name="l1007"></a>
<a name="l1008"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l1009"></a>{
<a name="l1010"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&amp;cur_state, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l1011"></a>}
<a name="l1012"></a>
<a name="l1013"></a></span><span class=cF1>U0</span><span class=cF0> SetMouseCursor()
<a name="l1014"></a>{
<a name="l1015"></a> </span><span class=cF9>I64</span><span class=cF0> x = (cursor_x - </span><span class=cFE>4</span><span class=cF0>) * g + g / </span><span class=cFE>2</span><span class=cF0>,
<a name="l1016"></a> y = (cursor_y - </span><span class=cFE>4</span><span class=cF0>) * g + g / </span><span class=cFE>2</span><span class=cF0>,
<a name="l1017"></a> z = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1018"></a>
<a name="l1019"></a> </span><span class=cF5>Mat4x4MulXYZ</span><span class=cF0>(w2s, &amp;x, &amp;y, &amp;z);
<a name="l1020"></a> x += cx + </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_left + </span><span class=cF5>Fs</span><span class=cF0>-&gt;scroll_x;
<a name="l1021"></a> y += cy + </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_top + </span><span class=cF5>Fs</span><span class=cF0>-&gt;scroll_y;
<a name="l1022"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse</span><span class=cF0>.pos.x != x || </span><span class=cFB>mouse</span><span class=cF0>.pos.y != y)
<a name="l1023"></a> </span><span class=cF5>MouseSet</span><span class=cF0>(x, y);
<a name="l1024"></a>}
<a name="l1025"></a>
<a name="l1026"></a></span><span class=cF1>U0</span><span class=cF0> SetKbdCursor(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l1027"></a>{
<a name="l1028"></a> </span><span class=cF9>I64</span><span class=cF0> z;
<a name="l1029"></a>
<a name="l1030"></a> x -= cx;
<a name="l1031"></a> y -= cy;
<a name="l1032"></a> z = y;
<a name="l1033"></a> </span><span class=cF5>Mat4x4MulXYZ</span><span class=cF0>(s2w, &amp;x, &amp;y, &amp;z);
<a name="l1034"></a> cursor_x = </span><span class=cF5>ClampI64</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>x + </span><span class=cFE>4</span><span class=cF0> * g</span><span class=cF7>)</span><span class=cF0> / g, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1035"></a> cursor_y = </span><span class=cF5>ClampI64</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>y + </span><span class=cFE>4</span><span class=cF0> * g</span><span class=cF7>)</span><span class=cF0> / g, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1036"></a>}
<a name="l1037"></a>
<a name="l1038"></a></span><span class=cF1>U0</span><span class=cF0> Chess()
<a name="l1039"></a>{
<a name="l1040"></a> </span><span class=cF9>I64</span><span class=cF0> arg1, arg2, cur_piece;
<a name="l1041"></a>
<a name="l1042"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l1043"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l1044"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l1045"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l1046"></a> Init;
<a name="l1047"></a>
<a name="l1048"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l1049"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l1050"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l1051"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l1052"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l1053"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l1054"></a> </span><span class=cF6>&quot; Move(,CH_SPACE);&quot;</span><span class=cF0>
<a name="l1055"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l1056"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>);
<a name="l1057"></a>
<a name="l1058"></a>
<a name="l1059"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit = </span><span class=cF3>WIG_TASK_DEFAULT</span><span class=cF0> - </span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0> - </span><span class=cF3>WIF_SELF_BORDER</span><span class=cF0> - </span><span class=cF3>WIF_FOCUS_TASK_MENU</span><span class=cF0>;
<a name="l1060"></a>
<a name="l1061"></a> cursor_x = cursor_y = </span><span class=cFE>3</span><span class=cF0>;
<a name="l1062"></a>
<a name="l1063"></a> w2s = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>; </span><span class=cF2>//World-to-Scrn</span><span class=cF0>
<a name="l1064"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(w2s, -</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>4</span><span class=cF0>);
<a name="l1065"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(w2s, </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>4</span><span class=cF0>);
<a name="l1066"></a>
<a name="l1067"></a> s2w = </span><span class=cF5>Mat4x4IdentNew</span><span class=cF0>; </span><span class=cF2>//Scrn-to-World</span><span class=cF0>
<a name="l1068"></a> </span><span class=cF5>Mat4x4RotX</span><span class=cF0>(s2w, -</span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>4</span><span class=cF0>);
<a name="l1069"></a> </span><span class=cF5>Mat4x4RotZ</span><span class=cF0>(s2w, </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cFE>4</span><span class=cF0>);
<a name="l1070"></a>
<a name="l1071"></a> brd_dc = BrdNew;
<a name="l1072"></a>
<a name="l1073"></a> SetMouseCursor;
<a name="l1074"></a>
<a name="l1075"></a> </span><span class=cF5>PaletteSetLight</span><span class=cF0>(</span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l1076"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;draw_it = &amp;</span><span class=cF5>DrawIt</span><span class=cF0>;
<a name="l1077"></a>
<a name="l1078"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l1079"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1080"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l1081"></a> {
<a name="l1082"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>MessageScan</span><span class=cF7>(</span><span class=cF0>&amp;arg1, &amp;arg2, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> +
<a name="l1083"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0> +
<a name="l1084"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0> +
<a name="l1085"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0> +
<a name="l1086"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF7>)</span><span class=cF0>)
<a name="l1087"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1088"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l1089"></a> </span><span class=cF1>if</span><span class=cF0> (!game_over &amp;&amp; !cur_state.is_human[cur_state.cur_player])
<a name="l1090"></a> {
<a name="l1091"></a> ai_thinking = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l1092"></a> AIMove(&amp;cur_state);
<a name="l1093"></a> ai_thinking = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l1094"></a> </span><span class=cF5>Beep</span><span class=cF0>;
<a name="l1095"></a> }
<a name="l1096"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l1097"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1098"></a>
<a name="l1099"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF0>:
<a name="l1100"></a> SetKbdCursor(arg1, arg2);
<a name="l1101"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1102"></a>
<a name="l1103"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0>:
<a name="l1104"></a> SetKbdCursor(arg1, arg2);
<a name="l1105"></a>ch_mv_start:
<a name="l1106"></a> </span><span class=cF1>if</span><span class=cF0> (!game_over &amp;&amp; cur_state.is_human[cur_state.cur_player])
<a name="l1107"></a> {
<a name="l1108"></a> cur_piece = PieceFind(cursor_x, cursor_y, cur_state.cur_player);
<a name="l1109"></a> </span><span class=cF1>if</span><span class=cF0> (cur_piece &gt;= </span><span class=cFE>0</span><span class=cF0>)
<a name="l1110"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1111"></a> cur_mv_cnt = PieceMoves(&amp;cur_state, cur_piece, cur_mvs);
<a name="l1112"></a> cur_mv_cnt = ChkPieceMoves(&amp;cur_state, cur_piece, cur_mvs, cur_mv_cnt);
<a name="l1113"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1114"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1115"></a> cur_mv_cnt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1116"></a> }
<a name="l1117"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1118"></a>
<a name="l1119"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0>:
<a name="l1120"></a> SetKbdCursor(arg1, arg2);
<a name="l1121"></a>ch_mv_end:
<a name="l1122"></a> </span><span class=cF1>if</span><span class=cF0> (!game_over &amp;&amp; cur_state.is_human[cur_state.cur_player])
<a name="l1123"></a> {
<a name="l1124"></a> </span><span class=cF1>if</span><span class=cF0> (cur_piece &gt;= </span><span class=cFE>0</span><span class=cF0> &amp;&amp; HumanMove</span><span class=cF7>(</span><span class=cF0>&amp;cur_state, cur_piece, cur_mvs, cur_mv_cnt, cursor_x, cursor_y</span><span class=cF7>)</span><span class=cF0>)
<a name="l1125"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1126"></a> </span><span class=cF5>Beep</span><span class=cF0>(</span><span class=cFE>22</span><span class=cF0>);
<a name="l1127"></a> cur_piece = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1128"></a> cur_mv_cnt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1129"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1130"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l1131"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1132"></a> cur_piece = -</span><span class=cFE>1</span><span class=cF0>;
<a name="l1133"></a> cur_mv_cnt = </span><span class=cFE>0</span><span class=cF0>;
<a name="l1134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1135"></a> }
<a name="l1136"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1137"></a>
<a name="l1138"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>:
<a name="l1139"></a> </span><span class=cF1>if</span><span class=cF0> (arg1 == </span><span class=cF3>CH_SPACE</span><span class=cF0>)
<a name="l1140"></a> </span><span class=cF1>goto</span><span class=cF0> ch_mv_end;
<a name="l1141"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1142"></a>
<a name="l1143"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>:
<a name="l1144"></a> </span><span class=cF1>switch</span><span class=cF0> (arg1)
<a name="l1145"></a> {
<a name="l1146"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l1147"></a> CleanUp;
<a name="l1148"></a> Init;
<a name="l1149"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1150"></a>
<a name="l1151"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l1152"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l1153"></a> </span><span class=cF1>goto</span><span class=cF0> ch_done;
<a name="l1154"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SPACE</span><span class=cF0>:
<a name="l1155"></a> </span><span class=cF1>goto</span><span class=cF0> ch_mv_start;
<a name="l1156"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l1157"></a> </span><span class=cF1>switch</span><span class=cF0> (arg2.u8[</span><span class=cFE>0</span><span class=cF0>])
<a name="l1158"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1159"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>:
<a name="l1160"></a> cursor_y = </span><span class=cF5>ClampI64</span><span class=cF0>(cursor_y + </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1161"></a> SetMouseCursor;
<a name="l1162"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1163"></a>
<a name="l1164"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_LEFT</span><span class=cF0>:
<a name="l1165"></a> cursor_y = </span><span class=cF5>ClampI64</span><span class=cF0>(cursor_y - </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1166"></a> SetMouseCursor;
<a name="l1167"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1168"></a>
<a name="l1169"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>:
<a name="l1170"></a> cursor_x = </span><span class=cF5>ClampI64</span><span class=cF0>(cursor_x - </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1171"></a> SetMouseCursor;
<a name="l1172"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1173"></a>
<a name="l1174"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>:
<a name="l1175"></a> cursor_x = </span><span class=cF5>ClampI64</span><span class=cF0>(cursor_x + </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>7</span><span class=cF0>);
<a name="l1176"></a> SetMouseCursor;
<a name="l1177"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1178"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1179"></a> }
<a name="l1180"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l1181"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1182"></a> }
<a name="l1183"></a>ch_done:
<a name="l1184"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1185"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l1186"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l1187"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l1188"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l1189"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l1190"></a> </span><span class=cF5>DCDel</span><span class=cF0>(brd_dc);
<a name="l1191"></a> </span><span class=cF5>Free</span><span class=cF0>(s2w);
<a name="l1192"></a> </span><span class=cF5>Free</span><span class=cF0>(w2s);
<a name="l1193"></a> CleanUp;
<a name="l1194"></a>}
<a name="l1195"></a>
<a name="l1196"></a>Chess;
<a name="l1197"></a>
<a name="l1198"></a></span><span class=cF1>U0</span><span class=cF0> DoChess()
<a name="l1199"></a>{
<a name="l1200"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l1201"></a> </span><span class=cF9>CTask</span><span class=cF0> *task = </span><span class=cF5>User</span><span class=cF0>;
<a name="l1202"></a>
<a name="l1203"></a> </span><span class=cF5>XTalk</span><span class=cF0>(task, </span><span class=cF6>&quot;#include \&quot;::/Demo/Games/Chess\&quot;;\n&quot;</span><span class=cF0>);
<a name="l1204"></a> </span><span class=cF5>BirthWait</span><span class=cF0>(&amp;task-&gt;popup_task);
<a name="l1205"></a> </span><span class=cF5>TaskWait</span><span class=cF0>(task-&gt;popup_task);
<a name="l1206"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task-&gt;popup_task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cF3>CH_SPACE</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l1207"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>100</span><span class=cF0>);
<a name="l1208"></a> </span><span class=cF5>BirthWait</span><span class=cF0>(&amp;task-&gt;popup_task);
<a name="l1209"></a> </span><span class=cF5>TaskWait</span><span class=cF0>(task-&gt;popup_task);
<a name="l1210"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task-&gt;popup_task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cF3>CH_SPACE</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l1211"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>100</span><span class=cF0>);
<a name="l1212"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>8</span><span class=cF0>; i++)
<a name="l1213"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l1214"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF3>SC_CURSOR_DOWN</span><span class=cF0>);
<a name="l1215"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF3>SC_CURSOR_RIGHT</span><span class=cF0>);
<a name="l1216"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>25</span><span class=cF0>);
<a name="l1217"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l1218"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>);
<a name="l1219"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>250</span><span class=cF0>);
<a name="l1220"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>, </span><span class=cF3>CH_SPACE</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l1221"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>);
<a name="l1222"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>250</span><span class=cF0>);
<a name="l1223"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF3>SC_CURSOR_UP</span><span class=cF0>);
<a name="l1224"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>, </span><span class=cF3>CH_SPACE</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l1225"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>1000</span><span class=cF0>);
<a name="l1226"></a> </span><span class=cF5>MessagePostWait</span><span class=cF0>(task, </span><span class=cF3>MESSAGE_KEY_DOWN_UP</span><span class=cF0>, </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l1227"></a> </span><span class=cF5>DeathWait</span><span class=cF0>(&amp;task, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l1228"></a>}
<a name="l1229"></a>
<a name="l1230"></a></span><span class=cF9>
<a name="l1231"></a>Chess/* Graphics Not Rendered in HTML */</span></pre></body>
</html>