# Thread: I really need your help with my Chess game @school

1. ## Re: I really need your help with my Chess game @school

Take what you have now and try to write code to find the valid squares to move to.
Put those in a list and print out the list

2. Member
Join Date
Dec 2011
Posts
19
Rep Power
0

## Re: I really need your help with my Chess game @school

Originally Posted by Norm
Take what you have now and try to write code to find the valid squares to move to.
Put those in a list and print out the list

Do I have to use Chain of responsibility back to square or how do I find those valid squares?

3. ## Re: I really need your help with my Chess game @school

how do I find those valid squares?
Do you play chess? There are rules for how each piece moves. You need to look at the chess rules to determine what moves are valid.

Do I have to use Chain of responsibility back to square
I guess you either look at the code or you ask the person who wrote the code.

4. Member
Join Date
Dec 2011
Posts
19
Rep Power
0

## Re: I really need your help with my Chess game @school

Sorry to be asking so nooby questions..but our teacher teaches us in a strange way..Ofcourse I wrote the code.

I dont want to program rules for the whole game, its just the highlight function I need

5. ## Re: I really need your help with my Chess game @school

You need the rules for the piece(s) you want to show the possible moves for.

6. Member
Join Date
Dec 2011
Posts
19
Rep Power
0

## Re: I really need your help with my Chess game @school

Ok so I have tried abit but need more help. When I click on a piece, I get it to mark the field the piece is placed on, now I need to get it to mark the field colon +1.

I need a method that finds the field infront of me, in short words

7. ## Re: I really need your help with my Chess game @school

When I click on a piece, I get it to mark the field the piece is placed on
That must mean you know where the piece is located and what type of piece it is.
Given those two pieces of information, you should be able to compute what the legal moves are.

8. Member
Join Date
Dec 2011
Posts
19
Rep Power
0

## Re: I really need your help with my Chess game @school

I do not need to make rules, I only need the field infront of the pawn to lighten up

9. ## Re: I really need your help with my Chess game @school

First you need to find the pawn's location.
Are the pieces' locations given by row and column?
Do the row numbers start at 0 or at 1?
Which is the first row? The one at the bottom or the one at the top of the board?
Answer the same questions for the columns.

Once you have the location of the piece on the 64 square board and know which piece it is and which side of the board is the starting side for that piece then you can compute the piece's legal moves.

Define all of the above and then you will be able to compute the legal moves for a piece.

To visualize this problem, pick a pawn to talk about. Write down its current location and write down the locations it can move to.

10. Member
Join Date
Dec 2011
Posts
19
Rep Power
0

## Re: I really need your help with my Chess game @school

First you need to find the pawn's location.
Are the pieces' locations given by row and column? Yes they are, they are placed on with a double array, but they are placed on top of Square.

here is the code:

public SquareMatrix() {
setLayout(new GridLayout(8, 0));
for (int i = 0; i < 64; i++)

}

Do the row numbers start at 0 or at 1?
Which is the first row? The one at the bottom or the one at the top of the board?
The one at top I guess
Answer the same questions for the columns.

Once you have the location of the piece on the 64 square board and know which piece it is and which side of the board is the starting side for that piece then you can compute the piece's legal moves.

Define all of the above and then you will be able to compute the legal moves for a piece.

To visualize this problem, pick a pawn to talk about. Write down its current location and write down the locations it can move to

But look at my code, I have a mouseclick, on that mouseclick i launch a method that paints a square..But I want that method to be painting for example the square in front...

This is driving me nuts !!!!!

11. ## Re: I really need your help with my Chess game @school

You need an algorithm that given a square (0-63) it will give you the row and column for that square.
Then when you have the row and column for that square and the information about the piece that is on that square you will be able to compute the legal moves for that piece from that square.
For example: Say these numbers are some of the squares:
Java Code:
``` 16 17 18 19 20 21 22  23
8  9  10 11 12 13 14 15
0  1   2  3  4   5   6  7```
if the pawn is on row 2, column 2 (square 9) then one of its legal moves are to row 3 and column2 (square 17)

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•