Creating a presentation for a chess game

I'm starting to make an 8 x 8 square board for playing Chess Game Assignment. However, I am wondering if there is anything to suggest a square, not a 2D array in Java.

one of the restrictions for assignment prohibits the use of a 2D array or the like. No AI except user control.

+4
source share
5 answers

You can use a one-dimensional array, say Figure [] board = new Figure[64] and make a simple getter / setter method to emulate two 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; } 
+7
source

You can use 1 dimensional array or ArrayList , and then divide by 8 and use the result and remainder to know which column and row you need to go to.

Then you can work the other way around to get the location in the array for the corresponding section of the checkerboard.

+3
source

You can also use the map:

 private Map<String, Figure> board = new HashMap<String, Figure>(); private String positionToString(int hor, int vert) { return hor + " " + vert; } public Figure get(int hor, int vert) { return board.get(positionToString(hor, vert)); } public void set(int hor, int vert, Figure fig) { board.put(positionToString(hor, vert), fig); } 
+2
source

I do not have working knowledge of Java, I play chess and program Delphi. I have no idea about Java bit manipulation capabilities.

But I suggest you research the structure of Bitboard and search the net for an open source engine based on this.

This is a common occurrence in the C ++ world.

+2
source

Perhaps you can avoid even creating a square in the first place?

An alternative way of representing a chessboard is simply a list of parts and their corresponding coordinates.

0
source

Source: https://habr.com/ru/post/1385492/


All Articles