Beispiel #1
0
        private static bool ApplyRulesPart2(Position[,] positions)
        {
            bool peopleMoved = false;

            for (var i = 0; i < positions.GetLength(0); i++)
            {
                for (var j = 0; j < positions.GetLength(1); j++)
                {
                    var position = positions[i, j];
                    if (position.State == PositionState.Floor)
                    {
                        continue;
                    }
                    var adjacents = GetFirstNotFloorAdjacents(positions, i, j);
                    if (position.State == PositionState.Empty && adjacents.Count(x => x.State == PositionState.Occupied) == 0)
                    {
                        peopleMoved          = true;
                        position.ChangeState = true;
                        continue;
                    }

                    if (position.State == PositionState.Occupied && adjacents.Count(x => x.State == PositionState.Occupied) >= 5)
                    {
                        peopleMoved          = true;
                        position.ChangeState = true;
                        continue;
                    }
                }
            }

            positions.ApplyChanges();

            return(peopleMoved);
        }