示例#1
0
        private bool ScanAreaPoints(AreaNumber areaNumber)
        {
            var areaPoints   = GetAreaPoints(areaNumber);
            var valuesInArea = areaPoints.Select(ap => ap.Value).ToList();

            var missingNumbers  = PossibleNumbers.Where(p => !valuesInArea.Contains(p)).ToList();
            var anyNumberSolved = false;

            foreach (var number in missingNumbers)
            {
                var numberPositions = FindPositionsForNumber(number);

                var numberPositionsX = numberPositions.Select(p => p.X).ToList();
                var numberPositionsY = numberPositions.Select(p => p.Y).ToList();

                var freePosition = areaPoints.Where(a => a.Value == null &&
                                                    !numberPositionsX.Contains(a.Position.X) &&
                                                    !numberPositionsY.Contains(a.Position.Y)).ToList();

                if (freePosition.Count() == 1)
                {
                    freePosition[0].Value = number;
                    anyNumberSolved       = true;
                }
            }

            return(anyNumberSolved);
        }
示例#2
0
        private List <Point> GetAreaPoints(AreaNumber areaNumber)
        {
            var areaStartingPosition = this.Areas.Single(area => area.AreaPosition == areaNumber).StartPosition;

            return(SudokuMatrix.Where(p => p.Position.X >= areaStartingPosition.X &&
                                      p.Position.X < areaStartingPosition.X + 3 &&
                                      p.Position.Y >= areaStartingPosition.Y &&
                                      p.Position.Y < areaStartingPosition.Y + 3).ToList());
        }
示例#3
0
        /// <summary>
        /// Returns true if ServiceArea instances are equal
        /// </summary>
        /// <param name="other">Instance of ServiceArea to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ServiceArea other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     MinistryServiceAreaID == other.MinistryServiceAreaID ||
                     MinistryServiceAreaID.Equals(other.MinistryServiceAreaID)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     District == other.District ||
                     District != null &&
                     District.Equals(other.District)
                 ) &&
                 (
                     StartDate == other.StartDate ||
                     StartDate.Equals(other.StartDate)
                 ) &&
                 (
                     AreaNumber == other.AreaNumber ||
                     AreaNumber != null &&
                     AreaNumber.Equals(other.AreaNumber)
                 ) &&
                 (
                     EndDate == other.EndDate ||
                     EndDate != null &&
                     EndDate.Equals(other.EndDate)
                 ));
        }
示例#4
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();
                hash = hash * 59 + MinistryServiceAreaID.GetHashCode();

                if (Name != null)
                {
                    hash = hash * 59 + Name.GetHashCode();
                }

                if (District != null)
                {
                    hash = hash * 59 + District.GetHashCode();
                }

                hash = hash * 59 + StartDate.GetHashCode();

                if (AreaNumber != null)
                {
                    hash = hash * 59 + AreaNumber.GetHashCode();
                }

                if (EndDate != null)
                {
                    hash = hash * 59 + EndDate.GetHashCode();
                }

                return(hash);
            }
        }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data
 /// structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(AreaNumber.GetHashCode() + GroupNumber.GetHashCode() + SerialNumber.GetHashCode());
 }
 /// <summary>
 /// Determines if two SocialSecurityNumber objects are equal.
 /// </summary>
 /// <param name="other">The other number.</param>
 /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns>
 public bool Equals(SocialSecurityNumber other)
 {
     return(AreaNumber.Equals(other.AreaNumber) && GroupNumber.Equals(other.GroupNumber) && SerialNumber.Equals(other.SerialNumber));
 }
示例#7
0
 public Area(AreaNumber areaPosition, Position startPosition)
 {
     this.AreaPosition  = areaPosition;
     this.StartPosition = startPosition;
     this.IsSolved      = false;
 }