playing with fire!

this logic is obviously very tricky. what i do know is that u have to
account for chess960 where the pieces can be anywhere.

this is why you can either castle by moving your king to the final
destination square OR by moving it to the rook location.

if there was a bug in this logic, it would have been revealed by now in one
of our millions of games, so i doubt it is buggy. if it is, then i
challenge u to reproduce the bug on production



On Saturday, December 21, 2013, Ben Curtis wrote:

> In ChessGame.php:
>
> > @@ -3122,11 +3124,41 @@ function getPossibleKingMoves($square, $color = null, $returnCastleMoves = true)
> >          $ret = $this->_getKingSquares($square);
> >          if ($returnCastleMoves) {
> >              $castleret = $this->_getCastleSquares($square);
> > +            // verify castling is allowed to each square due to
> > +            // check rules (cannot move the king out of, through, or into check)
> > +            // and that no pieces exist between the rook and king
> > +            // http://en.wikipedia.org/wiki/Castling#Requirements
> > +            foreach ($castleret as $idx => $moveTo) {
> > +                list($colFrom,$row) = str_split($square);
> > +                list($colTo,$row) = str_split($moveTo);
> > +
> > +                // let's check for interfering pieces first, since that's less expensive
> > +                // find all the columns that are between the king and the rook
> > +                $betweenCols = array_slice(range($colFrom, $colTo > $colFrom ? 'g':'b'), 1);
> > +                foreach($traverseCols as $col) {
>
> Cut/paste error — thanks!
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/ChessCom/Chess-Game/pull/15/files#r8518051>
> .
>