lundi 27 avril 2015

Does anyone know why this code just won't work

To me it makes sense, then again I'm nowhere near an expert. So I'm working on a project for my first programming course and I've been stuck on this question all day, I have probebly done 5 hours of cumulative research trying to figure out how this is even possible.

Basically I need to shuffle these 'cards' for a memory game and I can't figure out why it's not working. The program runs fine but none of the images change. i put the cout in there just to make sure that the value was changing each time, I just don't know why it won't swap with those values. I tried the shuffle and random_shuffle thing but I most likely did not do it right, if someone could show me what it has to look like with my code I would be ever so grateful. I'm just so puzzled as to why it won't work. If someone could provide a working example explaining as to where i went wrong that would be amazing. Here's the full code, it's a bit long.

void shuffle(int board[][NCOLS]) {
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dis(1, 6);
    for (int i = 0; i < 20; i++) {
        int randomX = dis(gen);
        swap(board[randomX][randomX], board[randomX][randomX]);
        cout << "num = " << randomX << endl;
    }

}

I'm not quite sure how to paste code on here and the program itself is actually pretty big in full length so I've opted to just upload the full code here if you need some context: http://ift.tt/1DQNMKB

Also, I'm right in calling the function by using shuffle(board); correct? it's just wierd because there's already a built in function called shuffle correct?

Thanks for any help you can provide, I highly appreciate it.




Aucun commentaire:

Enregistrer un commentaire