I'm trying to write my own chess game in Java. I've started writing the classes and my high level idea is as follows:
I have a Piece class with these fields:
private String name;
private String color;
Originally I was going to have an x and y coordinate for each piece but that seems like it's more a property of the board. Which brings me to...
I have a Board class with a field like this:
Piece[][] myBoard = new Piece[8][8];
I'm not really sure where / how I should be keeping track of where pieces are. As of now, I just have a 2d array of Piece objects. However, I think this'll present some challenges. For instance, say a user clicks on a piece, wants to move it. I need to figure out whether the move is valid and for that, I'll need the current square the piece is on.
If I have an x and y coordinate for each piece, I'm updating the state of the game in two places (in the Board class's 2d array) and the current piece's x and y coordinates. This seems bad...
Any suggestions?
Thanks for the help, Mariogs