示例#1
0
文件: Day11.cs 项目: Radimoid/AOC2020
 char CurrentState(int x, int y)
 {
     if (x < 0 || y < 0 || x >= _seats.Cols() || y >= _seats.Rows())
     {
         return(_boundary);
     }
     return(_seats.Get(x, y));
 }
示例#2
0
文件: Day11.cs 项目: Radimoid/AOC2020
        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);
        }
示例#3
0
文件: Day11.cs 项目: Radimoid/AOC2020
        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);
        }