Exemplo n.º 1
0
            public static SnakesLaddersSimulation ReadInput()
            {
                SnakesLaddersSimulation result = new SnakesLaddersSimulation();

                result.DieNumberProbabilities = Array.ConvertAll(
                    Console.ReadLine().Trim().Split(','), double.Parse);
                result.DieNumberAccumProbabilities = new double[6];
                for (int i = 0; i < 6; i++)
                {
                    result.DieNumberAccumProbabilities[i] = (i == 0) ?
                                                            result.DieNumberProbabilities[i] :
                                                            result.DieNumberProbabilities[i] + result.DieNumberAccumProbabilities[i - 1];
                }

                Console.ReadLine(); // cLadders, cSnakes, will take from next lines
                // ladders
                foreach (Match match in regex.Matches(Console.ReadLine()))
                {
                    int start = int.Parse(match.Groups[1].Value);
                    int end   = int.Parse(match.Groups[2].Value);
                    result.Ladders.Add(start, end);
                }

                // snakes
                foreach (Match match in regex.Matches(Console.ReadLine()))
                {
                    int start = int.Parse(match.Groups[1].Value);
                    int end   = int.Parse(match.Groups[2].Value);
                    result.Snakes.Add(start, end);
                }

                return(result);
            }
Exemplo n.º 2
0
        public static void Run()
        {
            int    n      = int.Parse(Console.ReadLine());
            Random rndGen = new Random(1);

            for (int i = 0; i < n; i++)
            {
                SnakesLaddersSimulation sim = SnakesLaddersSimulation.ReadInput();
                int sum    = 0;
                int cGames = 0;
                for (int s = 0; s < NumGames; s++)
                {
                    int thisGame = sim.SimulateGame(rndGen);
                    if (thisGame > 0)
                    {
                        cGames++;
                        sum += thisGame;
                    }
                }

                Console.WriteLine(sum / cGames);
            }
        }