A greedy algorithm for a rotated game

I need to know how to implement a greedy algorithm in a card game using C #. The game is a turn-based game. When an AI needs to issue some cards, it should be based on the last state of other cards that are already on the table. Does anyone have a solution for this or maybe a link for me to get started? Thanks in advance!

So far I have just finished the code for shuffling cards:

List<int> cards = new List<int>();

for (int j = 1; j <= 2; j++)
{
    for (int i = 1; i <= 54; i++)
    {
        cards.Add(i);
    }
}

List<int> ShuffledCards = new List<int>();
Random random = new Random();

int iterations = cards.Count;
int index = 0;
for (int j = 1; j <= 2; j++)
{
    for (int i = 0; i < iterations; i++)
    {
        index = random.Next(0, iterations - i);
        ShuffledCards.Add(cards[index]);
        cards.RemoveAt(index);
    }
    iterations = cards.Count;
    index = 0;
}

ShuffledCards.Reverse(0, ShuffledCards.Count);
ShuffledCards.RemoveRange(0, 8);
ShuffledCards.Reverse(0, ShuffledCards.Count);
+3
source share
2 answers

This book is like a bible about AI. You can start by reading the first three parts of this book.

+4
source

, . - -, ?

. , .

:

//Your deck state:
deck   //list of cards in the deck (in top->bottom order) (initially shuffled)
i;     //index of the card at the top of the deck

void dreshuffle(){
    shuffle(cards);
    i = 0;
}

int get_card(){
    if(i >= cards.length){
        //no cards left in pile
        reshuffle()    
    }
    return cards[i++];
}

, , , , . , .


, . ?

list;
n = list.count - 1 //last index in list
while(n >= 0){
    i = random integer in range [0,n] (inclusive)
    swap(list[i], list[n])
    n -= 1
}

( )

0

All Articles