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.

chess problem

omarB
hi all , i am writing a chess game
where can i perform if the test is legal or not ?
and should i take all the possibilities or is there might be
a better way to do that ?


Jessica Bradley
as was suggested in your previous post... one idea is to create an interface for the chess piece:
code:

interface ChessPiece{
/**
* Returns the type of piece this is: King, Queen, Pawn, etc
*/
public String getPieceType();

/**
* Returns true if the given move is allowed for this chess piece
*/
public boolean isMoveLegal( int x, int y );

/**
* Performs the given move, returns true if successful.
* @exception IllegalMoveException
*/
public boolean move( int x, int y ) throws IllegalMoveException;


Then you can implement this class for each type of chess piece. You'll have to come up with a scheme to determine if a given move is allowed.

For example... for a knight they can move (ummm I forget) 1 forward and 3 to the side?? so given the current position, is (x,y) the position that is 1 space forward and 3 to the side? Also is (x,y) even on the board? Is another piece occupying that space?

Maybe your Board class will have methods like
code:

/**
* Checks to see if the given space is occupied
*/
public boolean isSpaceOccupied( int x, int y)
/**
* Checks to see if there is a clear path between the start and end coordinates
*/
public boolean isPathClear( int startX, int startY, int endX, int endY )



Does that make sense? Try thinking along those lines and see what you come up with.