Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to code the chess stalemate rule ?

Tags:

chess

I'm trying to write a chess game and find that I cannot find solutions to find a stalemate situation. I'm trying to google, but can't find anything. Is there a well-known algorithm or something?

like image 332
Vbif Avatar asked Oct 31 '11 06:10

Vbif


People also ask

How do you force a stalemate in chess?

Stalemate is a tie game. Also known as a Draw. 3 ways to stalemate: insufficient material (not enough firepower), no legal moves, and three-fold repetition. Well, there's one more – 50 king moves with no other legal moves – but this almost never occurs outside of scholastic tournaments.

What is the 13 move stalemate in chess?

It's automatic if you press the button and it is a threefold (or more) repetition. Me and aparently OP as well at one point or another were told that once the last piece before the King, was captured, the opponent has only 13 moves, 15 in my case, to checkmate, or it is a draw.

What are the rules for stalemate?

Just like with Checkmate, in a Stalemate the King cannot move—he has no Safe Squares. In fact, a Stalemate happens when there are no legal moves, just like Checkmate. The only difference is that since the King isn't threatened, the attacker can't claim a win and the game is declared a Draw!

Is there a 15 move rule in chess?

There is no 15 move rule in standard chess.


1 Answers

Your move generator will be one of two different designs;

  • either it checks for legality while generating the moves
  • or you generate all possible moves and remove those that are illegal afterwards.

The former is better as it doesn't need post-processing.

A stalemate condition is simply one where there are no legal moves and the moving-side's king is not in check. A checkmate condition is one where there are no legal moves but the moving-side's king is in check.

In other words if you've figured out how to detect check and checkmate, you've already got everything necessary to detect stalemate.

like image 91
trojanfoe Avatar answered Sep 30 '22 13:09

trojanfoe