Esempio n. 1
0
        public Knight(int idx, int r_idx, int l_idx,
                      Rostrum rostrum, DrinkingBout drinkingBout)
        {
            Idx   = idx;
            R_Idx = r_idx;
            L_Idx = l_idx;

            this.rostrum      = rostrum;
            this.drinkingBout = drinkingBout;
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Rostrum      rostrum      = new Rostrum();
            DrinkingBout drinkingBout = new DrinkingBout();

            Knight[] knights = InitializeKnights(rostrum, drinkingBout);
            rostrum.RegisterKnights(knights);


            var threads = StartParty(knights, drinkingBout);

            StopParty(threads.Item1, threads.Item2);
        }
Esempio n. 3
0
        private static Knight[] InitializeKnights(Rostrum rostrum, DrinkingBout drinkingBout)
        {
            var knights = new Knight[Config.NumberOfKnights];

            for (int i = 1; i < Config.NumberOfKnights - 1; i++)
            {
                knights[i] = new Knight(i, i + 1, i - 1, rostrum, drinkingBout);
            }
            knights[0] = new Knight(0, 1, Config.NumberOfKnights - 1, rostrum, drinkingBout);
            knights[Config.NumberOfKnights - 1] =
                new Knight(Config.NumberOfKnights - 1, 0, Config.NumberOfKnights - 2, rostrum, drinkingBout);

            return(knights);
        }