File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Game Development and the fly likes Write Chess Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Write Chess Game" Watch "Write Chess Game" New topic

Write Chess Game

Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
I have no idea about how to build a chess game using Java.
Can somebody give me ideas or any useful links?
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
hi Rajan
I have the same problem , and i need to finish my game in 10 days
what i have done for now is putting on a JFrame an Image ,this image
is the playing Board , and then With the mouseListenerEvent i can locate
which Block ( careau in "French" ) is clicked
and on each Block there is a JLabel with an Image (this Image is the Piece that can be a castle , soldier ...)
and i dont move the pieces i only change the Image on the JLable located
on the Playing Board, plus there is a long tests if the move is legal or not.
hope i helped you with an idea to start with ,if you have a better one
plz tell me ,or if you need my sourceCode you can mail me and ill send it to you .
Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
Hi Omar

Nice to hear that u also work on the same thing, by the way is your game human to human or human to computer? I am looking for human to computer resource....
Anyway could u please mail your source code to
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi ,
I m impressed with ur idea .
I m also trying for the same but I am on a basic level .
Could u please tell me how can we add image on a frame .
Definately I will face some bigger problem in future so could u give me ur mail ID so i can mail u on that .
thanks in advance .
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
There are all kinds of ways to make the GUI on the board. You could do the JLabel version, which is pretty slick. You could write your own custom component by extending JComponent and then overriding the paintComponent() method. You could do it using jME and have the ability to do 3d with lighting effects, though that might be a bit much right now.

If you need to play against the computer, you'll need to look up AI resources. Implementing an AI chess system isn't going to be easy.

Aaron R>
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
1) ditch the GUI (for now) for text input
2) make it modular so you can easily plug one UI for another
3) read up on computer chess, there's tons of websites related to it
4) start with an engine that just validates moves input by the user
5) then add a move generator to replace a human player

I've been thinking of creating a chess program for a long time, never gotten around to making more than a tiny start (that was a few C++ classes I wrote about 10 years ago that I since lost the source of).

Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
The best way to start would be to create logic that obeys all the rules of chess and then a short routine to select the next best offensive move or any offensive move to begin with.

After that you could introduce standard chess openings. If you are not familiar with these, get a beginners book on chess. "Chess in a Nutshell" is good. I don't remember the author.

Once it is working you can get more sophisticated adding a governor of sorts to decide how many moves in advance to plan. Also a routine to identify threatened pieces and possible attacks from the opponent.

Like any complex programming challenge. Lay the ground work by getting the basic functions to work and then build on top of it.

Anxiety does not empty tomorrow of its sorrows, but only empties today of its strength. – Charles Spurgeon
Daniel Botelho

Joined: Nov 13, 2004
Posts: 6
Originally posted by ankur:

Could u please tell me how can we add image on a frame .

You can add an image to a JPanel this way:
1� - create your classe "Piece", that extends JPanel;
2� - Insert in the method paintComponent() the image that u want to display


Here it's a good link:
Chess Program Written in Java

Best regards,
Daniel Botelho
I agree. Here's the link:
subject: Write Chess Game
It's not a secret anymore!