Beispiel #1
0
        public void FieldValueChanged(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
        {
            DetermineFieldValue(game, e.Point);

            foreach (var direction in Directions.GetNonDiagonalDirections())
            {
                DetermineFieldValue(game, e.Point.GetNextPoint(direction));
            }
        }
Beispiel #2
0
        private static void CheckIsChangeValid(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
        {
            BimaruValue newValue = game.Grid[e.Point];

            if (!game.IsValid || !e.OriginalValue.IsCompatibleChangeTo(newValue))
            {
                throw new InvalidFieldValueChange();
            }
        }
        public void FieldValueChanged(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
        {
            if (AreTargetShipFieldsSetInRow(game, e.Point.RowIndex))
            {
                game.Grid.FillUndeterminedFieldsRow(e.Point.RowIndex, BimaruValueConstraint.WATER);
            }

            if (AreTargetShipFieldsSetInColumn(game, e.Point.ColumnIndex))
            {
                game.Grid.FillUndeterminedFieldsColumn(e.Point.ColumnIndex, BimaruValueConstraint.WATER);
            }
        }
        public void FieldValueChanged(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
        {
            if (AreOnlyShipFieldsMissingRow(game, e.Point.RowIndex))
            {
                game.Grid.FillUndeterminedFieldsRow(e.Point.RowIndex, BimaruValueConstraint.SHIP);
            }

            if (AreOnlyShipFieldsMissingColumn(game, e.Point.ColumnIndex))
            {
                game.Grid.FillUndeterminedFieldsColumn(e.Point.ColumnIndex, BimaruValueConstraint.SHIP);
            }
        }
Beispiel #5
0
        private void UpdateNumberOfShipsPerLength(FieldValueChangedEventArgs <BimaruValue> e)
        {
            foreach (int shipLength in DetectShips(e.Point, e.OriginalValue))
            {
                numberOfShipsPerLength[shipLength]--;
            }

            BimaruValue newValue = GetFieldValueNoCheck(e.Point);

            foreach (int shipLength in DetectShips(e.Point, newValue))
            {
                numberOfShipsPerLength[shipLength]++;
            }
        }
Beispiel #6
0
        private void UpdateNumberOfFields(FieldValueChangedEventArgs <BimaruValue> e)
        {
            int change;
            var newValue = this[e.Point];

            change = GetChangeInNumberOfFields(e.OriginalValue.IsShip(), newValue.IsShip());
            numberOfShipFieldsPerRow[e.Point.RowIndex]       += change;
            numberOfShipFieldsPerColumn[e.Point.ColumnIndex] += change;

            change = GetChangeInNumberOfFields(e.OriginalValue == BimaruValue.UNDETERMINED, newValue == BimaruValue.UNDETERMINED);
            numberOfUndeterminedFieldsPerRow[e.Point.RowIndex]       += change;
            numberOfUndeterminedFieldsPerColumn[e.Point.ColumnIndex] += change;

            change = GetChangeInNumberOfFields(!e.OriginalValue.IsFullyDetermined(), !newValue.IsFullyDetermined());
            numberOfNotFullyDeterminedFields += change;
        }
Beispiel #7
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;
                }
            }
        }
Beispiel #8
0
 public void FieldValueChanged(IGame game, FieldValueChangedEventArgs <BimaruValue> e)
 {
     ChangedEventArgs.Add(e);
 }
Beispiel #9
0
 protected override void OnAfterFieldValueSet(FieldValueChangedEventArgs <BimaruValue> e)
 {
     UpdateNumberOfFields(e);
     UpdateInvalidFieldBoundaries(e.Point);
     UpdateNumberOfShipsPerLength(e);
 }
Beispiel #10
0
 void OnFieldValueChanged(object sender, FieldValueChangedEventArgs <BimaruValue> e)
 {
     Rule.FieldValueChanged(Game, e);
 }