Skip to content

Commit 2813c62

Browse files
authored
Merge pull request #39 from ChessCom/revert-38-AM/CV-142681-Chess-Game-Do-not-allow-pieces-in-rook-position-to-castle
Revert "CV-142681 Chess-Game Do not allow pieces in rook position to castle"
2 parents da114f8 + 567fad2 commit 2813c62

File tree

2 files changed

+11
-54
lines changed

2 files changed

+11
-54
lines changed

Tests/ChessGameTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,6 @@ public function testBlankBoardFen()
7171
$this->assertEquals('8/8/8/8/8/8/8/8 w KQkq - 1 1', $this->game->renderFen());
7272
}
7373

74-
public function testCastlingForbiddenIfNotRook()
75-
{
76-
$startFen = 'q3k2q/pbpqppbp/1pnp1np1/8/8/1PNP1NP1/PBPQPPBP/Q3K2Q w KQkq - 2 9';
77-
$this->game->resetGame($startFen);
78-
79-
self::assertFalse($this->game->canCastleKingside());
80-
self::assertFalse($this->game->canCastleQueenside());
81-
82-
$this->game->moveSAN('e3');
83-
84-
self::assertFalse($this->game->canCastleKingside());
85-
self::assertFalse($this->game->canCastleQueenside());
86-
87-
$startFen = 'r3k2q/pppppppp/8/8/8/8/PPPPPPPP/Q3K2R w KQkq - 0 1';
88-
$this->game->resetGame($startFen);
89-
90-
self::assertTrue($this->game->canCastleKingside());
91-
self::assertFalse($this->game->canCastleQueenside());
92-
93-
$this->game->moveSAN('e3');
94-
95-
self::assertFalse($this->game->canCastleKingside());
96-
self::assertTrue($this->game->canCastleQueenside());
97-
98-
$startFen = 'q3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2Q w KQkq - 0 1';
99-
$this->game->resetGame($startFen);
100-
101-
self::assertFalse($this->game->canCastleKingside());
102-
self::assertTrue($this->game->canCastleQueenside());
103-
104-
$this->game->moveSAN('e3');
105-
106-
self::assertTrue($this->game->canCastleKingside());
107-
self::assertFalse($this->game->canCastleQueenside());
108-
}
109-
11074
public function testCastlingBlackFromTheKingSide()
11175
{
11276
$startFen = 'rnbqk2r/pppp1ppp/5n2/2b1p3/P1P1P1P1/8/1P1P1P1P/RNBQKBNR b KQkq a3 0 4';

src/Chess/Game/ChessGame.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,30 +2193,23 @@ 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-
22022196
if ($splitFen[2] != '-') {
22032197
for ($i = 0; $i < 4; $i++) {
22042198
if ($i >= strlen($splitFen[2])) {
22052199
continue;
22062200
}
2207-
22082201
switch ($splitFen[2][$i]) {
22092202
case 'K' :
2210-
$this->_WCastleK = $wr1 === 'h1' || $wr2 === 'h1';
2203+
$this->_WCastleK = true;
22112204
break;
22122205
case 'Q' :
2213-
$this->_WCastleQ = $wr1 === 'a1' || $wr2 === 'a1';
2206+
$this->_WCastleQ = true;
22142207
break;
22152208
case 'k' :
2216-
$this->_BCastleK = $br1 === 'h8' || $br2 === 'h8';
2209+
$this->_BCastleK = true;
22172210
break;
22182211
case 'q' :
2219-
$this->_BCastleQ = $br1 === 'a8' || $br2 === 'a8';
2212+
$this->_BCastleQ = true;
22202213
break;
22212214
default:
22222215
return $this->raiseError(self::GAMES_CHESS_ERROR_FEN_CASTLEWRONG,
@@ -3621,8 +3614,8 @@ public function rollbackTransaction()
36213614
public function isBishop($pieceName)
36223615
{
36233616
return $pieceName[1] == 'B' ||
3624-
($pieceName[1] == 'P' &&
3625-
$this->_pieces[$pieceName][1] == 'B');
3617+
($pieceName[1] == 'P' &&
3618+
$this->_pieces[$pieceName][1] == 'B');
36263619
}
36273620

36283621
/**
@@ -3638,8 +3631,8 @@ public function isBishop($pieceName)
36383631
public function isRook($pieceName)
36393632
{
36403633
return $pieceName[1] == 'R' ||
3641-
($pieceName[1] == 'P' &&
3642-
$this->_pieces[$pieceName][1] == 'R');
3634+
($pieceName[1] == 'P' &&
3635+
$this->_pieces[$pieceName][1] == 'R');
36433636
}
36443637

36453638
/**
@@ -3655,7 +3648,7 @@ public function isRook($pieceName)
36553648
public function isPawn($pieceName)
36563649
{
36573650
return $pieceName[1] == 'P' &&
3658-
$this->_pieces[$pieceName][1] == 'P';
3651+
$this->_pieces[$pieceName][1] == 'P';
36593652
}
36603653

36613654
/**
@@ -3681,8 +3674,8 @@ public function isKing($pieceName)
36813674
public function _isKnight($pieceName)
36823675
{
36833676
return $pieceName[1] == 'N' ||
3684-
($pieceName[1] == 'P' &&
3685-
$this->_pieces[$pieceName][1] == 'N');
3677+
($pieceName[1] == 'P' &&
3678+
$this->_pieces[$pieceName][1] == 'N');
36863679
}
36873680

36883681
/**

0 commit comments

Comments
 (0)