Digression: Shuffling

Today we aren't going to speak about development of 2.0.

When you talk about online card games, you can be sure that the shuffler will be mentionned at one time or another. Often with bad remarks.
There has been several mention of it in the comments of my previous post, but I don't feel that it's something I can just answer in one short comment. Moreover, I'm sure it's a first class topic which everyone is interested in.

Hence today's post: How shuffling is currently done in 2.0, and what am I thinking about it. 

But first,a small recap on how shuffling works in real life.
If you are truly honest about it, when you shuffle you are moving some packs of cards around, and interleaving some. A bit. I don't know many players who truly, completely, absolutely mix all the cards so that no card should be neighbouring one of the cards it was when the shuffle began (except thanks to sheer luck).
There are even players who take advantage of that. We surely all know someone who prepares his Magic decks by interleaving 2 spells + 1 land. Why ? Because they know that they wont totally mix all the cards, so that the lands should still be more or less evenly distributed in the shuffled deck, on average.

Conclusion: we are pretty bad shufflers.

Computers, on the other hand. Are very good at this. They take any card, with an equal probability, and they put it anywhere, again with equiprobability. Now, here's your chance of using the Probability & Statistics lecture you took at uni. If you apply such a distribution to a set of cards like 66% spells and 33% lands, you will get more than a fair probability of having big clumps of lands. "More than a fair probability" really means that it will happen time and again. In any case, surely a lot more than it would in real life.

