mirror of
https://github.com/OMGeeky/hcsalmon1-Chess-Engine-Test.git
synced 2025-12-26 16:27:23 +01:00
Add files via upload
This commit is contained in:
74
Java/Bitboard.java
Normal file
74
Java/Bitboard.java
Normal file
@@ -0,0 +1,74 @@
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Bitboard
|
||||
{
|
||||
|
||||
public static BigInteger addBit(BigInteger bitboard, int square)
|
||||
{
|
||||
return bitboard.setBit(square);
|
||||
}
|
||||
|
||||
public static void printBigInteger(BigInteger bitboard)
|
||||
{
|
||||
for (int rank = 0; rank < 8; rank++)
|
||||
{
|
||||
for (int file = 0; file < 8; file++)
|
||||
{
|
||||
int square = rank * 8 + file;
|
||||
processSquare(bitboard, square);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("BigInteger: " + bitboard);
|
||||
}
|
||||
|
||||
static void processSquare(BigInteger bitboard, int square)
|
||||
{
|
||||
if (bitboard.testBit(square))
|
||||
{
|
||||
System.out.print("X ");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.print("_ ");
|
||||
}
|
||||
}
|
||||
|
||||
static int bitScanForwardSlow(BigInteger bitboard)
|
||||
{
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
if (bitboard.testBit(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void printLong(long input)
|
||||
{
|
||||
for (int rank = 0; rank < 8; rank++)
|
||||
{
|
||||
for (int file = 0; file < 8; file++)
|
||||
{
|
||||
int square = rank * 8 + file;
|
||||
processSquareLong(input, square);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("long: " + input);
|
||||
}
|
||||
|
||||
static void processSquareLong(long bitboard, int square)
|
||||
{
|
||||
if ((bitboard & MoveConstants.SQUARE_BBS[square]) != 0)
|
||||
{
|
||||
System.out.print("X ");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.print("_ ");
|
||||
}
|
||||
}
|
||||
}
|
||||
142
Java/Board.java
Normal file
142
Java/Board.java
Normal file
@@ -0,0 +1,142 @@
|
||||
|
||||
public class Board
|
||||
{
|
||||
public static long[] bitboard_array_global = new long[12];
|
||||
public static boolean is_white_global = true;
|
||||
public static boolean[] castle_rights_global = new boolean[4];
|
||||
public static int ep_global;
|
||||
|
||||
static final long BP_STARTING_POSITIONS = 65280L;
|
||||
static final long WP_STARTING_POSITIONS = 71776119061217280L;
|
||||
static final long BK_STARTING_POSITION = 16L;
|
||||
static final long WK_STARTING_POSITION = 1152921504606846976L;
|
||||
static final long BN_STARTING_POSITIONS = 66L;
|
||||
static final long WN_STARTING_POSITIONS = 4755801206503243776L;
|
||||
static final long WR_STARTING_POSITIONS = Long.parseUnsignedLong("9295429630892703744");
|
||||
static final long BR_STARTING_POSITIONS = 129L;
|
||||
static final long BB_STARTING_POSITIONS = 36L;
|
||||
static final long WB_STARTING_POSITIONS = 2594073385365405696L;
|
||||
static final long WQ_STARTING_POSITION = 576460752303423488L;
|
||||
static final long BQ_STARTING_POSITION = 8L;
|
||||
|
||||
|
||||
public static void SetTrickyPosition() {
|
||||
|
||||
ep_global = GenConst.NO_SQUARE;
|
||||
is_white_global = true;
|
||||
castle_rights_global[0] = true;
|
||||
castle_rights_global[1] = true;
|
||||
castle_rights_global[2] = true;
|
||||
castle_rights_global[3] = true;
|
||||
|
||||
bitboard_array_global[GenConst.WP] = 65020788473856000L;
|
||||
bitboard_array_global[GenConst.WN] = 4398314946560L;
|
||||
bitboard_array_global[GenConst.WB] = 6755399441055744L;
|
||||
bitboard_array_global[GenConst.WR] = Long.parseUnsignedLong("9295429630892703744L");
|
||||
bitboard_array_global[GenConst.WQ] = 35184372088832L;
|
||||
bitboard_array_global[GenConst.WK] = 1152921504606846976L;
|
||||
bitboard_array_global[GenConst.BP] = 140746083544320L;
|
||||
bitboard_array_global[GenConst.BN] = 2228224L;
|
||||
bitboard_array_global[GenConst.BB] = 81920L;
|
||||
bitboard_array_global[GenConst.BR] = 129L;
|
||||
bitboard_array_global[GenConst.BQ] = 4096L;
|
||||
bitboard_array_global[GenConst.BK] = 16L;
|
||||
}
|
||||
|
||||
public static void setTestPosition()
|
||||
{
|
||||
ep_global = GenConst.NO_SQUARE;
|
||||
is_white_global = false;
|
||||
castle_rights_global[0] = false;
|
||||
castle_rights_global[1] = false;
|
||||
castle_rights_global[2] = false;
|
||||
castle_rights_global[3] = false;
|
||||
|
||||
bitboard_array_global[GenConst.WP] = 33554432L;
|
||||
bitboard_array_global[GenConst.WN] = 0;
|
||||
bitboard_array_global[GenConst.WB] = 0;
|
||||
bitboard_array_global[GenConst.WR] = 0;
|
||||
bitboard_array_global[GenConst.WQ] = 0;
|
||||
bitboard_array_global[GenConst.WK] = 4398046511104L;
|
||||
bitboard_array_global[GenConst.BP] = 0;
|
||||
bitboard_array_global[GenConst.BN] = 0;
|
||||
bitboard_array_global[GenConst.BB] = 0;
|
||||
bitboard_array_global[GenConst.BR] = 0;
|
||||
bitboard_array_global[GenConst.BQ] = 0;
|
||||
bitboard_array_global[GenConst.BK] = 2048L;
|
||||
}
|
||||
|
||||
public static void setStartingPosition() {
|
||||
|
||||
ep_global = GenConst.NO_SQUARE;
|
||||
is_white_global = true;
|
||||
castle_rights_global[0] = true;
|
||||
castle_rights_global[1] = true;
|
||||
castle_rights_global[2] = true;
|
||||
castle_rights_global[3] = true;
|
||||
|
||||
bitboard_array_global[GenConst.WP] = WP_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.WN] = WN_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.WB] = WB_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.WR] = WR_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.WQ] = WQ_STARTING_POSITION;
|
||||
bitboard_array_global[GenConst.WK] = WK_STARTING_POSITION;
|
||||
bitboard_array_global[GenConst.BP] = BP_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.BN] = BN_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.BB] = BB_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.BR] = BR_STARTING_POSITIONS;
|
||||
bitboard_array_global[GenConst.BQ] = BQ_STARTING_POSITION;
|
||||
bitboard_array_global[GenConst.BK] = BK_STARTING_POSITION;
|
||||
}
|
||||
|
||||
static final char[] PieceNames = {'P', 'N', 'B', 'R', 'Q', 'K', 'P', 'N', 'B', 'R', 'Q', 'K', '_'};
|
||||
static final char[] PieceColours = {'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', '_'};
|
||||
|
||||
static final int EMPTY = 12;
|
||||
|
||||
//static boolean IsOccupied(long bitboard, int square) {
|
||||
// return !bitboard.and(MoveConstants.SQUARE_BBS[square]).equals(long.ZERO);
|
||||
//}
|
||||
|
||||
static int GetOccupiedIndex(int square) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (true) {//(IsOccupied(bitboard_array_global[i], square)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
static int[] fillBoardArray() {
|
||||
int[] boardArray = new int[64];
|
||||
for (int i = 0; i < 64; i++) {
|
||||
boardArray[i] = GetOccupiedIndex(i);
|
||||
}
|
||||
return boardArray;
|
||||
}
|
||||
|
||||
public static void printBoard() {
|
||||
System.out.println("Board:");
|
||||
|
||||
int[] boardArray = fillBoardArray();
|
||||
|
||||
for (int rank = 0; rank < 8; rank++) {
|
||||
System.out.print(" ");
|
||||
|
||||
for (int file = 0; file < 8; file++) {
|
||||
int square = (rank * 8) + file;
|
||||
System.out.printf("%c%c ", PieceColours[boardArray[square]], PieceNames[boardArray[square]]);
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
System.out.printf("White to play: %b\n", is_white_global);
|
||||
System.out.printf("Castle: %b %b %b %b\n", castle_rights_global[0], castle_rights_global[1], castle_rights_global[2], castle_rights_global[3]);
|
||||
System.out.printf("ep: %d\n", ep_global);
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
12
Java/ChessEngine.java
Normal file
12
Java/ChessEngine.java
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
public class ChessEngine
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Board.setStartingPosition();
|
||||
//Board.setTestPosition();
|
||||
Perft.PrintBoardGlobal();
|
||||
//Perft.runPerftFunctionsDebug(6);
|
||||
Perft.runPerftFunctions(6);
|
||||
}
|
||||
}
|
||||
152
Java/GenConst.java
Normal file
152
Java/GenConst.java
Normal file
@@ -0,0 +1,152 @@
|
||||
public class GenConst {
|
||||
public static final int WP = 0;
|
||||
public static final int WN = 1;
|
||||
public static final int WB = 2;
|
||||
public static final int WR = 3;
|
||||
public static final int WQ = 4;
|
||||
public static final int WK = 5;
|
||||
public static final int BP = 6;
|
||||
public static final int BN = 7;
|
||||
public static final int BB = 8;
|
||||
public static final int BR = 9;
|
||||
public static final int BQ = 10;
|
||||
public static final int BK = 11;
|
||||
public static final int EMPTY = 12;
|
||||
|
||||
public static final long RANK_1_BITBOARD = Long.parseUnsignedLong("18374686479671623680");
|
||||
public static final long RANK_2_BITBOARD = 71776119061217280L;
|
||||
public static final long RANK_3_BITBOARD = 280375465082880L;
|
||||
public static final long RANK_4_BITBOARD = 1095216660480L;
|
||||
public static final long RANK_5_BITBOARD = 4278190080L;
|
||||
public static final long RANK_6_BITBOARD = 16711680L;
|
||||
public static final long RANK_7_BITBOARD = 65280L;
|
||||
public static final long RANK_8_BITBOARD = 255L;
|
||||
|
||||
public static final long WKS_EMPTY_BITBOARD = 6917529027641081856L;
|
||||
public static final long WQS_EMPTY_BITBOARD = 1008806316530991104L;
|
||||
public static final long BKS_EMPTY_BITBOARD = 96L;
|
||||
public static final long BQS_EMPTY_BITBOARD = 14L;
|
||||
|
||||
public static final long MAX_ULONG = Long.parseUnsignedLong("18446744073709551615");
|
||||
|
||||
public static final int TAG_NONE = 0;
|
||||
public static final int TAG_CAPTURE = 1;
|
||||
public static final int TAG_WHITE_EP = 2;
|
||||
public static final int TAG_BLACK_EP = 3;
|
||||
public static final int TAG_W_CASTLE_KS = 4;
|
||||
public static final int TAG_W_CASTLE_QS = 5;
|
||||
public static final int TAG_B_CASTLE_KS = 6;
|
||||
public static final int TAG_B_CASTLE_QS = 7;
|
||||
public static final int TAG_B_N_PROMOTION = 8;
|
||||
public static final int TAG_B_B_PROMOTION = 9;
|
||||
public static final int TAG_B_Q_PROMOTION = 10;
|
||||
public static final int TAG_B_R_PROMOTION = 11;
|
||||
public static final int TAG_W_N_PROMOTION = 12;
|
||||
public static final int TAG_W_B_PROMOTION = 13;
|
||||
public static final int TAG_W_Q_PROMOTION = 14;
|
||||
public static final int TAG_W_R_PROMOTION = 15;
|
||||
public static final int TAG_B_N_PROMOTION_CAP = 16;
|
||||
public static final int TAG_B_B_PROMOTION_CAP = 17;
|
||||
public static final int TAG_B_Q_PROMOTION_CAP = 18;
|
||||
public static final int TAG_B_R_PROMOTION_CAP = 19;
|
||||
public static final int TAG_W_N_PROMOTION_CAP = 20;
|
||||
public static final int TAG_W_B_PROMOTION_CAP = 21;
|
||||
public static final int TAG_W_Q_PROMOTION_CAP = 22;
|
||||
public static final int TAG_W_R_PROMOTION_CAP = 23;
|
||||
public static final int TAG_W_P_DOUBLE = 24;
|
||||
public static final int TAG_B_P_DOUBLE = 25;
|
||||
public static final int TAG_CHECK = 26;
|
||||
public static final int TAG_CHECK_CAP = 27;
|
||||
|
||||
public static final int A8 = 0;
|
||||
public static final int B8 = 1;
|
||||
public static final int C8 = 2;
|
||||
public static final int D8 = 3;
|
||||
public static final int E8 = 4;
|
||||
public static final int F8 = 5;
|
||||
public static final int G8 = 6;
|
||||
public static final int H8 = 7;
|
||||
public static final int A7 = 8;
|
||||
public static final int B7 = 9;
|
||||
public static final int C7 = 10;
|
||||
public static final int D7 = 11;
|
||||
public static final int E7 = 12;
|
||||
public static final int F7 = 13;
|
||||
public static final int G7 = 14;
|
||||
public static final int H7 = 15;
|
||||
public static final int A6 = 16;
|
||||
public static final int B6 = 17;
|
||||
public static final int C6 = 18;
|
||||
public static final int D6 = 19;
|
||||
public static final int E6 = 20;
|
||||
public static final int F6 = 21;
|
||||
public static final int G6 = 22;
|
||||
public static final int H6 = 23;
|
||||
public static final int A5 = 24;
|
||||
public static final int B5 = 25;
|
||||
public static final int C5 = 26;
|
||||
public static final int D5 = 27;
|
||||
public static final int E5 = 28;
|
||||
public static final int F5 = 29;
|
||||
public static final int G5 = 30;
|
||||
public static final int H5 = 31;
|
||||
public static final int A4 = 32;
|
||||
public static final int B4 = 33;
|
||||
public static final int C4 = 34;
|
||||
public static final int D4 = 35;
|
||||
public static final int E4 = 36;
|
||||
public static final int F4 = 37;
|
||||
public static final int G4 = 38;
|
||||
public static final int H4 = 39;
|
||||
public static final int A3 = 40;
|
||||
public static final int B3 = 41;
|
||||
public static final int C3 = 42;
|
||||
public static final int D3 = 43;
|
||||
public static final int E3 = 44;
|
||||
public static final int F3 = 45;
|
||||
public static final int G3 = 46;
|
||||
public static final int H3 = 47;
|
||||
public static final int A2 = 48;
|
||||
public static final int B2 = 49;
|
||||
public static final int C2 = 50;
|
||||
public static final int D2 = 51;
|
||||
public static final int E2 = 52;
|
||||
public static final int F2 = 53;
|
||||
public static final int G2 = 54;
|
||||
public static final int H2 = 55;
|
||||
public static final int A1 = 56;
|
||||
public static final int B1 = 57;
|
||||
public static final int C1 = 58;
|
||||
public static final int D1 = 59;
|
||||
public static final int E1 = 60;
|
||||
public static final int F1 = 61;
|
||||
public static final int G1 = 62;
|
||||
public static final int H1 = 63;
|
||||
|
||||
public static final int NO_SQUARE = 64;
|
||||
|
||||
static char[] SQ_CHAR_Y = {
|
||||
'8', '8', '8', '8', '8', '8', '8', '8',
|
||||
'7', '7', '7', '7', '7', '7', '7', '7',
|
||||
'6', '6', '6', '6', '6', '6', '6', '6',
|
||||
'5', '5', '5', '5', '5', '5', '5', '5',
|
||||
'4', '4', '4', '4', '4', '4', '4', '4',
|
||||
'3', '3', '3', '3', '3', '3', '3', '3',
|
||||
'2', '2', '2', '2', '2', '2', '2', '2',
|
||||
'1', '1', '1', '1', '1', '1', '1', '1',
|
||||
'A' // This seems like an extra value; ensure it is intentional
|
||||
};
|
||||
|
||||
static char[] SQ_CHAR_X = {
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'N' // This seems like an extra value; ensure it is intentional
|
||||
};
|
||||
|
||||
}
|
||||
4230
Java/Inb.java
Normal file
4230
Java/Inb.java
Normal file
File diff suppressed because it is too large
Load Diff
878
Java/MoveConstants.java
Normal file
878
Java/MoveConstants.java
Normal file
@@ -0,0 +1,878 @@
|
||||
|
||||
|
||||
public class MoveConstants {
|
||||
|
||||
//#region
|
||||
|
||||
|
||||
public static final long[] KNIGHT_ATTACKS =
|
||||
{
|
||||
132096,
|
||||
329728,
|
||||
659712,
|
||||
1319424,
|
||||
2638848,
|
||||
5277696,
|
||||
10489856,
|
||||
4202496,
|
||||
33816580,
|
||||
84410376,
|
||||
168886289,
|
||||
337772578,
|
||||
675545156,
|
||||
1351090312L,
|
||||
2685403152L,
|
||||
1075839008L,
|
||||
8657044482L,
|
||||
21609056261L,
|
||||
43234889994L,
|
||||
86469779988L,
|
||||
172939559976L,
|
||||
345879119952L,
|
||||
687463207072L,
|
||||
275414786112L,
|
||||
2216203387392L,
|
||||
5531918402816L,
|
||||
11068131838464L,
|
||||
22136263676928L,
|
||||
44272527353856L,
|
||||
88545054707712L,
|
||||
175990581010432L,
|
||||
70506185244672L,
|
||||
567348067172352L,
|
||||
1416171111120896L,
|
||||
2833441750646784L,
|
||||
5666883501293568L,
|
||||
11333767002587136L,
|
||||
22667534005174272L,
|
||||
45053588738670592L,
|
||||
18049583422636032L,
|
||||
145241105196122112L,
|
||||
362539804446949376L,
|
||||
725361088165576704L,
|
||||
1450722176331153408L,
|
||||
2901444352662306816L,
|
||||
5802888705324613632L,
|
||||
Long.parseUnsignedLong("11533718717099671552"),
|
||||
4620693356194824192L,
|
||||
288234782788157440L,
|
||||
576469569871282176L,
|
||||
1224997833292120064L,
|
||||
2449995666584240128L,
|
||||
4899991333168480256L,
|
||||
Long.parseUnsignedLong("9799982666336960512"),
|
||||
1152939783987658752L,
|
||||
2305878468463689728L,
|
||||
1128098930098176L,
|
||||
2257297371824128L,
|
||||
4796069720358912L,
|
||||
9592139440717824L,
|
||||
19184278881435648L,
|
||||
38368557762871296L,
|
||||
4679521487814656L,
|
||||
9077567998918656L,
|
||||
};
|
||||
public static final long[][] BISHOP_ATTACKS = {
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
0,
|
||||
256,
|
||||
513,
|
||||
1026,
|
||||
2052,
|
||||
4104,
|
||||
8208,
|
||||
16416,
|
||||
0,
|
||||
65536,
|
||||
131328,
|
||||
262657,
|
||||
525314,
|
||||
1050628,
|
||||
2101256,
|
||||
4202512,
|
||||
0,
|
||||
16777216,
|
||||
33619968,
|
||||
67240192,
|
||||
134480385,
|
||||
268960770,
|
||||
537921540,
|
||||
1075843080L,
|
||||
0,
|
||||
4294967296L,
|
||||
8606711808L,
|
||||
17213489152L,
|
||||
34426978560L,
|
||||
68853957121L,
|
||||
137707914242L,
|
||||
275415828484L,
|
||||
0,
|
||||
1099511627776L,
|
||||
2203318222848L,
|
||||
4406653222912L,
|
||||
8813306511360L,
|
||||
17626613022976L,
|
||||
35253226045953L,
|
||||
70506452091906L,
|
||||
0,
|
||||
281474976710656L,
|
||||
564049465049088L,
|
||||
1128103225065472L,
|
||||
2256206466908160L,
|
||||
4512412933881856L,
|
||||
9024825867763968L,
|
||||
18049651735527937L,
|
||||
},
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
128,
|
||||
0,
|
||||
516,
|
||||
1032,
|
||||
2064,
|
||||
4128,
|
||||
8256,
|
||||
16512,
|
||||
32768,
|
||||
0,
|
||||
132104,
|
||||
264208,
|
||||
528416,
|
||||
1056832,
|
||||
2113664,
|
||||
4227072,
|
||||
8388608,
|
||||
0,
|
||||
33818640,
|
||||
67637280,
|
||||
135274560,
|
||||
270549120,
|
||||
541097984,
|
||||
1082130432L,
|
||||
2147483648L,
|
||||
0,
|
||||
8657571872L,
|
||||
17315143744L,
|
||||
34630287488L,
|
||||
69260574720L,
|
||||
138521083904L,
|
||||
277025390592L,
|
||||
549755813888L,
|
||||
0,
|
||||
2216338399296L,
|
||||
4432676798592L,
|
||||
8865353596928L,
|
||||
17730707128320L,
|
||||
35461397479424L,
|
||||
70918499991552L,
|
||||
140737488355328L,
|
||||
0,
|
||||
567382630219904L,
|
||||
1134765260439552L,
|
||||
2269530520813568L,
|
||||
4539061024849920L,
|
||||
9078117754732544L,
|
||||
18155135997837312L,
|
||||
36028797018963968L,
|
||||
0,
|
||||
},
|
||||
{
|
||||
0,
|
||||
256,
|
||||
66048,
|
||||
16909312,
|
||||
4328785920L,
|
||||
1108169199616L,
|
||||
283691315109888L,
|
||||
72624976668147712L,
|
||||
0,
|
||||
65536,
|
||||
16908288,
|
||||
4328783872L,
|
||||
1108169195520L,
|
||||
283691315101696L,
|
||||
72624976668131328L,
|
||||
145249953336262656L,
|
||||
0,
|
||||
16777216,
|
||||
4328521728L,
|
||||
1108168671232L,
|
||||
283691314053120L,
|
||||
72624976666034176L,
|
||||
145249953332068352L,
|
||||
290499906664136704L,
|
||||
0,
|
||||
4294967296L,
|
||||
1108101562368L,
|
||||
283691179835392L,
|
||||
72624976397598720L,
|
||||
145249952795197440L,
|
||||
290499905590394880L,
|
||||
580999811180789760L,
|
||||
0,
|
||||
1099511627776L,
|
||||
283673999966208L,
|
||||
72624942037860352L,
|
||||
145249884075720704L,
|
||||
290499768151441408L,
|
||||
580999536302882816L,
|
||||
1161999072605765632L,
|
||||
0,
|
||||
281474976710656L,
|
||||
72620543991349248L,
|
||||
145241087982698496L,
|
||||
290482175965396992L,
|
||||
580964351930793984L,
|
||||
1161928703861587968L,
|
||||
2323857407723175936L,
|
||||
0,
|
||||
72057594037927936L,
|
||||
144115188075855872L,
|
||||
288230376151711744L,
|
||||
576460752303423488L,
|
||||
1152921504606846976L,
|
||||
2305843009213693952L,
|
||||
4611686018427387904L,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
},
|
||||
{
|
||||
Long.parseUnsignedLong("9241421688590303744"),
|
||||
36099303471055872L,
|
||||
141012904183808L,
|
||||
550831656960L,
|
||||
2151686144L,
|
||||
8404992,
|
||||
32768,
|
||||
0,
|
||||
4620710844295151616L,
|
||||
Long.parseUnsignedLong("9241421688590303232"),
|
||||
36099303471054848L,
|
||||
141012904181760L,
|
||||
550831652864L,
|
||||
2151677952L,
|
||||
8388608,
|
||||
0,
|
||||
2310355422147510272L,
|
||||
4620710844295020544L,
|
||||
Long.parseUnsignedLong("9241421688590041088"),
|
||||
36099303470530560L,
|
||||
141012903133184L,
|
||||
550829555712L,
|
||||
2147483648L,
|
||||
0,
|
||||
1155177711056977920L,
|
||||
2310355422113955840L,
|
||||
4620710844227911680L,
|
||||
Long.parseUnsignedLong("9241421688455823360"),
|
||||
36099303202095104L,
|
||||
141012366262272L,
|
||||
549755813888L,
|
||||
0,
|
||||
577588851233521664L,
|
||||
1155177702467043328L,
|
||||
2310355404934086656L,
|
||||
4620710809868173312L,
|
||||
Long.parseUnsignedLong("9241421619736346624"),
|
||||
36099165763141632L,
|
||||
140737488355328L,
|
||||
0,
|
||||
288793326105133056L,
|
||||
577586652210266112L,
|
||||
1155173304420532224L,
|
||||
2310346608841064448L,
|
||||
4620693217682128896L,
|
||||
Long.parseUnsignedLong("9241386435364257792"),
|
||||
36028797018963968L,
|
||||
0,
|
||||
144115188075855872L,
|
||||
288230376151711744L,
|
||||
576460752303423488L,
|
||||
1152921504606846976L,
|
||||
2305843009213693952L,
|
||||
4611686018427387904L,
|
||||
Long.parseUnsignedLong("9223372036854775808"),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
},
|
||||
};
|
||||
public static final long[][] ROOK_ATTACKS = {
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
128,
|
||||
257,
|
||||
514,
|
||||
1028,
|
||||
2056,
|
||||
4112,
|
||||
8224,
|
||||
16448,
|
||||
32896,
|
||||
65793,
|
||||
131586,
|
||||
263172,
|
||||
526344,
|
||||
1052688,
|
||||
2105376,
|
||||
4210752,
|
||||
8421504,
|
||||
16843009,
|
||||
33686018,
|
||||
67372036,
|
||||
134744072,
|
||||
269488144,
|
||||
538976288,
|
||||
1077952576L,
|
||||
2155905152L,
|
||||
4311810305L,
|
||||
8623620610L,
|
||||
17247241220L,
|
||||
34494482440L,
|
||||
68988964880L,
|
||||
137977929760L,
|
||||
275955859520L,
|
||||
551911719040L,
|
||||
1103823438081L,
|
||||
2207646876162L,
|
||||
4415293752324L,
|
||||
8830587504648L,
|
||||
17661175009296L,
|
||||
35322350018592L,
|
||||
70644700037184L,
|
||||
141289400074368L,
|
||||
282578800148737L,
|
||||
565157600297474L,
|
||||
1130315200594948L,
|
||||
2260630401189896L,
|
||||
4521260802379792L,
|
||||
9042521604759584L,
|
||||
18085043209519168L,
|
||||
36170086419038336L
|
||||
},
|
||||
{
|
||||
254,
|
||||
252,
|
||||
248,
|
||||
240,
|
||||
224,
|
||||
192,
|
||||
128,
|
||||
0,
|
||||
65024,
|
||||
64512,
|
||||
63488,
|
||||
61440,
|
||||
57344,
|
||||
49152,
|
||||
32768,
|
||||
0,
|
||||
16646144,
|
||||
16515072,
|
||||
16252928,
|
||||
15728640,
|
||||
14680064,
|
||||
12582912,
|
||||
8388608,
|
||||
0,
|
||||
4261412864L,
|
||||
4227858432L,
|
||||
4160749568L,
|
||||
4026531840L,
|
||||
3758096384L,
|
||||
3221225472L,
|
||||
2147483648L,
|
||||
0,
|
||||
1090921693184L,
|
||||
1082331758592L,
|
||||
1065151889408L,
|
||||
1030792151040L,
|
||||
962072674304L,
|
||||
824633720832L,
|
||||
549755813888L,
|
||||
0,
|
||||
279275953455104L,
|
||||
277076930199552L,
|
||||
272678883688448L,
|
||||
263882790666240L,
|
||||
246290604621824L,
|
||||
211106232532992L,
|
||||
140737488355328L,
|
||||
0,
|
||||
71494644084506624L,
|
||||
70931694131085312L,
|
||||
69805794224242688L,
|
||||
67553994410557440L,
|
||||
63050394783186944L,
|
||||
54043195528445952L,
|
||||
36028797018963968L,
|
||||
0,
|
||||
Long.parseUnsignedLong("18302628885633695744"),
|
||||
Long.parseUnsignedLong("18158513697557839872"),
|
||||
Long.parseUnsignedLong("17870283321406128128"),
|
||||
Long.parseUnsignedLong("17293822569102704640"),
|
||||
Long.parseUnsignedLong("16140901064495857664"),
|
||||
Long.parseUnsignedLong("13835058055282163712"),
|
||||
Long.parseUnsignedLong("9223372036854775808"),
|
||||
0
|
||||
},
|
||||
{
|
||||
72340172838076672L,
|
||||
144680345676153344L,
|
||||
289360691352306688L,
|
||||
578721382704613376L,
|
||||
1157442765409226752L,
|
||||
2314885530818453504L,
|
||||
4629771061636907008L,
|
||||
Long.parseUnsignedLong("9259542123273814016"),
|
||||
72340172838076416L,
|
||||
144680345676152832L,
|
||||
289360691352305664L,
|
||||
578721382704611328L,
|
||||
1157442765409222656L,
|
||||
2314885530818445312L,
|
||||
4629771061636890624L,
|
||||
Long.parseUnsignedLong("9259542123273781248"),
|
||||
72340172838010880L,
|
||||
144680345676021760L,
|
||||
289360691352043520L,
|
||||
578721382704087040L,
|
||||
1157442765408174080L,
|
||||
2314885530816348160L,
|
||||
4629771061632696320L,
|
||||
Long.parseUnsignedLong("9259542123265392640"),
|
||||
72340172821233664L,
|
||||
144680345642467328L,
|
||||
289360691284934656L,
|
||||
578721382569869312L,
|
||||
1157442765139738624L,
|
||||
2314885530279477248L,
|
||||
4629771060558954496L,
|
||||
Long.parseUnsignedLong("9259542121117908992"),
|
||||
72340168526266368L,
|
||||
144680337052532736L,
|
||||
289360674105065472L,
|
||||
578721348210130944L,
|
||||
1157442696420261888L,
|
||||
2314885392840523776L,
|
||||
4629770785681047552L,
|
||||
Long.parseUnsignedLong("9259541571362095104"),
|
||||
72339069014638592L,
|
||||
144678138029277184L,
|
||||
289356276058554368L,
|
||||
578712552117108736L,
|
||||
1157425104234217472L,
|
||||
2314850208468434944L,
|
||||
4629700416936869888L,
|
||||
Long.parseUnsignedLong("9259400833873739776"),
|
||||
72057594037927936L,
|
||||
144115188075855872L,
|
||||
288230376151711744L,
|
||||
576460752303423488L,
|
||||
1152921504606846976L,
|
||||
2305843009213693952L,
|
||||
4611686018427387904L,
|
||||
Long.parseUnsignedLong("9223372036854775808"),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
},
|
||||
{
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
7,
|
||||
15,
|
||||
31,
|
||||
63,
|
||||
127,
|
||||
0,
|
||||
256,
|
||||
768,
|
||||
1792,
|
||||
3840,
|
||||
7936,
|
||||
16128,
|
||||
32512,
|
||||
0,
|
||||
65536,
|
||||
196608,
|
||||
458752,
|
||||
983040,
|
||||
2031616,
|
||||
4128768,
|
||||
8323072,
|
||||
0,
|
||||
16777216,
|
||||
50331648,
|
||||
117440512,
|
||||
251658240,
|
||||
520093696,
|
||||
1056964608L,
|
||||
2130706432L,
|
||||
0,
|
||||
4294967296L,
|
||||
12884901888L,
|
||||
30064771072L,
|
||||
64424509440L,
|
||||
133143986176L,
|
||||
270582939648L,
|
||||
545460846592L,
|
||||
0,
|
||||
1099511627776L,
|
||||
3298534883328L,
|
||||
7696581394432L,
|
||||
16492674416640L,
|
||||
34084860461056L,
|
||||
69269232549888L,
|
||||
139637976727552L,
|
||||
0,
|
||||
281474976710656L,
|
||||
844424930131968L,
|
||||
1970324836974592L,
|
||||
4222124650659840L,
|
||||
8725724278030336L,
|
||||
17732923532771328L,
|
||||
35747322042253312L,
|
||||
0,
|
||||
72057594037927936L,
|
||||
216172782113783808L,
|
||||
504403158265495552L,
|
||||
1080863910568919040L,
|
||||
2233785415175766016L,
|
||||
4539628424389459968L,
|
||||
9151314442816847872L
|
||||
}
|
||||
};
|
||||
|
||||
public static final long[] WHITE_PAWN_ATTACKS = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
5,
|
||||
10,
|
||||
20,
|
||||
40,
|
||||
80,
|
||||
160,
|
||||
64,
|
||||
512,
|
||||
1280,
|
||||
2560,
|
||||
5120,
|
||||
10240,
|
||||
20480,
|
||||
40960,
|
||||
16384,
|
||||
131072,
|
||||
327680,
|
||||
655360,
|
||||
1310720,
|
||||
2621440,
|
||||
5242880,
|
||||
10485760,
|
||||
4194304,
|
||||
33554432,
|
||||
83886080,
|
||||
167772160L,
|
||||
335544320L,
|
||||
671088640L,
|
||||
1342177280L,
|
||||
2684354560L,
|
||||
1073741824L,
|
||||
8589934592L,
|
||||
21474836480L,
|
||||
42949672960L,
|
||||
85899345920L,
|
||||
171798691840L,
|
||||
343597383680L,
|
||||
687194767360L,
|
||||
274877906944L,
|
||||
2199023255552L,
|
||||
5497558138880L,
|
||||
10995116277760L,
|
||||
21990232555520L,
|
||||
43980465111040L,
|
||||
87960930222080L,
|
||||
175921860444160L,
|
||||
70368744177664L,
|
||||
562949953421312L,
|
||||
1407374883553280L,
|
||||
2814749767106560L,
|
||||
5629499534213120L,
|
||||
11258999068426240L,
|
||||
22517998136852480L,
|
||||
45035996273704960L,
|
||||
18014398509481984L
|
||||
};
|
||||
public static final long[] BLACK_PAWN_ATTACKS = {
|
||||
512,
|
||||
1280,
|
||||
2560,
|
||||
5120,
|
||||
10240,
|
||||
20480,
|
||||
40960,
|
||||
16384,
|
||||
131072,
|
||||
327680,
|
||||
655360,
|
||||
1310720,
|
||||
2621440,
|
||||
5242880,
|
||||
10485760,
|
||||
4194304,
|
||||
33554432,
|
||||
83886080,
|
||||
167772160,
|
||||
335544320,
|
||||
671088640,
|
||||
1342177280,
|
||||
2684354560L,
|
||||
1073741824,
|
||||
8589934592L,
|
||||
21474836480L,
|
||||
42949672960L,
|
||||
85899345920L,
|
||||
171798691840L,
|
||||
343597383680L,
|
||||
687194767360L,
|
||||
274877906944L,
|
||||
2199023255552L,
|
||||
5497558138880L,
|
||||
10995116277760L,
|
||||
21990232555520L,
|
||||
43980465111040L,
|
||||
87960930222080L,
|
||||
175921860444160L,
|
||||
70368744177664L,
|
||||
562949953421312L,
|
||||
1407374883553280L,
|
||||
2814749767106560L,
|
||||
5629499534213120L,
|
||||
11258999068426240L,
|
||||
22517998136852480L,
|
||||
45035996273704960L,
|
||||
18014398509481984L,
|
||||
144115188075855872L,
|
||||
360287970189639680L,
|
||||
720575940379279360L,
|
||||
1441151880758558720L,
|
||||
2882303761517117440L,
|
||||
5764607523034234880L,
|
||||
Long.parseUnsignedLong("11529215046068469760"),
|
||||
4611686018427387904L,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
public static final long[] KING_ATTACKS = {
|
||||
770,
|
||||
1797,
|
||||
3594,
|
||||
7188,
|
||||
14376,
|
||||
28752,
|
||||
57504,
|
||||
49216,
|
||||
197123,
|
||||
460039,
|
||||
920078,
|
||||
1840156,
|
||||
3680312,
|
||||
7360624,
|
||||
14721248,
|
||||
12599488,
|
||||
50463488,
|
||||
117769984,
|
||||
235539968,
|
||||
471079936,
|
||||
942159872,
|
||||
1884319744L,
|
||||
3768639488L,
|
||||
3225468928L,
|
||||
12918652928L,
|
||||
30149115904L,
|
||||
60298231808L,
|
||||
120596463616L,
|
||||
241192927232L,
|
||||
482385854464L,
|
||||
964771708928L,
|
||||
825720045568L,
|
||||
3307175149568L,
|
||||
7718173671424L,
|
||||
15436347342848L,
|
||||
30872694685696L,
|
||||
61745389371392L,
|
||||
123490778742784L,
|
||||
246981557485568L,
|
||||
211384331665408L,
|
||||
846636838289408L,
|
||||
1975852459884544L,
|
||||
3951704919769088L,
|
||||
7903409839538176L,
|
||||
15806819679076352L,
|
||||
31613639358152704L,
|
||||
63227278716305408L,
|
||||
54114388906344448L,
|
||||
216739030602088448L,
|
||||
505818229730443264L,
|
||||
1011636459460886528L,
|
||||
2023272918921773056L,
|
||||
4046545837843546112L,
|
||||
8093091675687092224L,
|
||||
Long.parseUnsignedLong("16186183351374184448"),
|
||||
Long.parseUnsignedLong("13853283560024178688"),
|
||||
144959613005987840L,
|
||||
362258295026614272L,
|
||||
724516590053228544L,
|
||||
1449033180106457088L,
|
||||
2898066360212914176L,
|
||||
5796132720425828352L,
|
||||
Long.parseUnsignedLong("11592265440851656704"),
|
||||
Long.parseUnsignedLong("4665729213955833856")
|
||||
};
|
||||
|
||||
public static final long[] SQUARE_BBS = {
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
16,
|
||||
32,
|
||||
64,
|
||||
128,
|
||||
256,
|
||||
512,
|
||||
1024,
|
||||
2048,
|
||||
4096,
|
||||
8192,
|
||||
16384,
|
||||
32768,
|
||||
65536,
|
||||
131072,
|
||||
262144,
|
||||
524288,
|
||||
1048576,
|
||||
2097152,
|
||||
4194304,
|
||||
8388608,
|
||||
16777216,
|
||||
33554432,
|
||||
67108864,
|
||||
134217728,
|
||||
268435456,
|
||||
536870912,
|
||||
1073741824L,
|
||||
2147483648L,
|
||||
4294967296L,
|
||||
8589934592L,
|
||||
17179869184L,
|
||||
34359738368L,
|
||||
68719476736L,
|
||||
137438953472L,
|
||||
274877906944L,
|
||||
549755813888L,
|
||||
1099511627776L,
|
||||
2199023255552L,
|
||||
4398046511104L,
|
||||
8796093022208L,
|
||||
17592186044416L,
|
||||
35184372088832L,
|
||||
70368744177664L,
|
||||
140737488355328L,
|
||||
281474976710656L,
|
||||
562949953421312L,
|
||||
1125899906842624L,
|
||||
2251799813685248L,
|
||||
4503599627370496L,
|
||||
9007199254740992L,
|
||||
18014398509481984L,
|
||||
36028797018963968L,
|
||||
72057594037927936L,
|
||||
144115188075855872L,
|
||||
288230376151711744L,
|
||||
576460752303423488L,
|
||||
1152921504606846976L,
|
||||
2305843009213693952L,
|
||||
4611686018427387904L,
|
||||
Long.parseUnsignedLong("9223372036854775808"),
|
||||
};
|
||||
|
||||
//#endregion
|
||||
|
||||
}
|
||||
236
Java/MoveUtils.java
Normal file
236
Java/MoveUtils.java
Normal file
@@ -0,0 +1,236 @@
|
||||
|
||||
public class MoveUtils
|
||||
{
|
||||
|
||||
static final int BISHOP_UP_LEFT = 0;
|
||||
static final int BISHOP_UP_RIGHT = 1;
|
||||
static final int BISHOP_DOWN_LEFT = 2;
|
||||
static final int BISHOP_DOWN_RIGHT = 3;
|
||||
|
||||
static final int ROOK_UP = 0;
|
||||
static final int ROOK_DOWN = 2;
|
||||
static final int ROOK_LEFT = 3;
|
||||
static final int ROOK_RIGHT = 1;
|
||||
|
||||
|
||||
public static long getRookMovesSeparate(long combined_occ, int square)
|
||||
{
|
||||
long combinedAttacks = 0;
|
||||
|
||||
long rookAttackUp = MoveConstants.ROOK_ATTACKS[ROOK_UP][square];
|
||||
long rookAndOccs = rookAttackUp & combined_occ;
|
||||
if (rookAndOccs != 0)
|
||||
{
|
||||
long lastValue = rookAndOccs;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
rookAndOccs = rookAndOccs & rookAndOccs - 1;
|
||||
if (rookAndOccs == 0)
|
||||
{
|
||||
int endSquare = Perft.bitScanForward(lastValue); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
break;
|
||||
}
|
||||
lastValue = rookAndOccs;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
combinedAttacks |= rookAttackUp;
|
||||
}
|
||||
// Pr.println("Rook up");
|
||||
//Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long rookAttackLeft = MoveConstants.ROOK_ATTACKS[ROOK_LEFT][square];
|
||||
rookAndOccs = rookAttackLeft & combined_occ;
|
||||
if (rookAndOccs != 0)
|
||||
{
|
||||
long lastValue = rookAndOccs;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
rookAndOccs = rookAndOccs & rookAndOccs - 1;
|
||||
if (rookAndOccs == 0)
|
||||
{
|
||||
int endSquare = Perft.bitScanForward(lastValue); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
break;
|
||||
}
|
||||
lastValue = rookAndOccs;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
combinedAttacks |= rookAttackLeft;
|
||||
}
|
||||
//Pr.println("Rook left");
|
||||
//Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long rookAttackDown = MoveConstants.ROOK_ATTACKS[ROOK_DOWN][square];
|
||||
rookAndOccs = rookAttackDown & combined_occ;
|
||||
if (rookAndOccs != 0)
|
||||
{
|
||||
int endSquare = Perft.bitScanForward(rookAndOccs); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
}
|
||||
else
|
||||
{
|
||||
combinedAttacks |= rookAttackDown;
|
||||
}
|
||||
// Pr.println("Rook down");
|
||||
// Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long rookAttackRight = MoveConstants.ROOK_ATTACKS[ROOK_RIGHT][square];
|
||||
rookAndOccs = rookAttackRight & combined_occ;
|
||||
if (rookAndOccs != 0)
|
||||
{
|
||||
int endSquare = Perft.bitScanForward(rookAndOccs); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
}
|
||||
else
|
||||
{
|
||||
combinedAttacks |= rookAttackRight;
|
||||
}
|
||||
// Pr.println("Rook right");
|
||||
// Pr.printlongLn(combinedAttacks);
|
||||
|
||||
return combinedAttacks;
|
||||
}
|
||||
|
||||
public static long getBishopMovesSeparate(long combined_occ, int square)
|
||||
{
|
||||
|
||||
//Pr.printIntLn(square);
|
||||
//Pr.printSquareLn(square);
|
||||
|
||||
long combinedAttacks = 0;
|
||||
|
||||
long bishopAttackUpLeft = MoveConstants.BISHOP_ATTACKS[BISHOP_UP_LEFT][square];
|
||||
long bishopAndOccs = bishopAttackUpLeft & combined_occ;
|
||||
if (bishopAndOccs != 0) {
|
||||
long lastValue = bishopAndOccs;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bishopAndOccs &= bishopAndOccs - 1;
|
||||
if (bishopAndOccs == 0) {
|
||||
int endSquare = Perft.bitScanForward(lastValue); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
break;
|
||||
}
|
||||
lastValue = bishopAndOccs;
|
||||
}
|
||||
} else {
|
||||
combinedAttacks |= bishopAttackUpLeft;
|
||||
}
|
||||
// Pr.println("Bishop up left");
|
||||
//Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long bishopAttackUpRight = MoveConstants.BISHOP_ATTACKS[BISHOP_UP_RIGHT][square];
|
||||
bishopAndOccs = bishopAttackUpRight & combined_occ;
|
||||
if (bishopAndOccs != 0) {
|
||||
long lastValue = bishopAndOccs;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bishopAndOccs &= bishopAndOccs - 1;
|
||||
if (bishopAndOccs == 0) {
|
||||
int endSquare = Perft.bitScanForward(lastValue); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
break;
|
||||
}
|
||||
lastValue = bishopAndOccs;
|
||||
}
|
||||
} else {
|
||||
combinedAttacks |= bishopAttackUpRight;
|
||||
}
|
||||
// Pr.println("Bishop up right");
|
||||
// Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long bishopAttackDownLeft = MoveConstants.BISHOP_ATTACKS[BISHOP_DOWN_LEFT][square];
|
||||
|
||||
// Pr.println("down left bitboard");
|
||||
// Pr.printlongLn(bishopAttackDownLeft);
|
||||
// Pr.println("__________");
|
||||
|
||||
bishopAndOccs = bishopAttackDownLeft & combined_occ;
|
||||
if (bishopAndOccs != 0) {
|
||||
int endSquare = Perft.bitScanForward(bishopAndOccs); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
} else {
|
||||
combinedAttacks |= bishopAttackDownLeft;
|
||||
}
|
||||
// Pr.println("Bishop down left");
|
||||
// Pr.printlongLn(combinedAttacks);
|
||||
|
||||
long bishopAttackDownRight = MoveConstants.BISHOP_ATTACKS[BISHOP_DOWN_RIGHT][square];
|
||||
bishopAndOccs = bishopAttackDownRight & combined_occ;
|
||||
if (bishopAndOccs != 0) {
|
||||
int endSquare = Perft.bitScanForward(bishopAndOccs); // Implement this method
|
||||
combinedAttacks |= Inb.INBETWEEN_BITBOARDS[square][endSquare];
|
||||
} else {
|
||||
combinedAttacks |= bishopAttackDownRight;
|
||||
}
|
||||
// Pr.println("Bishop down right");
|
||||
// Pr.printlongLn(combinedAttacks);
|
||||
return combinedAttacks;
|
||||
}
|
||||
|
||||
public static Boolean Is_Square_Attacked_By_Black_Global(int square, long occupancy)
|
||||
{
|
||||
|
||||
// if (Board.bitboard_array_global[GenConst.BP] & MoveConstants.WHITE_PAWN_ATTACKS[square]).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.BN] & MoveConstants.KNIGHT_ATTACKS[square]).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.BK] & MoveConstants.KING_ATTACKS[square]).signum() != 0) {
|
||||
/// return true;
|
||||
//}
|
||||
//long bishopAttacks = MoveUtils.GetBishopMovesSeparate(occupancy, square);
|
||||
//if (Board.bitboard_array_global[GenConst.BB] & bishopAttacks).signum() != 0) {
|
||||
/// return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.BQ] & bishopAttacks).signum() != 0) {
|
||||
/// return true;
|
||||
//}
|
||||
//B/igInteger rookAttacks = MoveUtils.GetRookMovesSeparate(occupancy, square);
|
||||
//if (Board.bitboard_array_global[GenConst.BR] & rookAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.BQ] & rookAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static Boolean Is_Square_Attacked_By_White_Global(int square, long occupancy)
|
||||
{
|
||||
|
||||
// if (Board.bitboard_array_global[GenConst.WP] & MoveConstants.BLACK_PAWN_ATTACKS[square]).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.WN] & MoveConstants.KNIGHT_ATTACKS[square]).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.WK] & MoveConstants.KING_ATTACKS[square]).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//long bishopAttacks = MoveUtils.GetBishopMovesSeparate(occupancy, square);
|
||||
//if (Board.bitboard_array_global[GenConst.WB] & bishopAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.WQ] & bishopAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//long rookAttacks = MoveUtils.GetRookMovesSeparate(occupancy, square);
|
||||
//if (Board.bitboard_array_global[GenConst.WR] & rookAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
//if (Board.bitboard_array_global[GenConst.WQ] & rookAttacks).signum() != 0) {
|
||||
//return true;
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
2378
Java/Perft.java
Normal file
2378
Java/Perft.java
Normal file
File diff suppressed because it is too large
Load Diff
39
Java/Pr.java
Normal file
39
Java/Pr.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Pr {
|
||||
|
||||
public static void print(String input)
|
||||
{
|
||||
System.out.print(input);
|
||||
}
|
||||
public static void println(String input)
|
||||
{
|
||||
System.out.println(input);
|
||||
}
|
||||
public static void printInt(int input)
|
||||
{
|
||||
System.out.print(input);
|
||||
}
|
||||
public static void printIntLn(int input)
|
||||
{
|
||||
System.out.println(input);
|
||||
}
|
||||
public static void printBigInteger(BigInteger input)
|
||||
{
|
||||
System.out.print(input);
|
||||
}
|
||||
public static void printBigIntegerLn(BigInteger input)
|
||||
{
|
||||
System.out.println(input);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void printSquareLn(int input)
|
||||
{
|
||||
assert input >= 0 && input < 64 : "Invalid square: " + input;
|
||||
|
||||
System.out.print(GenConst.SQ_CHAR_X[input]);
|
||||
System.out.println(GenConst.SQ_CHAR_Y[input]);
|
||||
}
|
||||
}
|
||||
92
Java/Testing.java
Normal file
92
Java/Testing.java
Normal file
@@ -0,0 +1,92 @@
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Testing
|
||||
{
|
||||
|
||||
public static void testRookMoves()
|
||||
{
|
||||
int rookSquare = 36;
|
||||
|
||||
long WP_STARTING_POSITIONS = 71776119061217280L;
|
||||
long BP_STARTING_POSITIONS = 65280L;
|
||||
long COMBINED_OCC = WP_STARTING_POSITIONS | BP_STARTING_POSITIONS;
|
||||
|
||||
long rookMoves = MoveUtils.getRookMovesSeparate(COMBINED_OCC, rookSquare);
|
||||
//Bitboard.printBigInteger(rookMoves);
|
||||
}
|
||||
|
||||
public static void TestKnightMoves()
|
||||
{
|
||||
BigInteger MAX_BIGINT = new BigInteger("18446744073709551615"); // Max u64 value
|
||||
BigInteger knightBitboard = BigInteger.ZERO;
|
||||
knightBitboard = knightBitboard.setBit(45);
|
||||
knightBitboard = knightBitboard.setBit(42);
|
||||
|
||||
Bitboard.printBigInteger(knightBitboard);
|
||||
Bitboard.printBigInteger(MAX_BIGINT);
|
||||
|
||||
BigInteger tempBitboard = knightBitboard;
|
||||
|
||||
while (!tempBitboard.equals(BigInteger.ZERO))
|
||||
{
|
||||
int knightSquare = Bitboard.bitScanForwardSlow(tempBitboard);
|
||||
tempBitboard = tempBitboard.clearBit(knightSquare);
|
||||
|
||||
Pr.println("Knight square: " + knightSquare);
|
||||
|
||||
if (knightSquare == -1)
|
||||
{
|
||||
Pr.println("Error knight sq -1");
|
||||
break;
|
||||
}
|
||||
|
||||
//BigInteger knightAttacks = MoveConstants.KNIGHT_ATTACKS[knightSquare];
|
||||
Pr.println("Knight on square " + knightSquare);
|
||||
//Bitboard.printBigInteger(knightAttacks);
|
||||
}
|
||||
}
|
||||
|
||||
public static void printRookMoves()
|
||||
{
|
||||
for (int direction = 0; direction < 4; direction++)
|
||||
{
|
||||
Pr.println("direction: " + direction);
|
||||
for (int sq = 0; sq < 64; sq++)
|
||||
{
|
||||
// Bitboard.printBigInteger(MoveConstants.ROOK_ATTACKS[direction][sq]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void printBishopMoves()
|
||||
{
|
||||
for (int direction = 0; direction < 4; direction++)
|
||||
{
|
||||
Pr.println("direction: " + direction);
|
||||
for (int sq = 0; sq < 64; sq++)
|
||||
{
|
||||
// Bitboard.printBigInteger(MoveConstants.BISHOP_ATTACKS[direction][sq]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void testLong()
|
||||
{
|
||||
long knight_bitboard = 0L;
|
||||
knight_bitboard |= MoveConstants.SQUARE_BBS[63];
|
||||
Bitboard.printLong(knight_bitboard);
|
||||
}
|
||||
|
||||
public static void bitScanTest()
|
||||
{
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
int square = Perft.bitScanForward(MoveConstants.SQUARE_BBS[i]);
|
||||
Pr.print("i: "); System.out.println(i); Pr.print("sq: "); System.out.println(square);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user