Beispiel #1
0
        private static bool ValidateRelativePosition(Coordinate coordinate)
        {
            var seatedPeople = 0;
            var nearbyPeople = new List <Coordinate>();

            foreach (var relation in _relationalCoordinates)
            {
                nearbyPeople.Add(coordinate.CombineToNew(relation));

                var occupiedSeat = coordinate.CombineToNew(relation);

                while (!_seats.ContainsKey(occupiedSeat))
                {
                    if (occupiedSeat.X < 0 || occupiedSeat.X > _maxXCoordinate || occupiedSeat.Y < 0 || occupiedSeat.Y > _maxYCoordinate)
                    {
                        break;
                    }

                    occupiedSeat = occupiedSeat.CombineToNew(relation);
                }
            }

            foreach (var n in nearbyPeople)
            {
                if (!_seats.ContainsKey(n))
                {
                    continue;
                }

                if (_seats[n])
                {
                    seatedPeople++;
                }
            }

            if (_seats[coordinate])
            {
                if (seatedPeople < _minSpaceNeeded)
                {
                    return(true);
                }
            }
            else
            {
                if (seatedPeople == 0)
                {
                    return(true);
                }
            }

            return(false);
        }