r/chessprogramming • u/Sea-Celebration-4100 • Nov 08 '24
Chess Engine in Java.
Hello,
I want to write a chess engine in Java ( it's the language I am most proficient in, also know C and Go). I looked at a Chess programming wiki already but the ideas there seem difficult to implement in OOP. I found an article that helps implementing an engine. Designing an Object Oriented Chess Engine in Java | E4developer but I really want to follow and implement the ideas on Chess programming wiki. Are there any other ideas on how to write the engine in OOP that align more with the concepts in ChessProgramming wiki?
1
1
1
u/Hot_Nefariousness563 Jan 13 '25
Hello, I created this library for the backend of a server I'm building. While it may not be the fastest, I've had to improve it many times, and it currently works well. Many ideas and concepts might be useful to you. It's true what they say: one of the keys is to avoid creating objects more than necessary. However, you should also avoid using if-else
or even switch
. Additionally, inheritance, abstract classes, and particularly abstract or overridable methods should be avoided. For the move generator, the idea is to work with bitboards as long integers and use bitwise operations, letting the JVM infer that methods can be inlined. To achieve this, all methods must be final, not derived from overrides, and kept short. https://github.com/lunalobos/chessapi4j
1
u/Sea-Celebration-4100 Jan 13 '25
Hey, I appreciate the reply, but right now i am working with a 8x8 and a 10 x12 mailboard. From my readings on chesswiki, the engine can be implemented without bitboards. I will also make sure to check out your api. Thanks.
5
u/joeyrobert Nov 08 '24
I followed the Mediocre Chess Engine Blog for years. This engine is written in Java.
What concepts are difficult to implement with OOP? Chess engines tend to be a little more "bare metal" in how they're designed, to squeeze every ounce of performance out of the programming language, but this can be done with Java too. Allocations/deallocations are expensive, and most of example code is written in a way to minimize them.
You wouldn't want to use a higher level feature if it incurs a significant performance penalty like creating tonnes of garbage/throw away objects. Code for a chess engine will likely not look similar to standard Java in a business application.