internal void Play(Player player)
        {
            _currentMarbleValue++;
            if (_currentMarbleValue % MutatedOperationValueFactor == 0)
            {
                // do special thing
                player.Score += _currentMarbleValue;
                var sevenBack = Current.Previous.Previous.Previous.Previous.Previous.Previous.Previous;

                var eightBack = sevenBack.Previous;
                var sixBack   = sevenBack.Next;
                eightBack.Next    = sixBack;
                sixBack.Previous  = eightBack;
                sevenBack.Removed = true;

                player.Score += sevenBack.Value;

                Current = sixBack;
            }
            else
            {
                var oneStep = Current.Next;
                var twoStep = Current.Next.Next;

                var newMarble = new Marble(_currentMarbleValue);
                newMarble.Previous = oneStep;
                oneStep.Next       = newMarble;

                newMarble.Next   = twoStep;
                twoStep.Previous = newMarble;

                Current = newMarble;
            }
        }
Beispiel #2
0
        // --------------------------------------------------------------------
        public long AddMarble(int marbleNumber)
        {
            var removed = 0L;

            if (marbleNumber % 23 == 0)
            {
                removed += (long)marbleNumber;
                for (int i = 0; i < 7; i++)
                {
                    _currentMarble = _currentMarble.Previous;
                }

                removed += _currentMarble.Value;
                _currentMarble.Previous.Next = _currentMarble.Next;
                _currentMarble.Next.Previous = _currentMarble.Previous;
                _currentMarble = _currentMarble.Next;
            }
            else
            {
                for (int i = 1; i < 3; i++)
                {
                    _currentMarble = _currentMarble.Next;
                }

                var insert = new Marble(marbleNumber, _currentMarble.Previous, _currentMarble);
                InsertMarble(_currentMarble, insert);
                _currentMarble = insert;
            }

            return(removed);
        }
Beispiel #3
0
 // --------------------------------------------------------------------
 public void Clear()
 {
     _firstMarble            = null;
     _currentMarble          = null;
     _currentMarble          = new Marble(0, null, null);
     _currentMarble.Next     = _currentMarble;
     _currentMarble.Previous = _currentMarble;
     _firstMarble            = _currentMarble;
 }
        public MarbleGame(int players, int maxMarbleValue)
        {
            Players             = Enumerable.Range(0, players).Select(x => new Player(x + 1)).ToList();
            _maxMarbleValue     = maxMarbleValue;
            _currentMarbleValue = 0;

            var zero = new Marble(0);

            zero.Previous = zero;
            zero.Next     = zero;
            Zero          = zero;
            Current       = zero;
        }
Beispiel #5
0
 public Marble(int val, Marble prev, Marble next)
 {
     Value    = val;
     Previous = prev;
     Next     = next;
 }
Beispiel #6
0
 // --------------------------------------------------------------------
 private void InsertMarble(Marble current, Marble insert)
 {
     current.Previous.Next = insert;
     current.Previous      = insert;
 }