예제 #1
0
        /// <summary>
        /// Constraint that a field value gives to the neighbour field in the given direction.
        /// </summary>
        public static BimaruValueConstraint GetConstraint(this BimaruValue value, Direction direction)
        {
            BimaruValueConstraint constraint = BimaruValueConstraint.NO;

            if (value.IsShip())
            {
                if (direction.GetDirectionType() == DirectionType.DIAGONAL)
                {
                    constraint = BimaruValueConstraint.WATER;
                }
                else if (value == direction.GetFirstShipValue())
                {
                    constraint = BimaruValueConstraint.SHIP;
                }
                else if (value != BimaruValue.SHIP_MIDDLE &&
                         value != BimaruValue.SHIP_UNDETERMINED)
                {
                    constraint = BimaruValueConstraint.WATER;
                }
            }

            return(constraint);
        }
예제 #2
0
 /// <summary>
 /// True, if a new field value does not contradict the old value.
 /// For example, the new value WATER would be incompatible with
 /// SHIP_UNDETERMINED. However, the new value SHIP_SINGLE would
 /// be compatible with SHIP_UNDETERMINED, as it further specifies it.
 /// </summary>
 public static bool IsCompatibleChangeTo(this BimaruValue oldValue, BimaruValue newValue)
 {
     return(oldValue == newValue ||
            oldValue == BimaruValue.UNDETERMINED ||
            (oldValue == BimaruValue.SHIP_UNDETERMINED && newValue.IsShip()));
 }