You are being forwarded to the lastest updates ot his page!
Or you can Click Here if it doesn't work or you don't wish to wait.

Write Chess Game

thiru73
I have no idea about how to build a chess game using Java.
Can somebody give me ideas or any useful links? [banghead]


omarB
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


thiru73
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


rathi ji
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


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


Daniel Botelho
quote:
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:
code:
import javax.swing.*;
import java.awt.*;

public class Queen extends javax.swing.JPanel {
Image image = null;

public Queen() {
setPreferredSize(new java.awt.Dimension(12,11));
try{
java.net.URL url = this.getClass().getResource("your link");
//java.net.URL url = new java.net.URL("your web link");
image = Toolkit.getDefaultToolkit().getImage(url);
}catch(Exception e){e.printStackTrace();}
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0,0, this);
}
}



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

Best regards,
Daniel Botelho