Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Board Presentation for Chess Game

Tags:

java

arrays

chess

I am starting to make a 8 x 8 square board for Chess Game Assignment. However, I am wondering if there's anything hint to create the square rather than the 2D array in Java.

one of the restrictions for the assignment disallows to use 2D array or any similar. There's no AI but user control only.

like image 840
Ye Lin Aung Avatar asked Dec 04 '22 19:12

Ye Lin Aung


1 Answers

You can use one-dimensional array, say Figure [] board = new Figure[64] and make a simple getter/setter method to emulate 2-dimensions:

Figure get(int hor, int vert) {
  return board[hor*8+ver];
}

void set(int hor, int vert, Figure f) {
  board[hor*8+ver] = f;
}
like image 90
korifey Avatar answered Dec 22 '22 10:12

korifey