using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models.Game;
using Models.Interfaces;

namespace Models.Rules
{
    public class Rules : IRules
    {
        public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
        {
            if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1)
                return false;

            return true;
        }

        public bool NearCellIsValid(Cell choosenCell, List<Cell> cells)
        {
            if (choosenCell == null) return false;
            
            IEnumerable<Cell> PlayedCellsQuery =
                from cell in cells
                where cell.Value != null
                select cell;

            foreach (var cell in PlayedCellsQuery)
            {
                if(!IsCellAdjacent(choosenCell, cell)) continue;

                return true;
            }
        }

        public bool IsZone(Cell choosen, List<Cell> cells,List<List<Cell>> zones)
        {
            IEnumerable<Cell> PlayedCellsQuery =
                from cell in cells
                where cell.Value != null
                select cell;
        }

    }
}