Now, this is frustrating. It's all about playing a fun game, isn't it ? If having a perfect shuffler ruins the game, why not have an imperfect one then ? I'll answer this question just below. But you should be aware that there's several things you can do about it:

  1. A very good deck should be carefully built, with the right amount of mana, but also with a bit of manafixing, just to be able to survive the games which are not too good shuffling-wise.
  2. There's a reason why a match should always be the best out of 3 or 5 games. First it's fun to use a sideboard to adapt to your opponent. But also because the more you play, the less luck should influence the result. I guess you can be out of luck for one game. But to be out of luck three games in a row is… really being out of luck!
  3. Don't forget to mulligan if you can't take a good start in the game. Starting well is über-important. And with a good start, you can probably survive a few bad draws. Keeping a not-so-good hand and hoping to "draw a land" is a sure strategy to loose (don't forget there's roughly 66% chances you won't draw that land). If you don't have the right mix of lands and spells, mulligan down to 6. If again you are out of luck, go down to 5. Here things get a bit harder for you… But as in point 2. Being out of luck three times in a row should be an exception. If it happens too often, then maybe your deck isn't built that well. Mulligan is too often disregarded, although it's an excellent tool to reduce the luck factor and increase your chances to win the game.

Ok, enough chit-chat, let's go back to 2.0. Right now I haven't made any effort to build a customized shuffler. I just built a perfect one. From all the test games I have done yet, it was fine. We haven't played that many games, though.

Should the shuffler of 2.0 exhibit the same defects as the current one (yeah, it gets on my nerves more often than I can cope with), I would create a game-specific shuffler. I've already thought about that: it would still be able to produce any arrangment of cards, but it would do so with a higher probability for "well" shuffled decks. This would be more like real-life, and would be more fun (which is the most important point IMHO). Of course, you would be free to use this "cheating" shuffler, or not.

But there's a saying in computer science which says: "If it ain't broken, don't fix it." So let's wait and see.
2.0 takes security against cheaters very seriously. You can not trust your opponent to shuffle his deck. Even less with open source software. So what happens (I'm simplifying a bit here), is that everyone shuffles your deck, except yourself! So to use the "better" shuffler, you should ask your opponent to enable it. And to be fair, you should enable it for them too… 

Well, it was a lot longer than I thought it would be. Thanks for being with me!


Explore posts in the same categories: OCTGN.net

5 Comments on “Digression: Shuffling”

  1. AkumAPRIME Says:

    you said equiprobability… cool word.
    The only thing about a totally random shuffler, is that statistically, clusters are going to occur. It’s a pattern you can see just by flipping coin a hundred times. So, idk if your shuffler takes this into account somehow but… it would be nice to artificially reduce clusters/clumps/we you wanna call me.

  2. eyerouge Says:

    About irl-shuffling: The rules state that the deck shoudl be randomized. Since there is no randomization in real life you’d do the next best thing and try to get as close as possible. If people like playing with landstack and such, great, let them have the option: Even though it’s against the rules in most games there could be more others where it would have to be implemented, so in a sense it can open up new horizons, and it’s great letting the players decide if they want to use it or not. Thumbs up.

    About irl-shuffling there’s this short introtext. I haven’t checked the math, but it seems to work out: http://www.kibble.net/magic/magic09.php

    idea one
    The site also gave me an idea that’s already seen in pokergames: The possibility to show probability for different events [with options to filter some maybe] (http://www.kibble.net/magic/magic08.php) in-game, as a part of octgn 2. Why encourage players to run third part software (which they always could if they wanted) when you can integrate it from the start? πŸ˜‰

    Many, including myself, would argue it kills a part of the game. On the other hand, that would depend on what the players want, just like the landsstacking case. Or one could argue that it only shows reality in numbers and that a smart player would take the advantage even if the other players wouldn’t (3:d party software, pen/paper, calculator etc). By having the octgn 2 having it built in you’d a) eliminate 3:d party crap and deliver better software b) make the players more equal c) open up the doors for game where the numbers would matter.

    idea two
    Some way for the players to create macro-like funtions that are a) associated with the game and/or b) a specific deck for cards and they should be able to be executed from a menu/button that displays somewhere when the “time is ripe” on the table/in the hand/whatever.

    In most cases this would not be needed since cardgames are pretty easy to play irl. However, if you use MTG as an example you’ll soon get to see the complexity of some decks that requires you to pull of 3-4 card combos with a lot of laying on the table, digging in the grave, twisting and turning, etc etc. All of this could really be made scriptable with ease. That way you’d also be able to both record games and creta demogames. It isn’t as complex as it sounds but should add crazy functionality. Please think about it πŸ˜‰

  3. Btrice Says:

    You didn’t mention what type of shuffling algorythm you chose. And I have done plenty of work in the past (results located on CF.com) that showed that the major problem lies in how the random number generator works. What scheme are you using to generate the numbers? The standard randn-type function or a higher level process such as the MT?

  4. jods Says:


    the shuffling algorithm is actually a bit more complex than I just outlined above, the main reason being the anti-cheating policy.

    It actually is a multi-step process. If you want to shuffle your library, you start by encrypting and shuffling it (using the standard .NET random number generator). That’s step #1. Then you send the result to the server.

    Step #2: The server splits your decks in whatever random way he wishes, and send one part to each other player than you (in my implementation, the split doesn’t shuffle at all).

    Step #3: Each client shuffles the part of the deck it receives in any way he want to shuffle it. Again, the OCTGN.net implementation is just using the standard .NET random number generator. The result is sent back to the server.

    Step #4: The server merges all parts back into one pile. This process is not a shuffling one, but it uses a special policy. If the wanted slot for one card is already used, the card is put in the first next free slot. So the final position are more or less decided at step #3, but not really. This is a bit tricky, but it prevents anyone trying to influence the result of the sort (like stacking lands well).

    I went a bit technical here, but I think you asked for it πŸ˜‰
    I don’t know what the actual .NET random number generator is, and I doubt it’s a Mersenne one. This could be easliy checked though (and substituted, if we really need it).

  5. Btrice Says:

    Wow, that is a pretty hardcore implementation. I doubt that the .NET is Mersenne either. When you say “Each client shuffles the part of the deck it receives in any way he want to shuffle it.” I imagine you are going to probably have the standard Fisher Yates or Riffle etc. Might I suggest my more humanesque riffle shuffle where instead of taking piles AAAA and BBBB and just turning them into ABABABAB, you “stick” cards together randomly (in my work I chose a random number from 1-3) then riffle them so that there are more variations (AABABBBA, ABABAABB, etc etc) I found that in my work to produce *slightly* better results. Good show as always man πŸ™‚

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: