Search code examples
javaarrayschess

Creating a Board Presentation for Chess Game


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.


Solution

  • 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;
    }