Giter Club home page Giter Club logo

chessmate's Introduction

Chessmate: Chess AI in Java

Update: Woohoo, my 10+ year-old Java Chess AI has made it into a Minecraft mod called MineChess!

Chessmate in the Minecraft mod, MineChess

How to run

Run src/build.bat to compile and run. You will need the Java SDK. You can beat her easily on a depth of 4, but if you give it ~20-30s at depth setting of 5, she plays a decent game.

I wrote this Java chess engine eight years ago in 2005 for my grade 12 high school project. I was 17 at the time, so I thought the code would be really bad, but it still works and beats me most of the time, bearing in mind that I'm not a very good chess player. It won a regional prize or something (cash must have gotten lost in the mail). I'm pretty proud of it :).

Chessmate Screenshot

Limitations

Chessmate has no opening book and cannot castle, take en passant or promote pawns. If you are feeling masochistic, you can add castling by modifying the Board class and heuristic function, positionEvaluation.

How does it work?

Chessmate uses an iterative deepening minimax search algorithm with alpha-beta pruning and simple horizon detection during exchanges with an original heuristic function.

That's a fancy way of saying:

  1. Chessmate builds a tree of all possible moves to some depth,
  2. rates each position with a heuristic function
  3. choose the move that minimises your advantage while maximising its own advantage,
  4. and looks beyond the horizon during exchanges.

Performance

Chessmate has a naive early game due the lack of an opening book, an average mid-game and a pretty strong end-game. It runs pretty fast for a Java application. I remember it searching through 500k moves/second on my slow computer in 2005. I now get about 1.2M nodes/second on my 2012 Macbook Air running on a single thread.

Database?

The project had a database requirement, but I ripped out the Access database prompt. It was mostly a gimmick for the project requirements that tracks a history of moves.

Design of Heuristic Function

The heuristic function is quite simple, but performs well given sufficient search depth (5 seems to be the sweet spot). The positionEvaluation method returns a floating-point value that is positive or negative based on whether it's winning or losing, respectively. It also uses some of the board control data set in the setControlData method.

The following factors are weighted to evaluate each board position:

  • Material gain (sum of the value of your pieces minus the opponent's)
  • Attacking the opponent's pieces
  • Defending it's own pieces
  • Controlling the board, with extra weight for controlling the four squares in the centre of the board.

The structure of these evaluation functions are terrible and really hard to unit test. Having read through the evaluation code, I am almost certain that the board control data is fundamentally broken. Oh well.

chessmate's People

Contributors

divideby0 avatar theronic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chessmate's Issues

Java Applet

Would be nice if this could run in a browser as a Java Applet

Windows-specific file separators

Cool project! To get it to run on OS X, I had to edit Main.java and replace all instances of the Windows-specific file separator "\" to "/". You might want to consider using File.separator instead.

Castling

Chessmate has no knowledge of castling

Suicide if it can checkmate you in 1 move

Chessmate allows itself to be mated if it sees a counter-mate in one or two moves, e.g.:
image

A simple solution would be to double the value of its own king, but a better design should incorporate a test for checkmate in every position. I fear this may significantly slow down the evaluation function.

En Passant

Chessmate has no knowledge of en passant, but some of the code for this is commented.

MineChess

Hey,

I wanted to let you know I've implemented your AI code in my Minecraft Modification, MineChess. As far as I know you've allowed this in your licence, which I'm very thankful about. I'm writing this as I thought you might like to see your project being used elsewhere :D

And a link if you like: http://www.minecraftforum.net/topic/1764960-172forgesspsmp-minechess/
And the source can be found in my github repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.