private bool TraceSub(Cell tracingCell, StoneType putStoneType, Position.Direction dir, ActionForSandwichedStoneDelegate action)
        {
            if (tracingCell == null)
            {
                return(false);
            }

            if (tracingCell.Stone == null)
            {
                return(false);
            }

            if (putStoneType.Equals(tracingCell.Stone))
            {
                return(true);
            }

            var neighberCell = board.GetNeighberCell(tracingCell.Position, dir);

            bool isSandwiched = TraceSub(neighberCell, putStoneType, dir, action);

            if (isSandwiched)
            {
                action(tracingCell);
            }

            return(isSandwiched);
        }
Exemple #2
0
        public Cell GetNeighberCell(Position position, Position.Direction direction)
        {
            if (!IsValidRange(position))
            {
                throw new ArgumentOutOfRangeException("Invalid position");
            }

            var neighberPosition = new Position(position.X + direction.dX, position.Y + direction.dY);

            if (!IsValidRange(neighberPosition))
            {
                return(null);
            }

            return(Cell(neighberPosition));
        }