Ejemplo n.º 1
0
            // Find monsters by rotating/flipping until some are found
            // Rotate the monster instead of the map, as it's cheaper
            static bool FindWaterRoughness(char[,] map, char[,] monster, ref int roughness)
            {
                var mapw  = map.GetLength(0);
                var maph  = map.GetLength(1);
                var monw  = monster.GetLength(0);
                var monh  = monster.GetLength(1);
                var xscan = mapw - monw;
                var yscan = maph - monh;

                var monsterspots = monster.PositionsOf('#');
                var monsters     = 0;

                // Scan map for occurrences of the monster (don't care about overlaps)
                for (var x = 0; x < xscan; x++)
                {
                    for (var y = 0; y < yscan; y++)
                    {
                        if (monsterspots.All(p => map[x + p.X, y + p.Y] == '#'))
                        {
                            monsters++;
                        }
                    }
                }
                if (monsters == 0)
                {
                    return(false);
                }
                roughness = map.CountChar('#') - monsters * monsterspots.Count();
                return(true);
            }