static void ApplyRuleSet2(SeatLayout previousLayout, SeatLayout currentLayout) { for (int row = 0; row < currentLayout.RowCount; row++) { for (int col = 0; col < currentLayout.ColumnCount; col++) { if (previousLayout.IsFloor(row, col)) { continue; } else { bool occupied = previousLayout.IsOccupied(row, col); int withinView = previousLayout.CountWithinViewOccupied(row, col); // If a seat is empty (L) and there are no visible // occupied seats within view, the seat becomes occupied. // The person can only see the first seat encountered in // each direction. if (!occupied && withinView == 0) { currentLayout.MarkOccupied(row, col); } // If a seat is occupied (#) and five or more seats // within view are also occupied, the seat becomes empty. // The person can only see the first seat encountered in // each direction. else if (occupied && withinView >= 5) { currentLayout.MarkEmpty(row, col); } } } } }
static void ApplyRuleSet1(SeatLayout previousLayout, SeatLayout currentLayout) { for (int row = 0; row < currentLayout.RowCount; row++) { for (int col = 0; col < currentLayout.ColumnCount; col++) { if (previousLayout.IsFloor(row, col)) { continue; } else { bool occupied = previousLayout.IsOccupied(row, col); int adjacent = previousLayout.CountAdjacentOccupied(row, col); // If a seat is empty (L) and there are no occupied // seats adjacent to it, the seat becomes occupied. if (!occupied && adjacent == 0) { currentLayout.MarkOccupied(row, col); } // If a seat is occupied (#) and four or more seats // adjacent to it are also occupied, the seat becomes empty. else if (occupied && adjacent >= 4) { currentLayout.MarkEmpty(row, col); } } } } }