Beispiel #1
0
        private static void CheckCaptureVertical(IBoard board, ISquare originSquare, Square.NeighborDirection direction)
        {
            if (direction == Square.NeighborDirection.Left || direction == Square.NeighborDirection.Right)
            {
                throw new ArgumentException();
            }

            ISquare targetSquare = originSquare.Neighbors[direction];

            if (targetSquare != null && targetSquare.IsOccupied && targetSquare.Occupant.Player != originSquare.Occupant.Player && !targetSquare.Occupant.IsKing)
            {
                IPiece  deadPiece      = null;
                ISquare oppositeSquare = targetSquare.Neighbors[direction];
                if (oppositeSquare != null && oppositeSquare.IsOccupied && oppositeSquare.Occupant.Player == originSquare.Occupant.Player)
                {
                    deadPiece = targetSquare.Occupant;
                }
                else if (oppositeSquare == null && (targetSquare.Right == null || targetSquare.Left == null))
                {
                    if ((targetSquare.Right == null && targetSquare.Left.Occupant != null && targetSquare.Left.Occupant.Player == originSquare.Occupant.Player) ||
                        (targetSquare.Left == null && targetSquare.Right.Occupant != null && targetSquare.Right.Occupant.Player == originSquare.Occupant.Player))
                    {
                        deadPiece = targetSquare.Occupant;
                    }
                }

                if (deadPiece != null)
                {
                    deadPiece.Location    = null;
                    targetSquare.Occupant = null;
                    board.Pieces.Remove(deadPiece);
                }
            }
        }
Beispiel #2
0
        public static List <Tuple <IPiece, ISquare> > ListValidMoves(IPiece piece, ISquare origin, Square.NeighborDirection direction)
        {
            List <Tuple <IPiece, ISquare> > validMoves = new List <Tuple <IPiece, ISquare> >();
            ISquare nextSquare = origin.Neighbors[direction];

            while (nextSquare != null && !nextSquare.IsOccupied)
            {
                if (piece.IsKing || !nextSquare.IsRestricted)
                {
                    validMoves.Add(new Tuple <IPiece, ISquare>(piece, nextSquare));
                }

                nextSquare = nextSquare.Neighbors[direction];
            }

            return(validMoves);
        }