コード例 #1
0
        public string Print()
        {
            var enumerable = Enumerable
                             .Range(0, Map.SizeY)
                             .Select(
                y =>
            {
                var strings = Enumerable
                              .Range(0, Map.SizeX)
                              .Select(
                    x =>
                {
                    var p = new V(x, Map.SizeY - y - 1);
                    if (Map[p] == CellState.Obstacle)
                    {
                        return("#");
                    }

                    var wCount = Workers.Count(w => w.Position == p);
                    if (wCount != 0)
                    {
                        return(wCount.ToString());
                    }

                    if (Workers.Any(w => w.Manipulators.Any(m => w.Position + m == p && Map.IsReachable(w.Position, w.Position + m))))
                    {
                        return("-");
                    }

                    if (Workers.Any(w => w.Manipulators.Any(m => w.Position + m == p)))
                    {
                        return("!");
                    }

                    var booster = Boosters.FirstOrDefault(b => b.Position == p);
                    if (booster != null)
                    {
                        return(booster.ToString()[0].ToString());
                    }

                    if (Map[p] == CellState.Void)
                    {
                        return(".");
                    }

                    return("*");
                })
                              .ToArray();
                return(string.Join("", strings));
            });

            return(string.Join("\n", enumerable));
        }