Showing content from https://tromp.github.io/c4/Connect4.java below:
// Fhourstones 3.0 Board Logic // Copyright 2000-2004 John Tromp import java.io.*; class Connect4 { static long color[]; // black and white bitboard static final int WIDTH = 7; static final int HEIGHT = 6; // bitmask corresponds to board as follows in 7x6 case: // . . . . . . . TOP // 5 12 19 26 33 40 47 // 4 11 18 25 32 39 46 // 3 10 17 24 31 38 45 // 2 9 16 23 30 37 44 // 1 8 15 22 29 36 43 // 0 7 14 21 28 35 42 BOTTOM static final int H1 = HEIGHT+1; static final int H2 = HEIGHT+2; static final int SIZE = HEIGHT*WIDTH; static final int SIZE1 = H1*WIDTH; static final long ALL1 = (1L< << HEIGHT; int moves[],nplies; byte height[]; // holds bit index of lowest free square public Connect4() { color = new long[2]; height = new byte[WIDTH]; moves = new int[SIZE]; reset(); } void reset() { nplies = 0; color[0] = color[1] = 0L; for (int i=0; i =0; h--) { for (int w=h; w >HEIGHT); if ((y & (y >> 2*HEIGHT)) != 0) // check diagonal \ return true; y = newboard & (newboard>>H1); if ((y & (y >> 2*H1)) != 0) // check horizontal - return true; y = newboard & (newboard>>H2); // check diagonal / if ((y & (y >> 2*H2)) != 0) return true; y = newboard & (newboard>>1); // check vertical | return (y & (y >> 2)) != 0; } void backmove() { int n; n = moves[--nplies]; color[nplies&1] ^= 1L<<--height[n]; } void makemove(int n) { color[nplies&1] ^= 1L< = 0 && col < WIDTH && c4.isplayable(col)) c4.makemove(col); } } } }
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4