There’s something profound here about how the very natural conventions in Chess (“If you did that, you’d lose, so I’d rather we continue playing”) have redefined “valid” in a way that is surprisingly hard to re-implement with code.
You can make illegal moves in over the board chess, and sometimes it's advantageous to do so. E.g. In blitz chess an invalid move is an immediate loss. So, if you're going to lose anyway, you can make an invalid move hoping your opponent doesn't take the time to notice. One common one is to move your king next to your opponent's king, putting their king in check, if they don't call you on it, and don't move their king out of check, they lose. Unofficially, this is considered part of the game in blitz, but is considered unsportsmanlike in long games (where it's not an immediate loss).
From memory it wasn't so long ago that the laws of chess "allowed" you to play an illegal move to cause a checkmate (e.g. Qd1xf7 mate). Your opponent would say "hey that's an illegal move, take it back". You could then say "according to this rule, taking back illegal moves can only be done during a game, and according to this other rule, checkmate immediately ends the game".
Note that it can be discovered during a game that a move several turns ago was actually illegal, and the board should be returned to that position (and times adjusted). I had this happen to me once.
As a former USCF tournament director, I can say this is not true. Rule 13A - "The player who checkmates the opponent king, providing the mating move is legal, wins the game."
Additionally, there are many contradictory rules that can't all be applied, so there is a lot of room for the tournament director to apply the rules according to the spirit of the game rather than the word of the law.
Is that... true? Are there tournament rules that say that? I'm not much of an OTB player, but this strikes me as somewhat against the spirit of the game. I will freely admit that I don't play blitz unless it's on a computer (I hate chess clocks) and computers don't allow illegal moves, but I would be very surprised if tournaments operated like this. Even small, local tournaments.
I remember reading about a serious tournament game where somebody castled twice. Nobody noticed during the game. I wonder how many computer databases allow that game to be entered.
Longer games go by FIDE's "Laws of Chess" which has a section 7 called "Irregularities" that indeed specifies the behavior if you accidentally knock over pieces or the game board falls over or you make an illegal move (moving away a piece that was keeping you from check etc).
Resolving irregularities does require your opponent to notice the irregularity and bring it to the attention of the referee.
It always struck me as odd that the checkmate definition should be so (relatively) complicated. A much simpler definition is "you lose if the opponent captures your king". A checkmate is just a situation where you can't avoid getting your king captured. If someone doesn't notice their king is on check, then they could lose the next move. After you pass the beginner phase, this will almost never happen to you anyway, so most games will end the same way: checkmate or losing because of time.
When I was in school, we used to play blitz like that. You lost track of your king, boom, you're dead
It is very easy to implement with code. Chess computers are some of the first well-known computer programs (see, for example, Deep Blue).
What is difficult is adapting chess's rules to this analog environment. It would be similarly difficult if you played this way with a real chess set in the real world, has nothing to do with code.
You don't actually have infinitely many moves available in analog chess since you can only click on a pixel. But while check should be doable in reasonable time, checkmate / stalemate would be expensive to compute since you have to check every possible move of yours (not just with the king, but with other pieces that could interpose as well) and then check every possible opponent's move in response to each of your moves to see if the king will be in check in the resulting positions.
you can’t represent the real plane on a computer. you can only have a limited amount of precision that effectively results in very dense grid, but a grid nonetheless
This is a classic example of something that should be fixed point, not floating point. Just represent positions internally as an integer between 0 and some large maximum. You could use the number of screen pixels, or a larger value if you want to allow e.g. precise moves by zooming in.
You stared real numbers are not representable, but specified “on computers”. Is there some medium they can be represented upon? Math papers is my only guess - but I read those on computers :)