using System;
using System.Collections.Generic;
using TheGameExtreme.model.card;
using TheGameExtreme.model.gameActions.abstractRules;
using TheGameExtreme.model.piles;
using TheGameExtreme.Resx;

namespace TheGameExtreme.model.gameActions.decimals
{
    public class TerminerSonTourDecimal : TerminerSonTour
    {
        public TerminerSonTourDecimal(Piles ListOrderedStacks) : base(ListOrderedStacks)
        {
        }

        override public bool end(List<Card> CurrentHand, List<Card> CurrentCardPlayed)
        {
            if (CurrentHand.Count == 0 || CurrentCardPlayed.Count >= 2)
            {
                // Vérifier la fin du jeu
                return true;
            }
            else
            {
                ErrorMessage = AppResources.StrCardPlayedLessThanTwo;
                return false;
            }

        }

        override protected void tryToFindSoluce(List<Card> playableCard, List<Card> CurrentHand)
        {
            CurrentHand.ForEach(card =>
            {
                for (int i = 0; i < ListOrderedStacks.Size; i++)
                {
                    if (i < (ListOrderedStacks.Size * 0.5))
                    {
                        if (card.Value > ListOrderedStacks.getStack(i).Peek().Value)
                        {
                            playableCard.Add(card);
                        }
                    }
                    else if (card.Value < ListOrderedStacks.getStack(i).Peek().Value)
                    {
                        playableCard.Add(card);
                    }
                    else if (card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value - 0.1m) == 0 || card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value + 0.1m) == 0 || card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value - 0.01m) == 0 || card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value + 0.01m) == 0 || card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value - 0.001m) == 0 || card.Value.CompareTo(ListOrderedStacks.getStack(i).Peek().Value + 0.001m) == 0)
                    {
                        playableCard.Add(card);
                    }
                }
            });
        }

        override protected bool testEndGame(List<Card> playableCard)
        {
            if (playableCard.Count < 2)
            {
                return false;
            }
            return true;
        }
    }
}
