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.

45 lines
1.3 KiB

using System;
using TheGameExtreme.model.card.cardType;
namespace TheGameExtreme.model.deck
{
public class FractionDeck : Deck
{
/**
* Fonction permettant de créer un jeu de carte pour jouer avec les fractions
*/
public FractionDeck()
{
Random random = new Random();
for (int i = 1; i < 100; i ++)
{
int numerateur = random.Next(1, 100);
int denominateur = random.Next(1, 100);
int pgcd = PGCD(numerateur, denominateur);
while (pgcd != 1)
{
numerateur /= pgcd;
denominateur /= pgcd;
pgcd = PGCD(numerateur, denominateur);
}
InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(numerateur, denominateur)));
}
}
/**
* Fonction permettant de retourner le plus grand diviseur commun à deux nombres
* <param name="a">Premier nombre</param>
* <param name="b">Deuxième nombre</param>
* <returns>Plus grand diviseur commun</returns>
*/
private int PGCD(int a, int b)
{
int temp = a % b;
if (temp == 0)
return b;
return PGCD(b, temp);
}
}
}