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); }
public PhilosopherFixed(int index, Table table) : base(index, table) { if (_left.Index < _right.Index) { _first = _left; _second = _right; } else { _first = _right; _second = _left; } }
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(); } }