private Direction?FindNonDiagonalNeighbour(IGame game, GridPoint center, BimaruValueConstraint constraint) { foreach (var direction in Directions.GetNonDiagonalDirections()) { var pointInDirection = center.GetNextPoint(direction); if (constraint.IsSatisfiedBy(game.Grid[pointInDirection])) { return(direction); } } return(null); }
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; } } }
/// <summary> /// Whether the constraint allows the Bimaru value. Note that all /// constraints allow the value UNDETERMINED as the constraint /// can still be fullfilled in the future. /// </summary> public static bool DoesAllow(this BimaruValueConstraint constraint, BimaruValue value) { return(constraint.IsSatisfiedBy(value) || value == BimaruValue.UNDETERMINED); }