Skip to content

Commit

Permalink
Aded implementation details to readme and updated bitboard picture
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed May 3, 2017
1 parent 43d3e00 commit ee310c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ This is the repo for a checkers AI project.
* `build/runner`
- When project is built it's compiled to the `runner` file

## Implementation Details
Here is an example of the bit board setup this project follows:
## (1) Implementation Details

The project was implemented purely in c++. The decision to use c++ was made because bit manipulation in Java is unnecessarily difficult due to not having any definitive unsigned 32 bit integer primitive. C++ on the other hand contains a plethora of integer data types in the `cstdint` library. Two group members were also taking the networks course concurrently so socket programming in C wasn't an issue.

### Bitboard Implenetation
Here is the bitboard layout that we utilized where each number corresponds to the bit index:

![bit board](/docs/bitboard.png)

This orientation allows all moves to be done with either a 7 bit or 1 bit rotation.
This orientation allows all moves to be done with either a 7 bit or 1 bit rotation. The entire board is then represented by three 32 bit integers: white pieces, black pieces, and kings. This is much more space-efficient than array implementations.

Along with space saving there were other advantages. Using bit manipulation means there's no need to constantly index into any sort of data structure like in the array representation of a board, saving time. Another large advantage is that many of the heuristics can be done with bit masks. That, in combination with inlining done by modern c++ compilers, boils many of these calculations down to a few lines of machine code.

### Search Implementation and Depth

For search we stuck to a recursive minimax with alpha-beta pruning. This implementation can be seen in the `src/MinimaxSearch.cpp` file. This function, identical to the description in the textbook, allows the elimination of unnecessary search, cutting the ply factor by a quarter on average.

We used a simple variable depth solution. We have a minimum and maximum search depth such that the minimum is always met and the search will continue to the maximum depth as long as there are jumps available. With this we could achieve a maximum ply of around 11 in a couple of seconds. The minimum depth of 5 ensured that pieces wouldn't hover around corners during endgame as 5 moves is often enough to encounter another piece which was combined with higher evaluation values on encounters rather than avoidance.

## Citations

The vast majority of the project is personal work but there were some inspirations and little tricks from various sources. Any code directly copied from a source like StackOverflow is stated inline in comments. An exhaustive list of all sources used is here:
* [Checkers Bitboard Tutorial](http://www.3dkingdoms.com/checkers/bitboards.htm#movegen)
* [Compiler Friendly Bit Rotation in C](http://stackoverflow.com/questions/776508/best-practices-for-circular-shift-rotate-operations-in-c)
* [Evolutionary-based heuristic generators](http://pdfs.semanticscholar.org/91c9/d140267f3b008d00b330b6b0e9182fa4b62e.pdf)
* [Strategy Game Programming](http://www.fierz.ch/strategy5.htm)
* [Strategy Game Programming](http://www.fierz.ch/strategy5.htm)
Binary file modified docs/bitboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ee310c6

Please sign in to comment.