This might be used in my "Determine From Square" but thought I'd create a new thread. Anyways, I haven't created a "Is Check" method yet but I'm thinking to check for pins, it would be easier to go ahead and make the intened move, then check to see if the King is in check. So really there is no "Is Pinned" check persee. If the King is in check after the move then the move can be retracted.
Am I thinking correctly here. Hopefully Im not missing anything. I'm pretty close to completing my routines. Just alittle more insight to the "Is InCheck" is needed.
This is only for a game viewer. Not an actual live game.
Thanks much,
David
Is King in Check
Moderators: hgm, Rebel, chrisw
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Is King in Check
Actually I think this would work for any type of game. If one tries to drag a piece that is pinned to another square, that piece would simply go back to the original square so I think by trying the actual move first would be fine.
Any comments would be appriciated.
David
Any comments would be appriciated.
David
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Is King in Check
Watch out for illegal castling moves, too. Castling is illegal if the king is in check before castling, or if the rook is attacked after castling (so the king went through check).
If efficiency is not an issue (which should be the case for a game viewer) then that's all for your legality test of a move: king not left in check, and move was not an illegal castling move.
You will need an "isInCheck" function anyway if your game viewer shall be able to detect checkmate or stalemate.
Sven
If efficiency is not an issue (which should be the case for a game viewer) then that's all for your legality test of a move: king not left in check, and move was not an illegal castling move.
You will need an "isInCheck" function anyway if your game viewer shall be able to detect checkmate or stalemate.
Sven
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: Is King in Check
I made some routines for legal move
"GetAttackersForSquare()" called with the kings position, this also returns
results for double check.
"DoesMoveIntercedeCheck()" to determine if a move will block the check, or capture the offending piece
If a piece is pinned I also look for moves in the cases of bishops, rooks and Queens that occur on the same file or diagonal, including the capture of the checking piece
"GetAttackersForSquare()" called with the kings position, this also returns
results for double check.
"DoesMoveIntercedeCheck()" to determine if a move will block the check, or capture the offending piece
If a piece is pinned I also look for moves in the cases of bishops, rooks and Queens that occur on the same file or diagonal, including the capture of the checking piece
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Is King in Check
Thanks for the info. Theres alot more to consider than I thought. Ill play around with a few things.
Thanks
Thanks