Exemple #1
0
        private void OnPieceMoved(PieceMoveInfo move)
        {
            var colorControlList            = _controlCardinality[move.MovedPiece.Color];
            var previouslyControlledSquares = _control[move.MovedPiece.Color][move.MovedPiece];
            var newControlledSquares        = move.MovedPiece.GetControlledSquares(_board)
                                              .Select(coordinate => _board[coordinate]);

            RemovePreviousControlledSquares(move.MovedPiece, previouslyControlledSquares);
            AddNewControlledSquares(move.MovedPiece, newControlledSquares);
            if (move.StartingSquare != move.EndingSquare)
            {
                RecalculateControlOnInterfearingPieceMoved(move);
            }

            ResetSquaresControl();
        }
Exemple #2
0
        private void RecalculateControlOnInterfearingPieceMoved(PieceMoveInfo move)
        {
            var controllingPieces = _piecesControlDict[move.StartingSquare];

            foreach (var controllingPiece in controllingPieces.Where(p => !p.Captured).ToList())
            {
                OnPieceMoved(new PieceMoveInfo(controllingPiece, move.StartingSquare, move.StartingSquare));
            }

            if (!move.IsCapture)
            {
                controllingPieces = _piecesControlDict[move.EndingSquare];
                foreach (var controllingPiece in controllingPieces.Where(p => !p.Captured).ToList())
                {
                    OnPieceMoved(new PieceMoveInfo(controllingPiece, move.EndingSquare, move.EndingSquare));
                }
            }
        }
Exemple #3
0
 private void MovePiece(PieceMoveInfo move)
 {
     _position[move.EndingSquare.Coordinate].Piece   = move.MovedPiece;
     _position[move.StartingSquare.Coordinate].Piece = null;
 }