Ejemplo n.º 1
0
        /// <summary>
        /// True, if the given value and its neighbour value in the given direction are compatible.
        /// </summary>
        public static bool IsCompatibleWith(this BimaruValue value, Direction direction, BimaruValue neighbourValue)
        {
            BimaruValueConstraint constraintToNeighbour = value.GetConstraint(direction);
            BimaruValueConstraint constraintToThis      = neighbourValue.GetConstraint(direction.GetOpposite());

            return(constraintToNeighbour.DoesAllow(neighbourValue) && constraintToThis.DoesAllow(value));
        }
Ejemplo n.º 2
0
        public void FieldValueChanged(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
        {
            BimaruValue newValue = game.Grid[e.Point];

            foreach (Direction direction in Directions.GetAllDirections())
            {
                BimaruValueConstraint constraintInDirection = newValue.GetConstraint(direction);

                GridPoint   pointInDirection = e.Point.GetNextPoint(direction);
                BimaruValue valueInDirection = game.Grid[pointInDirection];

                // Skip set if constraint already satisfied
                if (!constraintInDirection.IsSatisfiedBy(valueInDirection))
                {
                    BimaruValue valueToSet = constraintInDirection.GetRepresentativeValue();
                    game.Grid[pointInDirection] = valueToSet;
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// True, if the constraint is satisfied by the Bimaru value.
 /// </summary>
 public static bool IsSatisfiedBy(this BimaruValueConstraint constraint, BimaruValue value)
 {
     return(constraint == BimaruValueConstraint.NO || constraint == value.GetConstraint());
 }
Ejemplo n.º 4
0
 /// <summary>
 /// True, if the field is any kind of ship.
 /// </summary>
 public static bool IsShip(this BimaruValue value)
 {
     return(value.GetConstraint() == BimaruValueConstraint.SHIP);
 }