char CurrentState(int x, int y) { if (x < 0 || y < 0 || x >= _seats.Cols() || y >= _seats.Rows()) { return(_boundary); } return(_seats.Get(x, y)); }
public void PartOne() { while (true) { //_seats.Print(); //Console.WriteLine(); //Console.ReadKey(); var next = ApplyModel(); if (next.Equals(_seats)) { break; } _seats = next; } int cnt = 0; for (int x = 0; x < _seats.Cols(); x++) { for (int y = 0; y < _seats.Rows(); y++) { if (_seats.Get(x, y) == _occupied) { cnt++; } } } Console.WriteLine(cnt); }
Tools.Map ApplyModel() { var ret = new Tools.Map(_seats.Cols(), _seats.Rows()); for (int x = 0; x < ret.Cols(); x++) { for (int y = 0; y < ret.Rows(); y++) { ret.Set(x, y, NewState(x, y)); } } return(ret); }