using System.Linq;
using Gamelogic;
using Gamelogic.Grids;
using System.Collections.Generic;



public static class Extensions
{
	
	public static IEnumerable<PointyHexPoint> GetSpiralIterator<TCell>(this IGrid<TCell,PointyHexPoint> grid, int N) 
			where TCell : SpriteCell
	{
		var directions = new[] { 
				PointyHexPoint.East,
				PointyHexPoint.NorthEast,
				PointyHexPoint.NorthWest,
				PointyHexPoint.West,
				PointyHexPoint.SouthWest,
				PointyHexPoint.SouthEast
		};
			
		var hexPoint = new PointyHexPoint(0,0);
		yield return hexPoint;
		
		for (var k = 0; k < N; k++)
		{
			hexPoint = new PointyHexPoint(0, 0);
			hexPoint = hexPoint + directions[4] * (k);
			
			for (var i = 0; i < 6; i++)
			{
				for (var j = 0; j < k; j++)
				{
					if (grid.Contains(hexPoint))
					{
						yield return hexPoint;
					}

					hexPoint = hexPoint + directions[i];
				}
			}
		}
	}

	public static T SelectRandom<T>(this IEnumerable<T> list)
	{
		return list.SampleRandom(1).First();
	}
}
