This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Write Chess Game" Watch "Write Chess Game" New topic
Author

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 .
bye
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 thiru73@coolgoose.com.
Thanks
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 .
bye
Ankur
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.

HTH,
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).


42
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
Greenhorn

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

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

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

Example:


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

Best regards,
Daniel Botelho
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Write Chess Game
 
Similar Threads
Games
WA #1.....word association
Bit Scan Forward in java
Only fun forwards for fun ...
India Vs Australia