16718 Players currently online!
Man vs. Machine - good luck!
Turn-based games at any time!
Vote for the best move to win!
Do you have what it takes?
Sharpen your tactical vision!
Get advice and game insights!
Learn from top players & pros!
View millions of master games!
Your virtual chess coach!
Perfect your opening moves!
Test your skills vs. computer!
Find the right private coach!
Can you solve it each day?
Bring it all together!
Beginners, start here!
Make friends & play team games!
News from the world of chess!
Search all Chess.com members!
Find local clubs & events!
Who's the best of your friends?
Read what members are saying!
I'm implementing a chess engine. My current issue is about -fast- generation the list of legal moves in the situation where the king is in check. During some quick thoughts about possible situations I found some "rules", which I would like -you- to have a look at. Maybe I have overlooked something...
== 1. Situations with 1 piece attacking the king (simple) ==
a) King may move to an unattacked neighboring field
b) King may take attacking piece, if unprotected
c) Any other piece (except king) may block (=move between) or take the attacking piece.
== 2. Situation with 2 pieces attacking the king (double attack) ==
a) King must move to another, neighboring unattacked field (which may also mean: taking an unprotected neighboring opponent piece; which can of course be one of the attackers)
While the 1. Situation is clear, I'm not 100%ly sure about the double attack scenario. My "proof" is like the following: taking only one attacker (not using the king) leaves the king in check (=> other attacker). AND: Blocking two attacks at the king with one figure is not possible. Reason: The two attackers must attack from different directions (else one attacker would block the other one's attack).
Rule Next: More than two attacks at the king aren't possible (such a position is not reachable by legal moves). As the 1. king must have been -not- in check before the opponents move -and- 2. at most the last moved piece and one additional piece (which's attack was blocked by the last moved piece before) may start to attack a king during one move. Reason: one piece (last moved one) may only unblock one attack, because attacks must come from different directions or one pieces would block the other.
What do you think about that? Am I correct? Any mistakes?
Thanks for checking...
You are correct that in the case of a double attack on the king, the king must move.
True. I concur, etc.
To your first list I would say, item b is unnecessary -- it is a part of rule a) the king may move to an unattacked field (if that happens to involve capturing the piece giving check, well that's just gravvy.) And rule c should be made into two slightly expanded rules:
b: "interposition" a piece may move to block the check so long as that move does not expose the king to check
c: "capture" a piece may move to capture the piece giving check so long as that move does not expose the king to check
@Kingpatzer: Thanks for having a look at it...
@JG27Pyth: I also thank you. Yes rule "b)" can be put together with "a)". Spliting in "interposition" and "capture" is actually not needed for my case.
My engine currently generates moves for all pieces when placed on the board. These move lists are updated when interfering pieces are placed on the board (or are removed from it). Also attacked fields are tracked for white and black pieces seperated and also pinned pieces are detected (rook, bishop, queen attacked pieces with king behind with no obstacles between). The number of pieces attacking the king is counted; also the first attacking piece will store the "way" between it and the kind + its own position. ((in the end it will actually not be a list, but some quicker processing. But for now this explanation should do...)).
The legal move list is then combined as following:
1. If king not attacked: Combine the move lists of all pieces (of the side on the move) which are not pinned.
2. If king is attacked twice: only do king moves.
3. If king is attacked only once: combine king moves + all moves (including exchange moves) of pieces (except pinned ones) to positions in the position list which was saved by the attacking pieces.
If the combined move list is empty:
1. if king is attacked: mate
2. if king is not attacked: stale mate
Using these quick incremental updates I hope to be able to gain some speedup in comparison to engines that rebuild their entire move list at every single move. I think this method is usually avoid because of it's complexity... which could introduce a lot of errors during calculations. But once it works stable, it should work fine.
Who is better Paul Morphy or Magnus Carlsen
by HonzaZvolsky a few minutes ago
Why place the night here in QGD
by ghostofmaroczy a few minutes ago
Chess Books for Beginner?
by alec849 a few minutes ago
What is Seblebs real rating?
by TheGreatOogieBoogie 4 minutes ago
why e4 is better than d4.
by DelCheMethod 4 minutes ago
12/11/2013 - Topalov-Kramnik, Dortmund 1996
by eltodesukane 4 minutes ago
Who is the mysterious GM Phoenix?
by Addicted-to-Chess97 5 minutes ago
What's the best way to study tactics
by DunnoItAll 5 minutes ago
Why hasn't Ivanov been banned yet?
by bigpoison 11 minutes ago
London Chess Classic - Super 16 Rapid 2013
by MSC157 13 minutes ago
Why Join | Chess Topics |
Help & Support |
© 2013 Chess.com
• Chess - English
We are working hard to make Chess.com available in over 70 languages. Check back over the year as we develop the technology to add more, and we will try our best to notify you when your language is ready for translating!