april / decklist

The code behind decklist.org, which generates DCI Registration Sheets.
https://decklist.org/
MIT License
44 stars 20 forks source link

Invalid lists created when cards are in mainboard and sideboard #52

Closed april closed 6 years ago

april commented 6 years ago

If you have a mainboard of 4 Mountain and a sideboard of 4 Mountain, it will create a decklist with 8 Mountains in the main and 4 in the sideboard.

I think this is related to @Nightfirecat's recent changes.

Nightfirecat commented 6 years ago

Hm, that's not good. I'll take a look at that in a few hours once I'm off work.

april commented 6 years ago

Pretty sure it's somewhere in list_add() and list_merge(), but the code is pretty opaque.

There has probably got to be a more immutable way to do the decklist parsing, maybe a refactoring job someday. :)

Nightfirecat commented 6 years ago

I disagree, Decklist.parse('1 mountain', '1 mountain') correctly reports that there's one mountain in the maindeck and sideboard. I'm starting to debug this now, so I should hopefully spot the issue soon.

Nightfirecat commented 6 years ago

Found it... validateDecklist's combineDecks internal function ended up modifying the maindeck because it did not deep-copy cards as it added them to the "combined list", thus holding pointers to it when it incremented its quantity when sideboard copies were found later.