@@ -2193,23 +2193,30 @@ public function _parseFen($fen)
21932193 $ this ->_WCastleK = false ;
21942194 $ this ->_BCastleQ = false ;
21952195 $ this ->_BCastleK = false ;
2196+
2197+ $ wr1 = $ this ->getPiece ('WR1 ' );
2198+ $ wr2 = $ this ->getPiece ('WR2 ' );
2199+ $ br1 = $ this ->getPiece ('BR1 ' );
2200+ $ br2 = $ this ->getPiece ('BR2 ' );
2201+
21962202 if ($ splitFen [2 ] != '- ' ) {
21972203 for ($ i = 0 ; $ i < 4 ; $ i ++) {
21982204 if ($ i >= strlen ($ splitFen [2 ])) {
21992205 continue ;
22002206 }
2207+
22012208 switch ($ splitFen [2 ][$ i ]) {
22022209 case 'K ' :
2203- $ this ->_WCastleK = true ;
2210+ $ this ->_WCastleK = $ wr1 === ' h1 ' || $ wr2 === ' h1 ' ;
22042211 break ;
22052212 case 'Q ' :
2206- $ this ->_WCastleQ = true ;
2213+ $ this ->_WCastleQ = $ wr1 === ' a1 ' || $ wr2 === ' a1 ' ;
22072214 break ;
22082215 case 'k ' :
2209- $ this ->_BCastleK = true ;
2216+ $ this ->_BCastleK = $ br1 === ' h8 ' || $ br2 === ' h8 ' ;
22102217 break ;
22112218 case 'q ' :
2212- $ this ->_BCastleQ = true ;
2219+ $ this ->_BCastleQ = $ br1 === ' a8 ' || $ br2 === ' a8 ' ;
22132220 break ;
22142221 default :
22152222 return $ this ->raiseError (self ::GAMES_CHESS_ERROR_FEN_CASTLEWRONG ,
@@ -3614,8 +3621,8 @@ public function rollbackTransaction()
36143621 public function isBishop ($ pieceName )
36153622 {
36163623 return $ pieceName [1 ] == 'B ' ||
3617- ($ pieceName [1 ] == 'P ' &&
3618- $ this ->_pieces [$ pieceName ][1 ] == 'B ' );
3624+ ($ pieceName [1 ] == 'P ' &&
3625+ $ this ->_pieces [$ pieceName ][1 ] == 'B ' );
36193626 }
36203627
36213628 /**
@@ -3631,8 +3638,8 @@ public function isBishop($pieceName)
36313638 public function isRook ($ pieceName )
36323639 {
36333640 return $ pieceName [1 ] == 'R ' ||
3634- ($ pieceName [1 ] == 'P ' &&
3635- $ this ->_pieces [$ pieceName ][1 ] == 'R ' );
3641+ ($ pieceName [1 ] == 'P ' &&
3642+ $ this ->_pieces [$ pieceName ][1 ] == 'R ' );
36363643 }
36373644
36383645 /**
@@ -3648,7 +3655,7 @@ public function isRook($pieceName)
36483655 public function isPawn ($ pieceName )
36493656 {
36503657 return $ pieceName [1 ] == 'P ' &&
3651- $ this ->_pieces [$ pieceName ][1 ] == 'P ' ;
3658+ $ this ->_pieces [$ pieceName ][1 ] == 'P ' ;
36523659 }
36533660
36543661 /**
@@ -3674,8 +3681,8 @@ public function isKing($pieceName)
36743681 public function _isKnight ($ pieceName )
36753682 {
36763683 return $ pieceName [1 ] == 'N ' ||
3677- ($ pieceName [1 ] == 'P ' &&
3678- $ this ->_pieces [$ pieceName ][1 ] == 'N ' );
3684+ ($ pieceName [1 ] == 'P ' &&
3685+ $ this ->_pieces [$ pieceName ][1 ] == 'N ' );
36793686 }
36803687
36813688 /**
0 commit comments