Esempio n. 1
0
        public void PlayGame(long numPlayers, long lastMarble, bool showStatus = false)
        {
            Scores.Clear();
            firstMarble = new Marble {
                Value = 0
            };
            firstMarble.Previous = firstMarble;
            firstMarble.Next     = firstMarble;
            currentMarble        = firstMarble;

            for (long i = 1; i <= numPlayers; i++)
            {
                Scores.Add(i, 0);
            }

            for (long i = 0; i <= lastMarble; i++)
            {
                if (showStatus)
                {
                    PrintStatus();
                }

                currentPlayer = (i % numPlayers) + 1;
                Marble newMarble = new Marble {
                    Value = i + 1
                };
                if ((newMarble.Value % PointValueMultiple) > 0)
                {
                    Marble previousMarble = currentMarble.Next;
                    Marble nextMarble     = previousMarble.Next;
                    newMarble.Previous  = previousMarble;
                    newMarble.Next      = nextMarble;
                    previousMarble.Next = newMarble;
                    nextMarble.Previous = newMarble;
                    currentMarble       = newMarble;
                }
                else
                {
                    Marble marbleToRemove = currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;
                    currentMarble = marbleToRemove.Next;
                    marbleToRemove.Previous.Next = marbleToRemove.Next;
                    marbleToRemove.Next.Previous = marbleToRemove.Previous;

                    long currentPlayerScore = Scores[currentPlayer] + (newMarble.Value + marbleToRemove.Value);
                    Scores[currentPlayer] = currentPlayerScore;
                }
            }
        }
Esempio n. 2
0
        public void PrintStatus()
        {
            Console.Write("[{0}] ", currentPlayer);
            Marble marble = firstMarble;

            do
            {
                if (currentMarble.Value == marble.Value)
                {
                    Console.Write("({0}) ", marble.Value);
                }
                else
                {
                    Console.Write("{0} ", marble.Value);
                }
                marble = marble.Next;
            } while (marble.Value != 0);
            Console.WriteLine();
        }