<code
class
=
"language-c"
><span
class
=
"cm"
>
</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"cp"
>#
include
<stdio.h></stdio.h></span>
<span
class
=
"cm"
>
</span>
<span
class
=
"cp"
>#define STONE 3 </span><span
class
=
"c1"
>
<span
class
=
"cp"
>#define LEAF 7 </span><span
class
=
"c1"
>
<span
class
=
"cp"
>#define WHITE 0 </span><span
class
=
"c1"
>
<span
class
=
"cp"
>#define BLACK 1 </span><span
class
=
"c1"
>
<span
class
=
"cp"
>#define NOPIECE 0 </span><span
class
=
"c1"
>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"mi"
>64</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"p"
>{</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span>
<span
class
=
"p"
>};</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
static
</span> <span
class
=
"k"
>
const
</span> <span
class
=
"kt"
>int</span> <span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"mi"
>64</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"p"
>{</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span>
<span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>0</span>
<span
class
=
"p"
>};</span>
<span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>getXFromLocation</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>location</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"p"
>(</span><span
class
=
"n"
>location</span> <span
class
=
"o"
>&</span> <span
class
=
"mi"
>7</span><span
class
=
"p"
>)</span> <span
class
=
"o"
>-</span> <span
class
=
"mi"
>2</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>getYFromLocation</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>location</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"p"
>(</span><span
class
=
"n"
>location</span> <span
class
=
"o"
>>></span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>)</span> <span
class
=
"o"
>-</span> <span
class
=
"mi"
>2</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>getLocationFromXY</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>x</span><span
class
=
"p"
>,</span> <span
class
=
"kt"
>int</span> <span
class
=
"n"
>y</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"p"
>(</span><span
class
=
"n"
>x</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>2</span><span
class
=
"p"
>)</span> <span
class
=
"o"
>+</span> <span
class
=
"p"
>(</span><span
class
=
"n"
>y</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>2</span> <span
class
=
"o"
> <span
class
=
"mi"
>3</span><span
class
=
"p"
>);</span>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>currentPlayer</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>WHITE</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"kt"
>void</span> <span
class
=
"nf"
>changePlayer</span><span
class
=
"p"
>(){</span>
<span
class
=
"n"
>currentPlayer</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>1</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>currentPlayer</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>void</span> <span
class
=
"nf"
>addPiece</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>location</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>piece</span><span
class
=
"p"
>;</span>
<span
class
=
"n"
>piece</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>currentPlayer</span> <span
class
=
"o"
>*</span> <span
class
=
"mi"
>4</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>location</span><span
class
=
"p"
>]){</span>
<span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>location</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>piece</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>void</span> <span
class
=
"nf"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>location</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>location</span><span
class
=
"p"
>]){</span>
<span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>location</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>generateMoveFrom</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>move</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>move</span> <span
class
=
"o"
>&</span> <span
class
=
"mi"
>255</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>generateMoveTo</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>move</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>move</span> <span
class
=
"o"
>>></span> <span
class
=
"mi"
>8</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>composeMove</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>locationFrom</span><span
class
=
"p"
>,</span> <span
class
=
"kt"
>int</span> <span
class
=
"n"
>locationTo</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>locationFrom</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>locationTo</span> <span
class
=
"o"
>*</span> <span
class
=
"mi"
>256</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"cp"
>#define MAX_GEN_MOVES 32 </span><span
class
=
"c1"
>
<span
class
=
"k"
>
static
</span> <span
class
=
"kt"
>int</span> <span
class
=
"n"
>theMoves</span><span
class
=
"p"
>[</span><span
class
=
"n"
>MAX_GEN_MOVES</span><span
class
=
"p"
>];</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
static
</span> <span
class
=
"k"
>
const
</span> <span
class
=
"kt"
>char</span> <span
class
=
"n"
>movesTable</span><span
class
=
"p"
>[</span><span
class
=
"mi"
>4</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"p"
>{</span><span
class
=
"o"
>-</span><span
class
=
"mi"
>8</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>8</span><span
class
=
"p"
>,</span> <span
class
=
"o"
>-</span><span
class
=
"mi"
>1</span><span
class
=
"p"
>,</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>};</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>generateAllMoves</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"o"
>*</span><span
class
=
"n"
>moves</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>i</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>from</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>to</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>genCount</span><span
class
=
"p"
>;</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>pieceFrom</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>pieceTo</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>genCount</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>myPiece</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>currentPlayer</span> <span
class
=
"o"
>*</span> <span
class
=
"mi"
>4</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>from</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>from</span> <span
class
=
"o"
> <span
class
=
"mi"
>64</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>from</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>pieceFrom</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>from</span><span
class
=
"p"
>];</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>pieceFrom</span> <span
class
=
"o"
>!=</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
continue
</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span> <span
class
=
"o"
> <span
class
=
"mi"
>4</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>to</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>from</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>movesTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>];</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>to</span><span
class
=
"p"
>]){</span> <span
class
=
"c1"
>
<span
class
=
"n"
>pieceTo</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>to</span><span
class
=
"p"
>];</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>pieceTo</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"n"
>moves</span><span
class
=
"p"
>[</span><span
class
=
"n"
>genCount</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>composeMove</span><span
class
=
"p"
>(</span><span
class
=
"n"
>from</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>to</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>genCount</span><span
class
=
"o"
>++</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span><span
class
=
"c1"
>
<span
class
=
"p"
>}</span><span
class
=
"c1"
>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>genCount</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>makeOneMove</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>move</span><span
class
=
"p"
>,</span> <span
class
=
"kt"
>int</span> <span
class
=
"o"
>*</span><span
class
=
"n"
>eatTable</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>i</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>genCount</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>isLegalMove</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>from</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>to</span><span
class
=
"p"
>;</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>oppPiece</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>eatCount</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>isLegalMove</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>genCount</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateAllMoves</span><span
class
=
"p"
>(</span><span
class
=
"n"
>theMoves</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span> <span
class
=
"o"
> <span
class
=
"n"
>genCount</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>theMoves</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>move</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>isLegalMove</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
break
</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>isLegalMove</span> <span
class
=
"o"
>==</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>from</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateMoveFrom</span><span
class
=
"p"
>(</span><span
class
=
"n"
>move</span><span
class
=
"p"
>);</span>
<span
class
=
"n"
>to</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateMoveTo</span><span
class
=
"p"
>(</span><span
class
=
"n"
>move</span><span
class
=
"p"
>);</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>from</span><span
class
=
"p"
>);</span>
<span
class
=
"n"
>addPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>to</span><span
class
=
"p"
>);</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>eatCount</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>myPiece</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>currentPlayer</span> <span
class
=
"o"
>*</span> <span
class
=
"mi"
>4</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>oppPiece</span> <span
class
=
"o"
>=</span> <span
class
=
"p"
>(</span><span
class
=
"mi"
>1</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>currentPlayer</span><span
class
=
"p"
>)</span> <span
class
=
"o"
>*</span> <span
class
=
"mi"
>4</span> <span
class
=
"o"
>+</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span> <span
class
=
"o"
> <span
class
=
"mi"
>4</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>step</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>movesTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>];</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>+=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>oppPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>+=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>-=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>eatCount</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatCount</span><span
class
=
"o"
>++</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>oppPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>+=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>-=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>eatCount</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatCount</span><span
class
=
"o"
>++</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>oppPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>+=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>eatCount</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatCount</span><span
class
=
"o"
>++</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>NOPIECE</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>to</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>myPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>+=</span> <span
class
=
"n"
>step</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>inBoard</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>&&</span> <span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>oppPiece</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>focus</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>focus</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>eatCount</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>focus</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"n"
>eatCount</span><span
class
=
"o"
>++</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>changePlayer</span><span
class
=
"p"
>();</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"mi"
>1</span> <span
class
=
"o"
>+</span> <span
class
=
"n"
>eatCount</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>isCurrentPlayerDie</span><span
class
=
"p"
>(){</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>generateAllMoves</span><span
class
=
"p"
>(</span><span
class
=
"n"
>theMoves</span><span
class
=
"p"
>)){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"mi"
>1</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>evaluatePosition</span><span
class
=
"p"
>(){</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>i</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>whiteValue</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>blackValue</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>value</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>whiteValue</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>blackValue</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span> <span
class
=
"o"
> <span
class
=
"mi"
>64</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>STONE</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>whiteValue</span> <span
class
=
"o"
>+=</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>board</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>]</span> <span
class
=
"o"
>==</span> <span
class
=
"n"
>LEAF</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>blackValue</span> <span
class
=
"o"
>+=</span> <span
class
=
"mi"
>3</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"n"
>value</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>whiteValue</span> <span
class
=
"o"
>-</span> <span
class
=
"n"
>blackValue</span><span
class
=
"p"
>;</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>value</span><span
class
=
"p"
>;</span>
<span
class
=
"p"
>}</span>
<span
class
=
"cm"
>
</span>
<span
class
=
"cp"
>#define SEARCH_DEPTH 7 </span><span
class
=
"c1"
>
<span
class
=
"cp"
>#define INFINITY_VALUE 100 </span><span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>bestMove</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>theDepth</span><span
class
=
"p"
>;</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>void</span> <span
class
=
"nf"
>undoOneMove</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>move</span><span
class
=
"p"
>,</span> <span
class
=
"kt"
>int</span> <span
class
=
"n"
>eatCount</span><span
class
=
"p"
>,</span> <span
class
=
"kt"
>int</span> <span
class
=
"o"
>*</span><span
class
=
"n"
>eatTable</span><span
class
=
"p"
>){</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>i</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>from</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>to</span><span
class
=
"p"
>;</span>
<span
class
=
"n"
>from</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateMoveFrom</span><span
class
=
"p"
>(</span><span
class
=
"n"
>move</span><span
class
=
"p"
>);</span>
<span
class
=
"n"
>to</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateMoveTo</span><span
class
=
"p"
>(</span><span
class
=
"n"
>move</span><span
class
=
"p"
>);</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span> <span
class
=
"o"
> <span
class
=
"n"
>eatCount</span><span
class
=
"p"
>;</span> <span
class
=
"n"
>i</span><span
class
=
"o"
>++</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>addPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"n"
>i</span><span
class
=
"p"
>]);</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"n"
>changePlayer</span><span
class
=
"p"
>();</span> <span
class
=
"c1"
>
<span
class
=
"n"
>delPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>to</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"n"
>addPiece</span><span
class
=
"p"
>(</span><span
class
=
"n"
>from</span><span
class
=
"p"
>);</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"nf"
>MinMaxSearch</span><span
class
=
"p"
>(</span><span
class
=
"kt"
>int</span> <span
class
=
"n"
>depth</span><span
class
=
"p"
>){</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>i</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>genCount</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>value</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>bestValue</span><span
class
=
"p"
>;</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>allMoves</span><span
class
=
"p"
>[</span><span
class
=
"n"
>MAX_GEN_MOVES</span><span
class
=
"p"
>];</span>
<span
class
=
"kt"
>int</span> <span
class
=
"n"
>eatCount</span><span
class
=
"p"
>,</span> <span
class
=
"n"
>eatTable</span><span
class
=
"p"
>[</span><span
class
=
"mi"
>2</span><span
class
=
"p"
>];</span> <span
class
=
"c1"
>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>depth</span> <span
class
=
"o"
>==</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>){</span>
<span
class
=
"k"
>
return
</span> <span
class
=
"n"
>evaluatePosition</span><span
class
=
"p"
>();</span>
<span
class
=
"p"
>}</span>
<span
class
=
"c1"
>
<span
class
=
"k"
>
if
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>currentPlayer</span><span
class
=
"p"
>){</span>
<span
class
=
"n"
>bestValue</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>INFINITY_VALUE</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span><span
class
=
"k"
>
else
</span><span
class
=
"p"
>{</span>
<span
class
=
"n"
>bestValue</span> <span
class
=
"o"
>=</span> <span
class
=
"o"
>-</span><span
class
=
"n"
>INFINITY_VALUE</span><span
class
=
"p"
>;</span> <span
class
=
"c1"
>
<span
class
=
"p"
>}</span>
<span
class
=
"n"
>genCount</span> <span
class
=
"o"
>=</span> <span
class
=
"n"
>generateAllMoves</span><span
class
=
"p"
>(</span><span
class
=
"n"
>allMoves</span><span
class
=
"p"
>);</span>
<span
class
=
"k"
>
for
</span><span
class
=
"p"
>(</span><span
class
=
"n"
>i</span> <span
class
=
"o"
>=</span> <span
class
=
"mi"
>0</span><span
class
=
"p"
>;</span></span></span></span></span></span></span></span></span></span></span></span></code>