Beispiel #1
0
        public IEnumerable <NumbersGame> GenerateIntermediates()
        {
            var ret      = new List <NumbersGame>();
            int maxIndex = _numbers.Count - 1;

            // Take each possible pairing in turn, and apply all possible operations
            for (int ix1 = 0; ix1 < maxIndex; ++ix1)
            {
                int i1 = _numbers[ix1];
                for (int ix2 = ix1 + 1; ix2 <= maxIndex; ++ix2)
                {
                    int i2 = _numbers[ix2];
                    foreach (Operator op in OperationValues)
                    {
                        int?v = Operation.Apply(i1, i2, op);
                        if (v != null)
                        {
                            var game = new NumbersGame(this); // Deep copy
                            game._numbers.RemoveAt(ix2);      // Remove the latter ix2 element
                            game._numbers[ix1] = v.Value;     // Overwrite the earlier ix1 element with the result
                            game._history.Add(new Operation(i1, i2, op));

                            ret.Add(game);
                        }
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        public IGame CreateDescendent(IOperation op)
        {
            var game = new NumbersGame(this); // Deep copy - takes initial values, history and current values

            game._numbers.RemoveAt(ix2);      // Remove the latter ix2 element
            game._numbers[ix1] = v.Value;     // Overwrite the earlier ix1 element with the result
            game._history.Add(new Operation(i1, i2, op));

            ret.Add(game);
            throw new NotImplementedException();
        }
Beispiel #3
0
 // Copy constructor (deep)
 public NumbersGame(NumbersGame game)
 {
     _numbers.AddRange(game._numbers);
     _history.AddRange(game._history);
     Target = game.Target;
 }