Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Bitboards are fun :-)</p> <p>I am cooking up some code for this problem but here is something to get you started hopefully:</p> <pre><code>public class BitBoard { public static final int White = 0; public static final int Black = 1; public long[] board = { 0, 0 }; public int Player = 0; public int[] left = { 9, 9 }; public int Opponent() { return Player == White ? Black : White; } public void makemove(int from, int to, int capture) { if (from == 0) { assert left[Player] &gt; 0 : "makemove: no left"; left[Player]--; } if (from != 0) { assert (board[Player] &amp; from) != 0 : "makemove: source empty"; board[Player] &amp;= ~from; } assert (board[Player] &amp; to) == 0 : "makemove: target must be empty"; board[Player] |= to; if (capture != 0) { assert (board[Opponent()] &amp; capture) != 0 : "makemove: capture empty"; board[Opponent()] &amp;= ~capture; } } public void unmakemove(int from, int to, int capture) { if (capture != 0) { assert (board[Opponent()] &amp; capture) == 0 : "unmakemove: capture empty"; board[Opponent()] |= capture; } assert (board[Player] &amp; to) != 0 : "unmakemove: target empty"; board[Player] &amp;= ~to; if (from != 0) { assert (board[Opponent()] &amp; capture) != 0 : "unmakemove: source must be empty empty"; board[Player] |= from; } if (from == 0) { assert left[Player] &lt; 9 : "unmakemove: too many left"; left[Player]++; } } public void generatemoves() { // determine phase // } } </code></pre> <p>Didn't test this fully but following code shows how to use:</p> <pre><code>import java.math.*; public class NineMenBitboard { static int tst; // A B C D E F G // 1 0 1 2 // 2 3 4 5 // 3 6 7 8 // 4 9 10 11 12 13 14 // 5 15 16 17 // 6 18 19 20 // 7 21 22 23 // positions static int A1 = 1 &lt;&lt; 0; static int D1 = 1 &lt;&lt; 1; static int G1 = 1 &lt;&lt; 2; static int B2 = 1 &lt;&lt; 3; static int D2 = 1 &lt;&lt; 4; static int F2 = 1 &lt;&lt; 5; static int C3 = 1 &lt;&lt; 6; static int D3 = 1 &lt;&lt; 7; static int E3 = 1 &lt;&lt; 8; static int A4 = 1 &lt;&lt; 9; static int B4 = 1 &lt;&lt; 10; static int C4 = 1 &lt;&lt; 11; static int E4 = 1 &lt;&lt; 12; static int F4 = 1 &lt;&lt; 13; static int G4 = 1 &lt;&lt; 14; static int C5 = 1 &lt;&lt; 15; static int D5 = 1 &lt;&lt; 16; static int E5 = 1 &lt;&lt; 17; static int B6 = 1 &lt;&lt; 18; static int D6 = 1 &lt;&lt; 19; static int F6 = 1 &lt;&lt; 20; static int A7 = 1 &lt;&lt; 21; static int D7 = 1 &lt;&lt; 22; static int G7 = 1 &lt;&lt; 23; // mills static int hor1 = A1 | D1 | G1; static int hor2 = B2 | D2 | F2; static int hor3 = C3 | D3 | E3; static int hor4_1 = A4 | B4 | C4; static int hor4_2 = E4 | F4 | G4; static int hor5 = C5 | D5 | E5; static int hor6 = B6 | D6 | F6; static int hor7 = A7 | D7 | G7; static int ver1 = A1 | A4 | A7; static int ver2 = B2 | B4 | B6; static int ver3 = C3 | C4 | C5; static int ver4_1 = D1 | D2 | D3; static int ver4_2 = D5 | D6 | D7; static int ver5 = E3 | E4 | E5; static int ver6 = F2 | F4 | F6; static int ver7 = G1 | G4 | G7; public static void main(String[] args) { // sample on how to loop bits BitBoard game = new BitBoard(); game.makemove(0, A1, 0); game.makemove(A1, A4, 0); System.out.println(); tst = 255; for(int looper = tst, i = Integer.highestOneBit(looper); looper != 0; looper &amp;= ~i, i = Integer.highestOneBit(looper)) { System.out.println(i); } System.out.println(tst); } } </code></pre> <p>Also added a loop to show how you can loop through positions.</p> <p>Have fun. I'll be coding this game too since I want to refresh my AB pruning :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload