示例#1
0
        private void SetAdjacentSeatsForPart2(Seat seat)
        {
            int x       = seat.X;
            int y       = seat.Y;
            int yMax    = Seats.Max(x => x.Y);
            int xMax    = Seats.Max(x => x.X);
            int counter = xMax >= yMax ? xMax : yMax;


            bool rightUp = false, leftUp = false, leftDown = false, rightDown = false, up = false, left = false, down = false, right = false;

            for (int i = 1; i < counter; i++)
            {
                Seat tempSeat;

                if (!rightUp)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x + i && s.Y == y + i);

                    if (tempSeat != null)
                    {
                        rightUp = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!leftUp)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x - i && s.Y == y + i);

                    if (tempSeat != null)
                    {
                        leftUp = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!leftDown)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x - i && s.Y == y - i);

                    if (tempSeat != null)
                    {
                        leftDown = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!rightDown)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x + i && s.Y == y - i);

                    if (tempSeat != null)
                    {
                        rightDown = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!up)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x && s.Y == y + i);

                    if (tempSeat != null)
                    {
                        up = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!left)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x - i && s.Y == y);

                    if (tempSeat != null)
                    {
                        left = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!down)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x && s.Y == y - i);

                    if (tempSeat != null)
                    {
                        down = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }

                if (!right)
                {
                    tempSeat = Seats.FirstOrDefault(s => s.X == x + i && s.Y == y);

                    if (tempSeat != null)
                    {
                        right = true;
                        seat.AdjacentSeats.Add(tempSeat);
                    }
                }
            }
        }
示例#2
0
        private int CountAdjacentSeats(Seat seat)
        {
            var adjacentSeats = seat.AdjacentSeats.Count(x => x.PreviousState == '#');

            return(adjacentSeats);
        }