-1

I am in the process of building a chess engine in Java using bitboards. I know C/C++ is more optimal for this but I have no knowledge of either so I'd rather attempt to do it with Java for now. I have two questions about storing generated moves.

  1. With regard to the format in which the moves themselves are stored, I've read about Stockfish's 16 bit format (from square, to square, promotion piece, special move) and I've also looked through the source code of CuckooChess (written in Java, ~2600 on CCRL) that have a Move class designated to hold all characteristics of a move in an object. What are the tradeoffs between either method, or any other method not mentioned?
  2. I'd like to store legal moves in an array, but I wouldn't be able to just append a move to the end of the array. The logical alternative would be using an ArrayList; however I'm also worried that the larger memory requirement of ArrayList would cause some issues. Would I store legal moves in an array, arrayList, or another structure, or are these considerations insignificant?

1 Answer 1

2

My answer is not about chess, just as your question only superficially is about chess. The questions you ask are really about other things, and you may be better advised to try to address that part of the question in forums dedicated to Java.

If you haven't read Bloch's book Effective Java, do so, as you are sure to learn a lot about basic Java efficiency that will be important as well, perhaps even more so than the things you ask about here.

Question 1. The considerations are internal to your chess code, and you 'should' select a representation that makes it inexpensive to perform the operations you need: create moves, access the constituent parts of a move, etc. Unless you are fairly experienced you can't select the 'right' representation without knowing what your code needs. Choose something, and wrap in in your own class to make it easy to change implementation later without changing the class interface.

(Added: When you have working code, you can relatively easily replace your initial implementation with a different one, and see how that affects processing time, nodes per second, or other significant measures.)

Question 2. Create a suitable container class with the accessors etc that you require in your program. Then implement it by using an ArrayList, say. If you find that it isn't efficient enough replace the implementation with something better. But that's part of the improve/optimize phase of the development cycle, not the design phase. (From my own experience, I rarely find important inefficiencies in Java standard classes, I usually find the important problems in the code I have written myself.)

Programming (not only coding) is a large part eating pain: coding, discovering mistakes, retracing, and repeating; the more so the less experience you have. Accept that half of your initial design decisions will be sub-optimal, and don't press for optimal implementation too early.

Not the answer you're looking for? Browse other questions tagged or ask your own question.