Skip to content

Commit

Permalink
1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Senders authored and Senders committed Apr 26, 2020
1 parent 6483ba2 commit 189434c
Show file tree
Hide file tree
Showing 62 changed files with 2,333 additions and 1,915 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

A chessengine build in Java that uses the UCI protocol to communicate with graphical interfaces.
Should be used with a 64 bit JRE for optimal performance.
The binaries are build using Java 11 and are not compatible with older Java versions.
The binary is build using Java 14. Also a Java 11 binary is supplied.
Score is about 3100 elo (CCRL 40/4).

## Features
- (magic) bitboards
- transposition tables
- (internal) iterative-deepening
- killer/counter-moves and history-heuristics for move ordering
- principal variation search
- (static) null move pruning
Expand Down
21 changes: 8 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>nl.s22k</groupId>

<!-- so we can simply build other (experimental) artifacts -->
<!-- artifactId>${engineName}</artifactId -->
<!-- artifactId>${engineName}</artifactId-->
<artifactId>chess22k</artifactId>

<version>1.13</version>
<version>1.14</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -21,7 +22,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
Expand All @@ -43,13 +44,13 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<release>14</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.3.1</version>
<version>4.4.1</version>
</plugin>
</plugins>
</build>
Expand All @@ -61,20 +62,14 @@
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<skipEmptyReport>false</skipEmptyReport>
</configuration>
Expand Down
8 changes: 7 additions & 1 deletion release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
1.14 - 26-04-2020 - 3100 elo
- check validity of tt move (caused crashes when lots of threads were used)
- improved SMP scaling (caches per thread)
- some code-cleanup


1.13 - 28-07-2019 - 3100 elo
- fixed a crash
- simplified some code


1.12 - 03-12-2018 - 3100 elo
- participated in CSVN 54
- rewritten SMP implementation (inspired by Laser, performs worse than 1.11 at the moment...)
- rewritten SMP implementation (inspired by Laser)
- added some endgame knowledge
- implemented counter move heuristic
- improved LMR reductions calculation (inspired by Ethereal)
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/nl/s22k/chess/Bitboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ public class Bitboard {
// special ranks
public static final long RANK_12 = RANK_1 | RANK_2;
public static final long RANK_78 = RANK_7 | RANK_8;
public static final long RANK_123 = RANK_1 | RANK_2 | RANK_3;
public static final long RANK_234 = RANK_2 | RANK_3 | RANK_4;
public static final long RANK_567 = RANK_5 | RANK_6 | RANK_7;
public static final long RANK_678 = RANK_6 | RANK_7 | RANK_8;
public static final long RANK_1234 = RANK_1 | RANK_2 | RANK_3 | RANK_4;
public static final long RANK_5678 = RANK_5 | RANK_6 | RANK_7 | RANK_8;
public static final long RANK_23456 = RANK_2 | RANK_3 | RANK_4 | RANK_5 | RANK_6;
public static final long RANK_34567 = RANK_3 | RANK_4 | RANK_5 | RANK_6 | RANK_7;
public static final long RANK_234567 = RANK_2 | RANK_3 | RANK_4 | RANK_5 | RANK_6 | RANK_7;
public static final long RANK_34567 = RANK_3 | RANK_4 | RANK_5 | RANK_6 | RANK_7;
public static final long RANK_PROMOTION[] = { RANK_7, RANK_2 };
public static final long RANK_NON_PROMOTION[] = { ~RANK_PROMOTION[0], ~RANK_PROMOTION[1] };
public static final long RANK_FIRST[] = { RANK_1, RANK_8 };
Expand Down Expand Up @@ -174,15 +178,6 @@ public class Bitboard {
FILE_C | FILE_A, //
FILE_B };

public static final long KING_SIDE = FILE_F | FILE_G | FILE_H;
public static final long QUEEN_SIDE = FILE_A | FILE_B | FILE_C;

public static final long WHITE_SIDE = RANK_1 | RANK_2 | RANK_3 | RANK_4;
public static final long BLACK_SIDE = RANK_5 | RANK_6 | RANK_7 | RANK_8;

public static final long WHITE_SPACE_ZONE = (RANK_2 | RANK_3 | RANK_4) & (FILE_C | FILE_D | FILE_E | FILE_F);
public static final long BLACK_SPACE_ZONE = (RANK_7 | RANK_6 | RANK_5) & (FILE_C | FILE_D | FILE_E | FILE_F);

public static long getWhitePawnAttacks(final long pawns) {
return pawns << 9 & Bitboard.NOT_FILE_H | pawns << 7 & Bitboard.NOT_FILE_A;
}
Expand Down Expand Up @@ -228,4 +223,12 @@ public static long getBlackAdjacentMask(final int index) {
return getBlackPassedPawnMask(index) & ~FILES[index & 7];
}

public static long getFile(final long square) {
return FILES[Long.numberOfTrailingZeros(square) & 7];
}

public static long getRank(final long square) {
return RANKS[Long.numberOfTrailingZeros(square) / 8];
}

}
7 changes: 3 additions & 4 deletions src/main/java/nl/s22k/chess/CastlingUtil.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package nl.s22k.chess;

import static nl.s22k.chess.ChessConstants.ALL;
import static nl.s22k.chess.ChessConstants.BLACK;
import static nl.s22k.chess.ChessConstants.EMPTY;
import static nl.s22k.chess.ChessConstants.ROOK;
import static nl.s22k.chess.ChessConstants.WHITE;

