You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using TheGameExtreme.model.card;
|
|
|
|
namespace TheGameExtreme.model.deck
|
|
{
|
|
public abstract class Deck
|
|
{
|
|
|
|
protected List<Card> deck = new List<Card>();
|
|
|
|
public int size()
|
|
{
|
|
return deck.Count;
|
|
}
|
|
|
|
public void removeAt(int index)
|
|
{
|
|
deck.RemoveAt(index);
|
|
}
|
|
|
|
public Card getCard(int index)
|
|
{
|
|
return deck[index];
|
|
}
|
|
|
|
protected void InsertionDichotomique(List<Card> deck, int start, int end, Card card)
|
|
{
|
|
int mediane = (end - start) % 2 + start;
|
|
if (mediane > deck.Count - 1)
|
|
{
|
|
deck.Add(card);
|
|
return;
|
|
}
|
|
int comparateur = deck[mediane].Value.CompareTo(card.Value);
|
|
if (mediane == end)
|
|
{
|
|
if (comparateur > 0)
|
|
{
|
|
deck.Insert(start, card);
|
|
}
|
|
else
|
|
{
|
|
deck.Insert(end, card);
|
|
}
|
|
return;
|
|
}
|
|
if (comparateur == 0)
|
|
{
|
|
return;
|
|
}
|
|
else if (comparateur > 0)
|
|
{
|
|
InsertionDichotomique(deck, start, mediane, card);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
InsertionDichotomique(deck, mediane, end, card);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|