It is currently 27 Apr 2024, 00:47
   
Text Size

RNG/Shuffler

by BetaSteward

Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins

RNG/Shuffler

Postby tommygecko » 09 Feb 2015, 20:15

I'm just curious and wondering, what program is used to shuffle the decks in xmage?
tommygecko
 
Posts: 13
Joined: 15 Jan 2015, 14:59
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby emerald000 » 09 Feb 2015, 20:41

Code: Select all
for (int n = shuffled.length - 1; n > 0; n--) {
    int r = rnd.nextInt(n);
    UUID temp = shuffled[n];
    shuffled[n] = shuffled[r];
    shuffled[r] = temp;
}
User avatar
emerald000
 
Posts: 92
Joined: 07 Jul 2014, 16:55
Has thanked: 1 time
Been thanked: 9 times

Re: RNG/Shuffler

Postby tommygecko » 10 Feb 2015, 18:04

Is it actually flawless? honestly I have doubts about the RNG
tommygecko
 
Posts: 13
Joined: 15 Jan 2015, 14:59
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby emerald000 » 10 Feb 2015, 22:37

This is a normal Fisher-Yates shuffle using the built-in Java RNG. This is about as good as you can need/get.

The probable reason you feel the shuffler is flawed is because people usually do not shuffle correctly in real life. Randomness is not having the lands equally spaced in the deck. That is the opposite of random. Clumps should and will happen. You will get 8 non-lands in a row. You will get 8 lands in a row. You must not look at a specific event and say because it is unlikely, the shuffler is flawed.
User avatar
emerald000
 
Posts: 92
Joined: 07 Jul 2014, 16:55
Has thanked: 1 time
Been thanked: 9 times

Re: RNG/Shuffler

Postby tommygecko » 11 Feb 2015, 19:25

emerald000 wrote:This is a normal Fisher-Yates shuffle using the built-in Java RNG. This is about as good as you can need/get.

The probable reason you feel the shuffler is flawed is because people usually do not shuffle correctly in real life. Randomness is not having the lands equally spaced in the deck. That is the opposite of random. Clumps should and will happen. You will get 8 non-lands in a row. You will get 8 lands in a row. You must not look at a specific event and say because it is unlikely, the shuffler is flawed.
Clumps happen but not all the time. 8 lands in a row, yes. But having to mulligan almost every game with 20 land hands (UW heroic) is just plain weird.

It's badly screwing up my testing for games day. I'm sorry but telling an ordinary person like me Fisher-Yates shuffle does no help to me. Please explain it clearly to me and convincingly to me.

UW heroic won't be a top deck in the meta if every player has to mulligan 90% of their hands
tommygecko
 
Posts: 13
Joined: 15 Jan 2015, 14:59
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby LevelX » 11 Feb 2015, 19:49

tommygecko wrote:
emerald000 wrote:It's badly screwing up my testing for games day. I'm sorry but telling an ordinary person like me Fisher-Yates shuffle does no help to me. Please explain it clearly to me and convincingly to me.
Fisher-Yates shuffle
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: RNG/Shuffler

Postby Laqutis » 17 Feb 2015, 00:55

well tomy I am very sorry I just typed up an explanation for you about the fisher-yates shuffler that I was quite proud of only then I hit submit to find out the wonderful forum had decided to auto log me out without so much as saving all my work as a draft what a convenient feature ....... maybe some other time
Laqutis
 
Posts: 63
Joined: 08 Feb 2015, 05:07
Has thanked: 0 time
Been thanked: 2 times

Re: RNG/Shuffler

Postby Laqutis » 17 Feb 2015, 02:23

Dear Tommy

I will attempt to explain a Fisher-Yates shuffle.

First some basics, any deck no matter the cards are just the total number of objects in a ordered set.
The original order the objects are in is called the starting condition.

To start take your deck and lay the cards face down in a line. You have now done two things you have put your cards in an ordered set(they cannot move or repeat), and that ordered set is your starting condition. To calculate the number of possible starting conditions you take the total number in the set, in our case 60 and do as follows. Position one has 60 possibilities, position two has 59 possibilities because an object is in position one; thus each position has the same number of possibilities as the position before it -1. To calculate the total number of possibilities you simply multiply all of your possibilities in all of your positions, so in our case 60×59×58×57… This is called the number of permutations.

Now with your cards laid out in this fashion, we will randomize in a Fisher Yates manner. Go to position 60, now roll a 60 sided die, move the card in position 60 to the number that you rolled and replace the card from that position to position 60. Now do the same thing with position 59 only this time only roll a 59 sided die, perform your exchange and continue to do this for each position shrinking the die you roll by one each time. Example position eight will roll an eight sided die etc. If you roll the number of whatever position you are currently on the card does not move and you continue to the next step. This is exactly the function a properly implemented Fisher Yates shuffle performs.

The main difference between a PC shuffle and you humanly shuffling, is that the PC will have absolutely no bias towards any starting condition of the set. Whether we mean to or not just the act of playing groups and clumps the cards in such a fashion that we bias the number of possibilities of the initial conditions.

This math is actually also the reason why most any card game uses 60 card decks with max four iteration rule. This is because with less than 60 cards or with more than four of any one card it becomes too easy to predict the likely outcomes, and this is the farthest thing from a competitive game of chance.

Further these calculations are why all the tutors are banned, because they effectively shrink the total positions of the cards by the number of tutors. Basically just shrinking the deck size from 60 minus the number of tutors again making outcomes to likely to be predictable.

Hope this helped
Laqutis
 
Posts: 63
Joined: 08 Feb 2015, 05:07
Has thanked: 0 time
Been thanked: 2 times

Re: RNG/Shuffler

Postby nyrang » 17 Feb 2015, 19:40

This is a very interesting discussion, not only for xmage because as far as I know the Fisher-Yates shuffling algorithm is widely used in card games.
I wonder why a plain and simple algorithm like this is not used:

- Start with a pile of 60 cards in any order
- Generate a random number n from 1 to 60
- The n-th card of the original pile is placed on the top of the deck
- Generate a random number n from 1 to 59
- The n-th card of the original pile is placed on the top of the deck
... and so on

While Fisher-Yates is a proper shuffling algorithm, in that it behaves roughly as a human could do in real life, I can't help but feeling that it does introduce a bias in the final result, if only because it ends up evaluating most cards' position multiple times.
Wouldn't it make more sense to use a purely random (well, pseudo-random actually due to how RNGs work) algorithm like the one described above?
nyrang
 
Posts: 10
Joined: 04 Nov 2014, 22:21
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby Laqutis » 17 Feb 2015, 20:11

nyrang wrote:This is a very interesting discussion, not only for xmage because as far as I know the Fisher-Yates shuffling algorithm is widely used in card games.
I wonder why a plain and simple algorithm like this is not used:

- Start with a pile of 60 cards in any order
- Generate a random number n from 1 to 60
- The n-th card of the original pile is placed on the top of the deck
- Generate a random number n from 1 to 59
- The n-th card of the original pile is placed on the top of the deck
... and so on

While Fisher-Yates is a proper shuffling algorithm, in that it behaves roughly as a human could do in real life, I can't help but feeling that it does introduce a bias in the final result, if only because it ends up evaluating most cards' position multiple times.
Wouldn't it make more sense to use a purely random (well, pseudo-random actually due to how RNGs work) algorithm like the one described above?
All you have done is improperly and backwards :) (no offense meant) described what a fisher-yates shuffle is doing. As i pointed out
the major difference between a proper pc shuffle and human shuffles is in the "starting conditions" it's actually incorrect that we "account" in anyway for the order of our cards prior to our shuffles. We DO period, how often would you be willing to shuffle your deck with all the lands in a giant clump probably never. We are WRONG for taking any assumption about the "starting conditions", mathematically it's equally as likely that you would have your cards in what we humanly would consider a bad or "bizarre" starting order. I even explained how to calculate the number of starting permutations.

n! / (n!-r)! =
where n is your total number of objects
! is a the factorial function which means to multiply the descending natural ordered numbers eg 60x59x58x57 ....x1
r is how many objects your gonna pick from the set
so (n!-r) in this case just means how many of the objects we are gonna pick out of the total objects (assuming you wanted to shrink the number of objects you were choosing this is how you would do it but for our card purpose this is irrelevant as when we are initially shuffling we are always going to be picking the total number of objects)

Simply put we are all cheating technically by not having a magical hurricane box we throw our decks into that with no bias mixes your cards to a starting order that we then shuffle from.

If you look up any experimental set of data using a properly implemented f/y shuffle using Google you will see an exactly even gradient across all possible outcomes. Finally the cards placements are only non static for the positions who's objects have not yet been shuffled. Once a Fisher-Yates has placed an object into a "position" during the shuffle sequence that card can not move, just like a paper card. IE your 1 lightning bolt can not be in both the 5th and 17th position unless you have actual "magical" cards.

-Edit- forgot to add that in your example you made, the final "shuffled" order would have an extremely dangerous correspondence to the order of the initial set. Without the extra layer of "randomization" at each step where you put an object into the set you exponentially lower the possible outcomes, down from there mathematical limits which is where you wanna be at the limit.
it would be akin to playing a long game resulting in a fair amount of groupings and card bias and then playing game 2 with only a couple cut's to the deck.

again hope this helps :)
Laqutis
 
Posts: 63
Joined: 08 Feb 2015, 05:07
Has thanked: 0 time
Been thanked: 2 times

