copperdogma / mtgen

Magic: the Gathering Product Generator
Other
36 stars 13 forks source link

About duplicate cards #5

Closed goblin closed 7 years ago

goblin commented 7 years ago

Hi,

I'm not sure if that's actually an issue, but it appears there can be duplicates of a card in a booster.

While looking at the code, I'm thinking this MIGHT not be properly modeled (although I don't fully understand what's going on yet). It is sometimes possible that mtgen will come up with a duplicate, but whenever something like take[8]> is used, I believe it's translated to _.sample, which will never return duplicates.

Please let me know what you think (I'd love to be wrong).

goblin commented 7 years ago

OH and BTW, many thanks for doing this thing and for making it opensource! It kicks ass.

copperdogma commented 7 years ago

Glad you like!;)

Yeah as your link says, it may happen but it's not supposed to. If it does it's an error.

There are 1000 things I could do to make the generator be more true to life, including these sorts of errors, but it's exponentially more complex to do that. In end the I'd have to simulate their print sheets and human errors exactly, which is pretty much impossible.

The spirit of the generator is to let people simulate opening boosters. Adding all of that complexity for 1% more accurate "real life" simulation that most people may even want doesn't seem worth it.

What do you think?

On Fri, Dec 9, 2016 at 4:06 PM, goblin notifications@github.com wrote:

OH and BTW, many thanks for doing this thing and for making it opensource! It kicks ass.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/copperdogma/mtgen/issues/5#issuecomment-266147779, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnZobtHWROnaZni3asl_YmOQT4oMPnQks5rGd8MgaJpZM4LJcM7 .

goblin commented 7 years ago

Yeah, not really sure anymore if it's an error or not on their part ;-)

Right, yeah, you're right, it may not be worth fixing. It is a minor issue at most, and I can tell a possible fix would be quite cumbersome.

I'm thinking of redoing it a bit, allowing for secure multi-party generation of decks, but I'm not sure if I succeed ;-) I'll let you know if I'm done.

BTW2, I like your avatar! I've just watched a lot of Archer, it's great ;-)

copperdogma commented 7 years ago

That sounds fun! What would "secure multi-party generation of decks" be like??

I tried to make the code modular and as stand-alone as possible, but I certainly didn't have in mind what you're trying to do. I'm fascinated to see how it goes. Let me know!

Ah yeah I love Archer. Have you watched Rick & Morty? It's even funnier if that's possible.

On Sun, Dec 11, 2016 at 4:31 PM, goblin notifications@github.com wrote:

Yeah, not really sure anymore if it's an error or not on their part ;-)

Right, yeah, you're right, it may not be worth fixing. It is a minor issue at most, and I can tell a possible fix would be quite cumbersome.

I'm thinking of redoing it a bit, allowing for secure multi-party generation of decks, but I'm not sure if I succeed ;-) I'll let you know if I'm done.

BTW2, I like your avatar! I've just watched a lot of Archer, it's great ;-)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/copperdogma/mtgen/issues/5#issuecomment-266316912, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnZoYBJSjoE3hNwx3a9HgD6E1UPgAP5ks5rHIfJgaJpZM4LJcM7 .

goblin commented 7 years ago

Well, for starters, I want the players to be able to generate random boosters securely between them. So e.g. player X in Chicago, and player Y in Moscow, exchange a couple of random-looking messages and end up with a list of cards they've got. None of them know the opponent's cards, and both of them can be sure they were generated randomly. They can then print proxies, meet up in London and play them.

Later on, more advanced stuff like shuffling them and playing with them online, using stuff like libTMCG or something special-purpose (I'd love to learn more about zk-SNARKs). I've done some experiments with that in the past. We'll see how it goes ;-)

The first step is pretty easy. To generate a booster for player X, have X generate a large random number N, then send SHA256(N) to Y. Then Y generates another random number M and sends it to X, who then uses N xor M as the seed to a random-number generator, which he then uses to generate the booster. After the game, X reveals N, so Y can verify that all the cards in X's deck were valid.

I'm not that great with JavaScript, unfortunately. I tried to make it work on the commandline with node.js, but I don't think it's going to work. So for now I've re-implemented the crucial aspects of it in Perl. Perhaps using your stuff would be simpler if I did it all in the browser (though I'm not sure how to deploy mtgen locally).

In either case I'll let you know how it goes :-)

I hereby confirm putting Rick & Morty on my to-watch list, thanks! ;-)

goblin commented 7 years ago

Back to the original issue, I was worried that there is a slight inconsistency in the code. Let's take the first 2 queries for Kaladesh:

        { "query": "take[8]>from[kld-main]?rarity='c" },
        { 
          "querySet": [
            {
              "percent": "143/144",
              "query": "from[kld-main]?rarity='c"
            },
            {
              "percent": "1/144",
              "query": "from[kld-masterpiece-series]"
            }
          ]
        },

The first query won't get you any duplicates, but it can get you, say, a common Acrobatic Maneuver. Is there anything to stop the second query (querySet) from returning Acrobatic Maneuver again?

copperdogma commented 7 years ago

I just re-checked the code and it doesn't allow duplicate cards in a pack unless you specifically allow it. The code keeps a running set of all cards chosen so far and feeds them into the next query to ensure they're not chosen again. See mtg-generator.lib, generateCardSetFromPack(), where it uses randomCards() to choose the current query's cards.

copperdogma commented 7 years ago

As for your sharing of random boosters... You clearly love math and security protocols! Very cool. I'm terrible at both. I do have a server, though. Wouldn't that be way easier with server-side support? You could say "generate me X sets of [the following boosters]" and it would give you a single link. Each time you hit the link it will give you a different unique link to your set of boosters (as far as my site's concerned, these would be saved draws).

The first play could try to cheat by hitting the link more than once and looking at each of the generated sets, but the other players would never get theirs so they'd know that something was up.

So it would look like so:

  1. Master player would request 2 sets of X be generated.
  2. Site would generate link B and C, and give master player link A.
  3. Master player would give out link A to the second player.
  4. Master play would hit link A and be randomly given link C containing their draw.
  5. Second player would hit link A and be given the remaining link B containing their draw.

It would work for an arbitrary number of players.

goblin commented 7 years ago

Re the first comment: thanks for this, I'll read up more closely to see how it works.

Re the second: not requiring a trusted server is part of the fun! :-) Sure, this should be doable with a server as well, but my method ensures no-one can cheat: not the first player, not the server, not anyone :-)

copperdogma commented 7 years ago

Yeah I totally get you! I do this project 1/3 because I like Magic, 2/3 because I like programming.

Can I close this issue, then?

goblin commented 7 years ago

Yeah, I think it's pretty clear that duplicates shouldn't be that much of an issue, thanks!