TinyChess

This was my first real Java program from years ago - a simple Chess AI and UI. It is built with Swing and Swing HTML. The JAR contains the sources too.

https://bitbucket.org/aclarke/headline-distribution/downloads/tinychess.jar

Not implemented : castling, en passant.

I should mention that this was also my first artificial intelligence, and it sometimes beats me :slight_smile:

I took so long (seven years) to post this because there is a bug that sometimes the HTML doc representing the board does not load correctly at startup. I still haven’t fixed the bug… The workaround is to restart.

Since I was a kid I’ve been intimidated by chess AIs - I naively imagined they were masses of if statements based on a deep expertise in chess (an expertise I most definitely lack)… I had a brainwave one day that I wouldn’t need any if statements at all for the AI (all I would need are some simple rules to quantify the quality of a position), and wrote this in my lunch breaks at work.

I’m impressed you can get it down to 60kb! It makes reasonably intelligent moves but I guess the small size of the program rules out much positional logic. This got it a little unstuck as after a dozen moves it was down a piece, had tripled pawns and it’s king was stuck in the middle of the board. I couldn’t work out how to castle which did nearly loose me a piece. I also had to start out as black as it wouldn’t show the board when I tried playing as white.

I do know how difficult it is writing a chess program though - here’s mine if you care to try it out :slight_smile:

Mike

Thanks for the feedback! Castling and en passant are not implemented - adding them would be simple, but I never got round to it. I would need to fix the board display bug first I think.

I like how TinyChess can make seemingly reasonable moves when all it does is count up for each possible move:

  • how many distinct moves you can make
  • how many pieces are defending each of your pieces
  • how many enemies you threaten
  • surviving friendly pieces
  • how many moves your enemy can make
  • how many pieces are defending the enemy pieces
  • how many of your pieces are threatened
  • surviving enemy pieces

You should implement castling as this is a basic move in chess.

You should try to have some basic idea of positioning ie

  • knights to the centre
  • rooks on open files
  • number of squares controlled by a piece
  • pawns to the centre
  • doubled pawns are generally bad
  • king far away from centre
    also remember it’s not the number of pieces but their value ie a queen is approx 9 pawns. Does it look ahead at all - I’m guessing not at the moment?

Yes, I do provide weights based on the relative value of the pieces. I can see I could easily add the rules you suggest. It would be interesting if the new AI would beat the old one reliably.

By the way, unless you mean something else, my algo already considers control - in the form of total number of moves available to each player.

I’m held back by the horrible user interface code and all the other projects I’m commited to. Also I try out each possible move by making a deep copy of the whole board which is really crazy.

Castling will be so simple to add, it wouldn’t require any changes to the AI logic…