- Saved searches
- Use saved searches to filter your results more quickly
- License
- jswaff/chess4j
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- Querz/chess
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
a Java based chess engine
License
jswaff/chess4j
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
an XBoard compatible Java based chess engine
chess4j is a chess program written using Java technologies. It is not meant to be super competitive, but just a test bed of sorts for various interests. Those interests include experimenting with different JVM based languages, parallel and distributed computing, and machine learning.
To play chess4j, you’ll need a Java 11 or later JRE and Winboard or Xboard.
To see if you have a JRE installed, open a command prompt and type ‘java -version’. If you need to download a JRE you can download one from the Oracle website:
See http://www.gnu.org/software/xboard for details on installing Winboard or Xboard.
Once those prerequisites are met you can download the latest release and extract the zipfile. Once you extract the zipfile, open the ‘chess4j-winboard.bat’ file (or chess4j-xboard.sh on Linux) and modify the path to match the location you just unzipped to.
chess4j can be built with or without Prophet bundled as a static library. The benefit of bundling Prophet is simply speed. When Prophet is bundled and activated (using the ‘-native’ command line argument), chess4j will leverage Prophet when «thinking.» Since Prophet is written in C and is native, it will execute about 2-3 times faster. It doesn’t move any faster, but it will «see further» and therefore play stronger moves. Otherwise, the algorithms are the same. Just keep in mind that native code is platform dependent. Currently the only platform supported for bundling Prophet is Linux.
Whether you want to bundle Prophet or not, you will need a Java 11 (or better) SDK and Maven. You will probably also need to ensure the JAVA_HOME environment variable is properly set.
Without the Prophet Engine
Clone the repository and go into the chess4j/chess4j-java directory.
Once this process is complete you should see the build artifact in the target directory, e.g. chess4j-java-5.1-uber.jar. Verify everything is working:
java -jar chess4j-java-5.1-uber.jar -suite=../src/test/resources/suites/wac2.epd
You should see the program search for about 10 seconds and display the result.
This option is slighly more complex. In addition to the other prerequisites, you’ll also need a working C/C++ toolchain. I always use gcc / g++. Others may work but have not been tested. You’ll also need ‘make’ and a copy of Google Test from https://github.com/google/googletest . Finally, set an environment variable GTEST_DIR to point to the ‘googletest’ project (we don’t need the googlemock stuff).
Once you have the prerequisites, clone the chess4j repository. Since Prophet4 is a separate project, you’ll need to do a recursive clone, e.g.
git clone —recurse-submodules git@github.com:jswaff/chess4j.git
If that worked you should see the contents of chess4j/lib/prophet populated. Now, just go into the top level ‘chess4j’ directory and execute:
That will kick off the build process, first building Prophet, then the JNI code that is the «bridge» between the Java and C layer, and finally chess4j itself. The final build artifact will be in the chess4j-java/target directory.
You now have the option to run with or without the native (Prophet) code enabled by using the ‘-native’ command line argument. If you omit that argument, the native code will not be enabled.
Verify everything is working:
java -jar chess4j-java-5.1-uber.jar -suite=../src/test/resources/suites/wac2.epd -native
You should see the program search for about 10 seconds and display the result.
chess4j has a small opening book but it is not enabled by default. If you would like to enable the opening book, you can do it with a command line parameter:
Normally you wouldn’t need to worry about memory usage, but if you want to tweak chess4j here is some important information.
chess4j currently employs two transposition tables. One is used in the main search and one in the pawn evaluation. The default size for each table is 128 MB. (If you run with the -native option, the default size may be different.)
You can specify the maximum memory allocated to each table via command line parameters, but you would really only want to do this if you were running the program directly from the command line, and not using a Winboard compatible GUI or test harness. (I do this when running test suites but that’s about it.)
The above arguments would allocate 256 MB to each table.
Winboard / XBoard has an option to specify the maximum memory usage, and chess4j does respect that. chess4j will divide the memory equally between the two tables.
You can run EPD formatted test suites with chess4j using the ‘suite’ command line argument. The default time per problem is 10 seconds, but that can also be changed with the ‘time’ argument.
java -jar chess4j-java-5.1-uber.jar -suite=wac.epd -time=30
The command above would start chess4j to process the Win At Chess (WAC) test suite, giving it 30 seconds per problem. (A few test suites can be found in the test/resources folder.)
- Passed pawn by rank (was a single value)
- Non-linear mobility (was a single value)
- Knight outposts
- Trapped bishop penalty
- added logistic regresssion with gradient descent
- fully implemented tapered eval (previously was just kings)
- simple mobility terms for bishop and queens
There may be another minor release or two on the 5.x line, but the main focus of development going forward is to implement a neural network.
You can see the combined Prophet / chess4j backlog here: https://trello.com/b/dhcOEaCO/chess4j-board .
About
a Java based chess engine
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Chess in Java using JavaFX
License
Querz/chess
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Chess in Java to exercise the usage of different serialization formats.
A small Chess game implementing the default rules by restricting movement of figures, highlighting fields and showing status messages for:
- Movement of pieces
- En passant
- Castling
- Promotion
- Check
- Check mate
- Stalemate
- 50-moves-rule
Serialization and Deserialization
The game can be saved and loaded using any format. The interface ChessIO can be used to implement a custom format:
ChessIO#load(byte[], ChessBoard) is used to load a byte[] (the first parameter) into the ChessBoard (the second parameter).
ChessIO#save(ChessBoard) is used to serialize the current state of the ChessBoard into a byte[].
To make your own implementation show up in the load / save dialog, simply implement the ChessIO#getFileTypeDescription() and ChessIO#getFileExtension() and add the complete class name to META-INF/services/net.querz.chess.ChessIO.
There are multiple example implementations of linear reading and writing of differend kinds of formats:
Library | Location | Description |
---|---|---|
gson | net.querz.chess.io.json | Saves and loads the game’s state as JSON |
stax | net.querz.chess.io.xml | Uses the StAX library to save and load xml files |
snakeyaml | net.querz.chess.io.yaml | Uses the snakeyaml library to save and load yml files |
csv | net.querz.chess.io.csv | Saves and loads the game’s state as CSV files |
NBT | net.querz.chess.io.nbt | Uses Tags from my NBT library to load from and save the game’s state to gzip compressed NBT files |
BSON | net.querz.chess.io.bson | Loads from and saves the game’s state to gzip compressed BSON encoded files |
Ini | net.querz.chess.io.ini | Loads and saves the game state from and to ini files using a simple ini parser |
bits | net.querz.chess.io.bits | An absolutely minimized proprietary format to save the game’s state using bit manipulation |
FigureFactory.createFigure(Color, String, String, int) can be used to make Figures from basic data. For example:
Figure figure = FigureFactory.createFigure(Color.BLACK, "queen", "c4", 6);
This would create a new instance of Queen on the field C4, which moved the first time on the 6th turn in the game. Keeping track of when the first turn of a figure occured is used to validate Castling and En Passant.
ChessBoard#setFigure(Figure) then sets the Figure to the respective field.
For serialization, the following methods will return all required information to save an entire Chess game:
- ChessBoard#getFigures()
- ChessBoard#getCurrentTurn()
- ChessBoard#get50MoveRuleTurns()
- Figure#getName()
- Figure#getPos()
- Figure#getFirstTurn()
The program can be started in a Test-/Godmode by using the program argument «—godmode». This enables several functions to freely control the ChessBoard and the Pieces. Right-clicking a field shows a context menu to add and remove Pieces, and the options menu in the bottom right corner of the window can now clear the ChessBoard and increment the turn counter (therefore switching the player whose turn it is).