Exemple #1
0
 public Philosopher(int index, Table table)
 {
     Index   = index;
     Table   = table;
     _left   = table.Chopsticks[index];
     _right  = table.Chopsticks[(index + 1) % table.Chopsticks.Length];
     _random = new Random(Index);
 }
Exemple #2
0
 public PhilosopherFixed(int index, Table table)
     : base(index, table)
 {
     if (_left.Index < _right.Index)
     {
         _first  = _left;
         _second = _right;
     }
     else
     {
         _first  = _right;
         _second = _left;
     }
 }
Exemple #3
0
        public Table(int numSeats, Func <int, Table, Philosopher> philosopherCreator)
        {
            Chopsticks = new Chopstick[numSeats];
            for (int i = 0; i < numSeats; ++i)
            {
                Chopsticks[i] = new Chopstick(i);
            }

            Philosophers = new Philosopher[numSeats];
            for (int i = 0; i < numSeats; ++i)
            {
                Philosophers[i] = philosopherCreator(i, this);
            }
            foreach (var philosopher in Philosophers)
            {
                philosopher.AllPhilosophersBeSeated();
            }
        }