Re: RNG/Shuffler

Postby tommygecko » 21 Feb 2015, 07:17

Man, i don't know, it just feels weirdly different compared to real life. And this discourages me abit from playtesting online. Is there a rng that mimics more closely to real life shuffling? I think it would be a nice addition to be able to choose from 2 different rng generators.
tommygecko
 
Posts: 13
Joined: 15 Jan 2015, 14:59
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby Laqutis » 21 Feb 2015, 15:02

tommygecko wrote:Man, i don't know, it just feels weirdly different compared to real life. And this discourages me abit from playtesting online. Is there a rng that mimics more closely to real life shuffling? I think it would be a nice addition to be able to choose from 2 different rng generators.
:| .... We will try the simple approach

You are wrong , science is right.
Two shuffle algorithms would be a waste of time. They would do the exact same thing.
Laqutis
 
Posts: 63
Joined: 08 Feb 2015, 05:07
Has thanked: 0 time
Been thanked: 2 times

Re: RNG/Shuffler

Postby BiasedDice » 23 Feb 2015, 15:24

There is, but I doubt it'll ever be done. Make a 3D model of a card, then use a physical simulation to shuffle the cards with virtual hands. Take in account the paper's density, the forces, the direction of all forces, shuffle like it would in real life with virtual hands.

Flawed RNG is when there is too much repetition. If you make a deck and out of 10 first hands you always draw 2 or 3 copies of the same card, that's flawed. That's what I experienced in OCTGN.
BiasedDice
 
Posts: 17
Joined: 15 Nov 2014, 04:45
Has thanked: 0 time
Been thanked: 0 time

Re: RNG/Shuffler

Postby Laqutis » 26 Feb 2015, 19:01

BiasedDice wrote:There is, but I doubt it'll ever be done. Make a 3D model of a card, then use a physical simulation to shuffle the cards with virtual hands. Take in account the paper's density, the forces, the direction of all forces, shuffle like it would in real life with virtual hands.

Flawed RNG is when there is too much repetition. If you make a deck and out of 10 first hands you always draw 2 or 3 copies of the same card, that's flawed. That's what I experienced in OCTGN.
NO just NO!!! ... this is just idiotic. Stop.

The math NEVER changes.
It doesn't matter how you rearrange the order of the set.
As long as the method is non-biased and non-influenced.

When you humanly shuffle you are taking the 60 card deck in ANY 1 of {60!/(60-60)!=8.32098711x10^81} possible orders; and reordering into ANY 1 of the 8.32098711x10^81 orders

When a Fisher/Yates shuffles it takes the 60 card deck in ANY 1 of {60!/(60-60)!= 8.32098711x10^81} possible orders; and is reordering it into ANY 1 of the 8.32098711x10^81 orders

If you have a fully functional and funded modern science facility with a huge data center, money for the HUGE amounts of
power to run and cool entire server farms, personnel to "program" large scale parameter physical simulation environments,
etc well actually 2 of them as i assume you want to play with someone then what ends up happening is.....

your magical physics simulator will take the 60 card deck in ANY 1 of {60!/(60-60)!= 8.32098711x10^81} possible orders; and reorder it into ANY 1 of the 8.32098711x10^81 orders

finally a flawed random number generator is ACTUALLY when for ANY reason (you guessed it!!!!)

the method does NOT take the 60 card deck in ANY 1 of {60!/(60-60)!=8.32098711x10^81} possible starting orders equally
OR
the method does NOT reorder it into ANY 1 of the 8.32098711x10^81 orders equally

TRUE NUMBER
| Open
short answer was used in post for readability
8.3209871127413901442763411832233643807541726063612459524492776964096x10^81 or
8,320,987,112,741,390,144,276,341,183,223,364,380,754,172,606,361,245,952,449,277,696,409,600,000,000,000,000


THE END
Laqutis
 
Posts: 63
Joined: 08 Feb 2015, 05:07
Has thanked: 0 time
Been thanked: 2 times

Re: RNG/Shuffler

Postby BiasedDice » 27 Feb 2015, 15:53

Use visual shuffling with USB gloves. Then ppl can shuffle with their own hands and see the cards being shuffled in 3D. Then nobody will be complaining about bad shuffling. No RNG at all, take in account paper's mass, density, texture and thickness, hardness, etc.

I dropped octgn after experienced too much order and predictable draws. Drawing the same card in two turns, first hand having two or three copies of the same cards, and that happening in many games one after the other.
BiasedDice
 
Posts: 17
Joined: 15 Nov 2014, 04:45
Has thanked: 0 time
Been thanked: 0 time

Next

Return to XMage

Who is online

Users browsing this forum: No registered users and 176 guests


Who is online

In total there are 176 users online :: 0 registered, 0 hidden and 176 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 176 guests

Login Form