79481802

Date: 2025-03-03 18:19:53
Score: 0.5
Natty:
Report link

Some of the trickiest code involves checks and checkmates, and stalemates, promotions

Write some separate independent code that works as a chess engine. That code can be asked questions about various board positions from the code managing Tiles/Grid/Board

For example if the chess engine can't find any legal move that gets the player whose turn it is out of check, that's checkmate. Similar for stalemate when the king is not in check

Likewise, for castling, en passant, don't allow them if the chess engine hasn't

To get started you could borrow an open source chess engine or load a binary. There is a standard interface for loading chess engines that works in several programming languages, probably all the popular ones.

Then if you need some extra information that you can't get either customize an open source one or write your own.

I would argue that you should start out architecting it around the chess engine first. That way you make the chess engine do most of the work. All your UI layer has to do is refuse moves that are not on the list of legal moves.

I found this out the hard way.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Kevin Baker