import nl.s22k.chess.eval.EvalConstants;
import nl.s22k.chess.eval.MaterialUtil;;

public final class CastlingUtil {

Expand Down Expand Up @@ -152,8 +152,8 @@ public static void castleRookUpdateKeyAndPsqt(final ChessBoard cb, final int kin
}

private static void castleRookUpdatePsqt(final ChessBoard cb, final int fromIndex, final int toIndex, final int color) {
cb.pieces[color][ALL] ^= Util.POWER_LOOKUP[fromIndex] | Util.POWER_LOOKUP[toIndex];
cb.pieces[color][ROOK] ^= Util.POWER_LOOKUP[fromIndex] | Util.POWER_LOOKUP[toIndex];
cb.friendlyPieces[color] ^= Util.POWER_LOOKUP[fromIndex] | Util.POWER_LOOKUP[toIndex];
cb.pieceIndexes[fromIndex] = EMPTY;
cb.pieceIndexes[toIndex] = ROOK;
cb.psqtScore += EvalConstants.PSQT[ROOK][color][toIndex] - EvalConstants.PSQT[ROOK][color][fromIndex];
Expand All @@ -170,8 +170,7 @@ public static boolean isValidCastlingMove(final ChessBoard cb, final int fromInd
long kingIndexes = ChessConstants.IN_BETWEEN[fromIndex][toIndex] | Util.POWER_LOOKUP[toIndex];
while (kingIndexes != 0) {
// king does not move through a checked position?
if (CheckUtil.isInCheckIncludingKing(Long.numberOfTrailingZeros(kingIndexes), cb.colorToMove, cb.pieces[cb.colorToMoveInverse], cb.allPieces,
MaterialUtil.getMajorPieces(cb.materialKey, cb.colorToMoveInverse))) {
if (CheckUtil.isInCheckIncludingKing(Long.numberOfTrailingZeros(kingIndexes), cb.colorToMove, cb.pieces[cb.colorToMoveInverse], cb.allPieces)) {
return false;
}
kingIndexes &= kingIndexes - 1;
Expand Down
39 changes: 2 additions & 37 deletions src/main/java/nl/s22k/chess/CheckUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,6 @@ public final class CheckUtil {

//@formatter:off

public static long getCheckingPieces(final ChessBoard cb) {
final int kingIndex = cb.kingIndex[cb.colorToMove];

// put 'super-piece' in kings position
return (cb.pieces[cb.colorToMoveInverse][NIGHT] & StaticMoves.KNIGHT_MOVES[kingIndex]
| (cb.pieces[cb.colorToMoveInverse][ROOK]|cb.pieces[cb.colorToMoveInverse][QUEEN]) & MagicUtil.getRookMoves(kingIndex, cb.allPieces)
| (cb.pieces[cb.colorToMoveInverse][BISHOP]|cb.pieces[cb.colorToMoveInverse][QUEEN]) & MagicUtil.getBishopMoves(kingIndex, cb.allPieces)
| cb.pieces[cb.colorToMoveInverse][PAWN] & StaticMoves.PAWN_ATTACKS[cb.colorToMove][kingIndex]
);
}

public static long getCheckingPieces(final ChessBoard cb, final int sourcePieceIndex) {
switch(sourcePieceIndex) {
case PAWN:
return cb.pieces[cb.colorToMoveInverse][PAWN] & StaticMoves.PAWN_ATTACKS[cb.colorToMove][cb.kingIndex[cb.colorToMove]];
case NIGHT:
return cb.pieces[cb.colorToMoveInverse][NIGHT] & StaticMoves.KNIGHT_MOVES[cb.kingIndex[cb.colorToMove]];
case BISHOP:
return cb.pieces[cb.colorToMoveInverse][BISHOP] & MagicUtil.getBishopMoves(cb.kingIndex[cb.colorToMove], cb.allPieces);
case ROOK:
return cb.pieces[cb.colorToMoveInverse][ROOK] & MagicUtil.getRookMoves(cb.kingIndex[cb.colorToMove], cb.allPieces);
case QUEEN:
return cb.pieces[cb.colorToMoveInverse][QUEEN] & MagicUtil.getQueenMoves(cb.kingIndex[cb.colorToMove], cb.allPieces);
default:
//king can never set the other king in check
return 0;
}
}

public static boolean isInCheck(final int kingIndex, final int colorToMove, final long[] enemyPieces, final long allPieces) {

Expand All @@ -53,15 +25,8 @@ public static boolean isInCheck(final int kingIndex, final int colorToMove, fina
)!= 0;
}

public static boolean isInCheckIncludingKing(final int kingIndex, final int colorToMove, final long[] enemyPieces, final long allPieces, final int enemyMajorPieces) {

//TODO
if(enemyMajorPieces==0) {
return (enemyPieces[PAWN] & StaticMoves.PAWN_ATTACKS[colorToMove][kingIndex]
| enemyPieces[KING] & StaticMoves.KING_MOVES[kingIndex]
)!= 0;
}

public static boolean isInCheckIncludingKing(final int kingIndex, final int colorToMove, final long[] enemyPieces, final long allPieces) {

// put 'super-piece' in kings position
return (enemyPieces[NIGHT] & StaticMoves.KNIGHT_MOVES[kingIndex]
| (enemyPieces[ROOK] | enemyPieces[QUEEN]) & MagicUtil.getRookMoves(kingIndex, allPieces)
Expand Down
Loading

0 comments on commit 189434c

Please sign in to comment.