//counts potentially active marble positions
        public static int CountActive(int[] map)
        {
            var actives = 0;

            for (var x = 0; x < 13; x++)
            {
                for (var y = 0; y < 13; y++)
                {
                    if (map[x * 13 + y] != 1)
                    {
                        continue;
                    }

                    var count = 0;

                    for (var i = 0; i < 8; i++)
                    {
                        //going around
                        var x2 = HexMath.XInDirection(x, y, i % 6);
                        var y2 = HexMath.YInDirection(y, i % 6);

                        if (map[x2 * 13 + y2] != 0)
                        {
                            count = 0;
                        }
                        else
                        {
                            count++;
                        }
                        if (count == 3)
                        {
                            actives++;
                            break;
                        }
                    }
                }
            }
            return(actives);
        }
        //creates pretty patterns by mirroring spreading holes in 2, 3 or 6 directions
        public static int[] GenerateRandomMapPattern(Random random, int rotations)
        {
            //default game map
            int[] generatedMap =
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
                0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                0, 1, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 0,
                0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
                0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            var marbleCount = 90;

            //how many points to start spreading holes from
            var numberOfPoints = random.Next(0 + rotations, 3 + rotations);

            var points = new List <Point>();

            for (var i = 0; i < numberOfPoints; i++)
            {
                var p = new Point(0, 0);
                while (generatedMap[p.X * 13 + p.Y] != 1)
                {
                    p.X = random.Next(1, 13);
                    p.Y = random.Next(1, 13);
                }
                DoRotations(generatedMap, rotations, p);
                marbleCount -= 6 / rotations;
                points.Add(p);
                //DrawMap(generatedMap);
            }


            var fullbreak = false;
            var iteration = 0;

            while (!fullbreak)
            {
                foreach (var p in points)
                {
                    var direction = random.Next(0, 6);
                    var x         = HexMath.XInDirection(p.X, p.Y, direction);
                    var y         = HexMath.YInDirection(p.Y, direction);
                    if (x > 0 && x < 13 && y > 0 && y < 13 &&
                        generatedMap[x * 13 + y] == 1)
                    {
                        p.X = x;
                        p.Y = y;
                        DoRotations(generatedMap, rotations, p);
                        marbleCount -= 6 / rotations;
                        //DrawMap(generatedMap);
                        if (marbleCount < 55)
                        {
                            fullbreak = true;
                            break;
                        }
                    }

                    //if it goes for too long, it's stuck so rerandomize points
                    iteration++;
                    if (iteration == 100)
                    {
                        iteration = 0;
                        foreach (var p2 in points)
                        {
                            p2.X = random.Next(1, 13);
                            p2.Y = random.Next(1, 13);
                        }
                    }
                }
            }

            //Console.WriteLine(generatedMap.Where(m => m == 1).Count() + "-" + marbleCount);

            //DrawMap(generatedMap);

            return(generatedMap);
        }