public CrabCups(string cups, bool reachMillion) { Cups = cups.Select(c => c.ToString()).Select(Int32.Parse).ToList(); CurrcentCupIndex = 0; var maxValue = Cups.Max(); for (int i = maxValue + 1; i <= 1000000; i++) { Cups.Add(i); } }
public void Play(int until = 10) { for (int move = 1; move <= until; move++) { if (PRINT) { Console.WriteLine($"-- move {move} --"); } if (PRINT) { PrintCups(); } // the current cup int currentCup = Cups[CurrcentCupIndex]; // pick up the three cups that are immediately clockwise of the current cup List <int> cupsInHand = PickupCups(); // select a destination cup. the cup with a label equal to the current cup's label minus one // can only be on the board to search. if not found lowest, go up and search from the highest again int destinationCup = SelectDestinationCup(currentCup); // insert the cup from the hands in the right position after the destination cup var destinationCupIndex = Cups.IndexOf(destinationCup); Cups.InsertRange(destinationCupIndex + 1, cupsInHand); // make sure the holden cup is at the same index as before! otherwise shift everything while (currentCup != Cups[CurrcentCupIndex]) { var firstCup = Cups.FirstOrDefault(); Cups.RemoveAt(0); Cups.Add(firstCup); } // select a new current cup, the cup which is immediately clockwise of the current cup CurrcentCupIndex = GetNextCupIndex(CurrcentCupIndex); } if (PRINT) { Console.WriteLine($"-- final --"); } if (PRINT) { PrintCups(); } }