dimanche 27 janvier 2019

Bringing Numbers in Vector from One Function into Another

I am currently trying to create a weighted dice roll system. I am running into some problems with accessing the weighted numbers I have. So in my dice class, I have two functions. The first function creates a weighted dice system with specified parameters for the weights and sides. So when in main, I can do something like:

Die dice1({.5,.1,.1,.1,.1,.1}, 6); //Creates die with higher probability of 1 being rolled, with six sides

The second function I have is a roll function, that returns a roll number given the weight attributes set from the earlier function. It looks something like:

void Die::roll() {
    double random = ((double) rand() / RAND_MAX);
    for (int i = 0; i < SIDES; i++) {
        if (random < new_weights[i]) last_roll = i;
        random -= new_weights[i];
    }
}

Now, my problem is, how do I bring the new_weights vector of weight attributes into the roll() function? Can it be as simple as to pass it by const ref?

Also, I have a function that creates a "normal" six-sided die with fair probability to land any number from 1-6. How can I change roll() to work from the weighted die parameters versus the regular die parameters, given the die the player decides to use?

Thank you so much for any help/tips.




Aucun commentaire:

Enregistrer un commentaire