This is only for on line chess lol. Over the board it would be hard to convince your opponent unless he has short term memory loss😳
How Does the chess algorithm know-Castling
Maybe the algorithm checks if you have moved the king and the rook in the game before validating castling.

Well, most junior chess players learn that if you move your king you lose the right to Castle. In on line chess I'm curious. I think you might be right. If you move your castle one move up and back it must remember that you now have also lost the right to castle

The question is.... How long does it remember.
In a hypothetical
If you move your king 10 times and back to the castling position. Does the algorithm remember. The algorithm also has to remember you have lost the right on the Queen side. But if you move your king side rook.... You still can castle on the Queen side. A lot to remember. I can't remember what I had for breakfast 3some days 😳😳

I have never seen a chess game where a rook is moved and then back to its original position and then a castling on the other side is attempted in on line chess or even on that side. One side legal the other side illegal move

Algorithm-wise, I don’t personally think it’s much of a mystery. But I do remember a GM game (Illescas-Kamsky, Manila 1990) where Black forgot he had moved his king (just three moves earlier) and tried to castle, the resulting touch move penalty leading to his defeat shortly afterwards.
That's not a mystery at all. Once you lose the right to castle, this is stored in a flag. It takes exactly on bit to store this information. You can also see it in the FEN. What's mysterious about that?

That's not a mystery at all. Once you lose the right to castle, this is stored in a flag. It takes exactly on bit to store this information. You can also see it in the FEN. What's mysterious about that?
+1 yeah
@aflfooty, I suspect that you're assuming that a chess position is entirely defined by the positions of the pieces. That's not the case.
It's a program: When the game starts, there is a variable associated with each side called something like "cancastle." it is set to TRUE. The first time you move your king, the program sets cancastle to FALSE. After that, you will never be able to castle. It's really simple

Yes..... In a sense I am suggesting that a chess position is defined by the positions of the pieces. If you have just the 2 rooks and King on the back row. Both sides are active for castling. If you move one rook you break the castling rule. Why should the algorithm then allow you to castle at all (On the other side). Break the castling rule at all and the algorithm should deny castling full stop. It's like with en passant. If you choose not to act on an en passant capture on the left side, why should you suddenly be able to on the other side with the same pawn. It should lose the right to. Anyway.... It is what it is I guess
Yes..... In a sense I am suggesting that a chess position is defined by the positions of the pieces. If you have just the 2 rooks and King on the back row. Both sides are active for castling. If you move one rook you break the castling rule. Why should the algorithm then allow you to castle at all (On the other side). Break the castling rule at all and the algorithm should deny castling full stop. It's like with en passant. If you choose not to act on an en passant capture on the left side, why should you suddenly be able to on the other side with the same pawn. It should lose the right to. Anyway.... It is what it is I guess
Well, you may suggest that, but it just isn't. So are the rules. That's why the FEN contains this extra information.
Well, computers are generally better than humans in remembering and calculating stuff.
It is quite trivial to mark castling as "done" and then check it later to validate the moves. Or you can loop through all the moves made every time you try to make a move (let's, say, typical game is about 50 moves, it's literally nothing for computers nowadays). It can be implemented in different ways, different chess programs can use different approaches.
BTW, castling is not the only move which you cannot get from the pieces position. En passant pawn capture is also valid only for 1 move and after that you cannot do it, so you have to take into account what was the last move.

One of the mysteries of life.
If you are in the castling position. Then you move your king instead.
Say you move it 3 times.
Then, finally you move your king back to its original position.
How does the chess gods remember you moved your king and can't castle.
You're using a computer to communicate nearly instantly with people from literally all around the planet, and you can't understand how anyone could write code that checks if castling is possible?

It's like someone sitting in the lobby of the Burj Khalifa wondering aloud how gingerbread houses are structurally possible.
You obviously know nothing about computers.
Nothing.

Here's some pseudo code.
Set castling kingside flag to 1
Set castling queenside flag to 1
If kingside rook moves then set kingside castle flag to 0
If queenside rook moves then set queenside castle flag to 0
If king moves then set kingside castle flag to 0 and set queenside castle flag to 0
If king tries to castle queenside then allow if queenside flag is 1, otherwise disallow
If king tries to castle kingside then allow if kingside flag is 1, otherwise disallow
> Both sides are active for castling. If you move one rook you break the castling rule. Why should the algorithm then allow you to castle at all (On the other side).
I don't know about FEN (probably the same, though), but in chess programs castling king-side and queen-side are stored separately for each side. I can literally show you how to check it out on chess.com.
I can show the values being stored at chess.com. At any moment of playing live chess, you can open JavaScript console and run this snippet:
document.querySelector('.board').__vue__.game.setup.castling
It will output which castling directions are available.
Screenshots
Before anyone has castled, it outputs "KQkq", where "K" means castling king-side for white, "Q" means castling queen-side for white, "k" for castling king-side for black and "q" for castling queen-side for black.
After white castled, it outputs "kq" — only castling for black is allowed.
After everyone castled, it outputs "-" that means no castling moves allowed.
Sorry for the long post, I hope it's useful 🙂
One of the mysteries of life.
If you are in the castling position. Then you move your king instead.
Say you move it 3 times.
Then, finally you move your king back to its original position.
How does the chess gods remember you moved your king and can't castle.