News for hackers. Stuff that matters.
Re:I Made a Chess Library in Java by pgt on Thursday April 02, 2020 @06:39PM (#22764619)
When I was 17, I built a Java Chess AI for a school project called Chessmate. The AI couldn't castle or en passant, but it won a regional prize that got lost in the mail.

10 Years later, the code (which I had put on GitHub) made its way into a Minecraft mod called MineChess: http://petrustheron.com/posts/chessmate.html

Source code: https://github.com/theronic/chessmate

Re:I Made a Chess Library in Java by durbat on Thursday April 02, 2020 @04:47PM (#22763607)
You need to switch your data representation to 0x88 [1] or bitbords [2] to get anything performant. You won't get anywhere with a class hierarchy

[1] https://www.chessprogramming.org/0x88 [2] https://www.chessprogramming.org/Bitboards

Re:I Made a Chess Library in Java by thom on Thursday April 02, 2020 @05:50PM (#22764270)
If someone just wants a library to power a chess UI this isn't really necessary. Either way I'd suggest the author finish off the current implementation until they can get perft and other automated tests up and running first.

That said, chess programming is a _wonderful_ education in Computer Science, and you'll be following in the footsteps of so many great figures in the industry. Understanding bitboards and how to work with them can take you all the way from the bit-twiddling chapters of The Art of Computer Programming, right up to recent advances in CPU architecture and instruction sets. Learning how search works will teach you both very low techniques and high level heuristics in performance optimisation. And of course you can go all all the way up to recent advances in evaluation from deep learning.

Re:I Made a Chess Library in Java by reitzensteinm on Thursday April 02, 2020 @10:09PM (#22765777)
You need to consider the goals of a project before giving advice.
Re:I Made a Chess Library in Java by durbat on Friday April 03, 2020 @02:33AM (#22766758)
OP mentions chess AI and game analyzer. Those would benefit from an optimized data representation.
Re:I Made a Chess Library in Java by reitzensteinm on Friday April 03, 2020 @04:52AM (#22767388)
But both can also be written optimizing for simplicity and clarity at the cost of performance.

Competing with the state of the art is not an implicit goal for every project.

Re:I Made a Chess Library in Java by saagarjha on Thursday April 02, 2020 @05:13PM (#22763933)
Perhaps they don’t need anything performant? You don’t need a bitboard for everything. (They’re also not always performant.)
Re:I Made a Chess Library in Java by blackflame7000 on Thursday April 02, 2020 @06:17PM (#22764477)
Yea and you probably also need OpenCL or CUDA and several GPUs to get anything really “performant”. The basic OO model is good for its own purposes
Re:I Made a Chess Library in Java by voz_ on Thursday April 02, 2020 @05:37PM (#22764156)
If the API is well written, this is an implementation detail.
Re:I Made a Chess Library in Java by durbat on Friday April 03, 2020 @02:41AM (#22766799)
Well, it depends on the project goals. For a GUI app I can agree but good luck writing a chess engine where data representation is hidden behind an abstract interface.
Re:I Made a Chess Library in Java by blackflame7000 on Friday April 03, 2020 @06:02AM (#22767714)
Abstract as in using bit-boards or proper abstraction as in giving a clean interface to interact with a model and let the implementation worry about itself?
Re:I Made a Chess Library in Java by mk_chan on Friday April 03, 2020 @01:00AM (#22766411)
The first thing you'd want to implement is perft: https://www.chessprogramming.org/Perft_Results It actually doubles as a performance test(like it's name) and a debugging tool to verify that you can generate moves correctly by comparing your numbers vs the positions given on the website and a few large suites.

I'd encourage you to get involved with the passionate community at talkchess: http://talkchess.com/forum3/index.php

And join a small group on IRC at Freenode ##chessprogramming where we discuss chess AIs, libraries and often other games like Ataxx and Go.

I myself am an author of a chess library: https://github.com/Mk-Chan/libchess ! Great to see development for Java as well

Re:I Made a Chess Library in Java by koff3 on Thursday April 02, 2020 @05:57PM (#22764324)
There is also http://www.chesspresso.org/ which worked great for PGN and FEN processing.
Re:I Made a Chess Library in Java by WoodenChair on Thursday April 02, 2020 @08:22PM (#22765239)
Official author GitHub repository: https://github.com/BernhardSeybold/Chesspresso

Has had some very minor fixes since the last source forge version.

Re:I Made a Chess Library in Java by aaron_seattle on Thursday April 02, 2020 @10:17PM (#22765812)
Hats off to you for tackling such a hard problem. Coding chess is a beast.

I cut you this one issue, https://github.com/jaeheonshim/ChessBoard/issues/1

I think your castling logic is incomplete? Worth a double check.

Re:I Made a Chess Library in Java by johnathana on Thursday April 02, 2020 @06:36PM (#22764610)
You can check also my lib magnus4j for some ideas: https://github.com/johnathana/magnus4j
Re:I Made a Chess Library in Java by lspears on Thursday April 02, 2020 @09:44PM (#22765669)
I loved building my chess library and would encourage other developers to try it. It is large and complex enough to test your abilities. Building it in a idiomatic, testable, and performant way really encourages software engineering skills instead of just coding. I felt like I didn’t really write solid go code until I finished my chess library.

https://github.com/notnil/chess

Re:I Made a Chess Library in Java by nurettin on Thursday April 02, 2020 @05:48PM (#22764255)
As someone who has implemented online multiplayer tbs games before, this is exactly the kind of thing you would use at the backend.

However, you also need the same code running on the frontend in order to do validations before sending moves to the backend. That optimization helps distribute some server load and gets you immediate feedback. In Java's case, I'd use some java to js or java to kotlin to js transpilation.

Re:I Made a Chess Library in Java by Pmop on Thursday April 02, 2020 @09:30PM (#22765599)
Is performing chess validations that heavy, if you're serving ~10,000 games? (just asking for a friend)
Re:I Made a Chess Library in Java by nurettin on Friday April 03, 2020 @12:55AM (#22766385)
To do all validations and move suggesions on the server side causes data traffic for no reason. Not just cpu time. It is senseless.
Re:I Made a Chess Library in Java by nurettin on Friday April 03, 2020 @05:20AM (#22767517)
As a clarification, of course you will validate all moves on the server side and make sure client side state is consistent, but what I meant by validation is when you have to give every feedback from the server back to the client you will quickly find yourself in a ddos situation with so many players online.
Re:I Made a Chess Library in Java by dabei on Thursday April 02, 2020 @04:40PM (#22763502)
Nice, great to see more open source efforts on Chess. GitHub is down and I can’t quite tell what is the need you are trying to address with this library.
Re:I Made a Chess Library in Java by jaeheonshim on Thursday April 02, 2020 @04:53PM (#22763687)
GitHub is down at the worst possible moment for me... Hopefully they'll fix it up soon
Re:I Made a Chess Library in Java by jordiburgos on Friday April 03, 2020 @08:25AM (#22768470)
Could be nice to see the board.toString() with a Unicode representation of the board.

Edit: the comment text does not allow Unicode characters.

Re:I Made a Chess Library in Java by skocznymroczny on Friday April 03, 2020 @03:38AM (#22767022)
Interesting. What is the reason for starting a new project in Java if much better alternatives such as Rust or Kotlin exist?
Re:I Made a Chess Library in Java by tdons on Thursday April 02, 2020 @04:33PM (#22763404)
Cool, thanks for sharing. I'll check it out once github is back up :-)
Re:I Made a Chess Library in Java by suyash on Thursday April 02, 2020 @03:31PM (#22762739)
Awesome, I would encourage turn this into a actual chess game using JavaFX.
Re:I Made a Chess Library in Java by jaeheonshim on Thursday April 02, 2020 @04:04PM (#22763109)
That's a great idea, I'm going to look into creating an online chess game application soon!
Re:I Made a Chess Library in Java by Pmop on Thursday April 02, 2020 @09:33PM (#22765610)
Hey, yo! I was thinking doing the same. I was thinking in something with link sharing i.e. you create a game session and then get a link you can share with the second player and spectators.
Re:I Made a Chess Library in Java by onefuncman on Thursday April 02, 2020 @04:34PM (#22763417)
Good job, you crashed GitHub.