Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  TinyChess  (Read 5284 times)
0 Members and 1 Guest are viewing this topic.
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Posted 2015-07-31 11:15:06 »

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.


Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #1 - Posted 2015-07-31 16:15:52 »

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

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.

Offline mike_bike_kite
« Reply #2 - Posted 2015-08-18 09:52:53 »

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 Smiley

Mike

Arcade swarm
Board Chess - Checkers - Othello
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #3 - Posted 2015-08-18 10:30:36 »

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

Offline mike_bike_kite
« Reply #4 - Posted 2015-08-18 12:13:55 »

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?

Arcade swarm
Board Chess - Checkers - Othello
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #5 - Posted 2015-08-18 16:49:10 »

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...

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (43 views)
2019-09-04 15:33:17

hadezbladez (4024 views)
2018-11-16 13:46:03

hadezbladez (1467 views)
2018-11-16 13:41:33

hadezbladez (4047 views)
2018-11-16 13:35:35

hadezbladez (777 views)
2018-11-16 13:32:03

EgonOlsen (4097 views)
2018-06-10 19:43:48

EgonOlsen (4683 views)
2018-06-10 19:43:44

EgonOlsen (2761 views)
2018-06-10 19:43:20

DesertCoockie (3656 views)
2018-05-13 18:23:11

nelsongames (3866 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!