8 Replies - 20769 Views - Last Post: 09 November 2011 - 01:18 PM Rate Topic: -----

#1 loonybhatia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-October 11

Attempting to make a chess game in java.

Posted 09 November 2011 - 11:51 AM

Hey I want to make a chess game in java and I am confused on how to start. I know I need a two dimensional array for the board and that I need to develop algorithms for each piece but I am confused on how to start it. I am not looking for code, though some examples would be helpful, but rather hints and tips to help me make this. All help is appreciated thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Attempting to make a chess game in java.

#2 I ♣ Seals   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 52
  • Joined: 20-November 10

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:14 PM

A good place to start would be to have a Piece class with a getLegalMoves() method. Other things you'll want to implement are isInCheck() for kings, canCastle() for kings and rooks, and canCaptureEnPassant() for pawns.

Will it involve an AI opponent, or is it just for human players?
Was This Post Helpful? 0
  • +
  • -

#3 dD3   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 16
  • Joined: 04-November 11

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:17 PM

If you are confused on where to start, why not start with something simpler? Start with building another board game called OTHELLO or Reversi.
Othello also uses 8x8 square board and algorithm to play the game and by building this, you gain insight on how to use the pieces and boundaries of the board.
If you get this right, you can start adding additional algorithms to pieces to make your chess game.

Good luck :)
Was This Post Helpful? 1
  • +
  • -

#4 loonybhatia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-October 11

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:18 PM

Just 2 human players and thanks
Was This Post Helpful? 0
  • +
  • -

#5 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:30 PM

I would say use a GUI and add an 8x8 section of Jlabels, change the background color to black and white alternated. Create an super class Piece, has methods legalMoves() and playerType() , will be a 0 or 1 or true or false, helps differentiate between player 1 and 2, and an ImageIcon in the constructor. Then make a separate class for each piece, Rook extends Piece and so forth. Add an MouseListener to each label that you have, when the mouse goes over it, will show where the pieces can move. Just make a Board class that starts the GUI and handles the moves etc. Then add little small things like score, row and column numbers, and maybe a timer, and a Graveyard where the pieces who have been "Taken" are placed at.
Was This Post Helpful? 2
  • +
  • -

#6 Cancos   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 66
  • Joined: 04-February 09

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:36 PM

View PostFuzzyness, on 09 November 2011 - 12:30 PM, said:

I would say use a GUI and add an 8x8 section of Jlabels, change the background color to black and white alternated. Create an super class Piece, has methods legalMoves() and playerType() , will be a 0 or 1 or true or false, helps differentiate between player 1 and 2, and an ImageIcon in the constructor. Then make a separate class for each piece, Rook extends Piece and so forth. Add an MouseListener to each label that you have, when the mouse goes over it, will show where the pieces can move. Just make a Board class that starts the GUI and handles the moves etc. Then add little small things like score, row and column numbers, and maybe a timer, and a Graveyard where the pieces who have been "Taken" are placed at.

Just be sure to keep your superclass (ChessPiece) abstract. We wouldnt want to mistakenly create some freaky objects.

Edit* If you are new to GUI, I would recommend that you work with the console. It should work just as fine and you may even create some method that will print the board and show you the available pieces and/or location of them on the board. You can fill the spaces with something such as wP for white pawn or bR for black rook in their locations. Just a suggestion.

This post has been edited by Cancos: 09 November 2011 - 12:41 PM

Was This Post Helpful? 1
  • +
  • -

#7 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:41 PM

He wanted advice, not the actual game.. so I call technicalities on that slip up :P

But yes make sure that you have your superclass an Abstract class.

Another thing just thought of is have each players name in the top right and left corner, and underneath it have a JProgressBar with a limit of 16, and every time a piece gets "Taken", the person who owned that piece will have his bar increase by 1, and it will show them how close they are to losing. Oh the pressure! ^^
Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11072
  • View blog
  • Posts: 18,910
  • Joined: 19-March 11

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 12:49 PM

View PostFuzzyness, on 09 November 2011 - 02:30 PM, said:

I would say use a GUI and add an 8x8 section of Jlabels, change the background color to black and white alternated. Create an super class Piece, has methods legalMoves() and playerType() , will be a 0 or 1 or true or false, helps differentiate between player 1 and 2, and an ImageIcon in the constructor. Then make a separate class for each piece, Rook extends Piece and so forth. Add an MouseListener to each label that you have, when the mouse goes over it, will show where the pieces can move. Just make a Board class that starts the GUI and handles the moves etc. Then add little small things like score, row and column numbers, and maybe a timer, and a Graveyard where the pieces who have been "Taken" are placed at.



Hold on there - don't get your presentation and your logic tangled up or you'll have a hell of a time.

Internal representation of the game is one set of decisions, interface is another, and you should be able to change either without modifying the other.
Was This Post Helpful? 2
  • +
  • -

#9 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11072
  • View blog
  • Posts: 18,910
  • Joined: 19-March 11

Re: Attempting to make a chess game in java.

Posted 09 November 2011 - 01:18 PM

View PostdD3, on 09 November 2011 - 02:17 PM, said:

If you are confused on where to start, why not start with something simpler? Start with building another board game called OTHELLO or Reversi.
Othello also uses 8x8 square board and algorithm to play the game and by building this, you gain insight on how to use the pieces and boundaries of the board.
If you get this right, you can start adding additional algorithms to pieces to make your chess game.

Good luck :)


This is actually a very good suggestion. I second it.

View PostCancos, on 09 November 2011 - 02:36 PM, said:

I would recommend that you work with the console. It should work just as fine and you may even create some method that will print the board and show you the available pieces and/or location of them on the board.



Also a good suggestion. If your design is a good one, you should be able to convert it to a GUI later on without any trouble - or to an android app, if you want, or to some sort of verbal interface for the blind. That's what I mean by keeping the internal representation separate from the presentation.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1