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.
110 lines
2.7 KiB
110 lines
2.7 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)
|
|
{
|
|
if (deck.Count == 0)
|
|
{
|
|
deck.Add(card);
|
|
return;
|
|
}
|
|
|
|
int mediane = (end - start) / 2 + start;
|
|
int comparateur = deck[mediane].Value.CompareTo(card.Value);
|
|
|
|
if (comparateur == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (mediane == start)
|
|
{
|
|
if (comparateur < 0)
|
|
{
|
|
if (deck[end].Value.CompareTo(card.Value) < 0)
|
|
{
|
|
deck.Insert(end + 1, card);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
deck.Insert(end, card);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
deck.Insert(start, card);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (comparateur < 0)
|
|
{
|
|
InsertionDichotomique(deck, mediane, end, card);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
InsertionDichotomique(deck, start, mediane, card);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
//int mediane = (end - start) / 2 + start;
|
|
//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;
|
|
//}
|
|
}
|
|
}
|
|
}
|