It is currently 13 Sep 2025, 16:23
   
Text Size

Deck Generation Code

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Deck Generation Code

Postby jendave » 12 Aug 2011, 14:37

Hi,

I am starting to refactor the Deck generation classes and wanted some feedback before I do too much damage. There are two sets of classes (original vs. new in the New Game interface) that generate two and three color decks. I am looking to drop the older code since the new code creates much better decks. The older code can create five color decks so I would have to add that feature to the new code. Any concerns or insight from the long-timers?

Dave
jendave
 
Posts: 307
Joined: 01 Jun 2008, 07:19
Has thanked: 8 times
Been thanked: 21 times

Re: Deck Generation Code

Postby Braids » 12 Aug 2011, 15:47

i would suggest using Generators, the static methods in forge.CardFilter that return Generator<Card>, net.slightlymagic.braids.util.generator.GeneratorFunctions.filterGenerator() and GeneratorFunctions.selectRandom().

a lot of the existing code already does this.

don't bother with GeneratorFunctions.solidify() unless performance is noticeably terrible.


edit: it would also be nice if we could tell Forge to choose random colors for one or both decks instead of picking all the colors for both decks.
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. ;)
User avatar
Braids
Programmer
 
Posts: 556
Joined: 22 Jun 2011, 00:39
Location: Unknown. Hobby: Driving myself and others to constructive madness.
Has thanked: 1 time
Been thanked: 1 time

Re: Deck Generation Code

Postby Rob Cashwalker » 12 Aug 2011, 17:04

One thing I began to play with but abandoned it, was to centralize the land counting code. Given any card list, calculate required lands, with dual land options. It was easy to write that in-line with all the other code for the decks generation. It was getting rather messy trying to adapt it to be more generic, but not impossible, I just didn't get back to it yet due to the repo shifts, and now working on the GUI..

Ditching the old deck generators has been on my list for a while. Writing a five-color deck generator following the examples of 2 and 3 colors may be possible, especially if much of it is refactored to be generic.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Deck Generation Code

Postby jendave » 15 Aug 2011, 16:49

I did a real quick and dirty Generate5ColorDeck class. Please try it out from the NewGame screen. I figure that if it works OK, then I use it as a basis for refactoring.
jendave
 
Posts: 307
Joined: 01 Jun 2008, 07:19
Has thanked: 8 times
Been thanked: 21 times

Re: Deck Generation Code

Postby Braids » 16 Aug 2011, 16:26

jendave wrote:I did a real quick and dirty Generate5ColorDeck class. Please try it out from the NewGame screen. I figure that if it works OK, then I use it as a basis for refactoring.
it is a pity that i don't see a single Generator<Card> in there. one can use it almost interchangeably with CardList and get much better performance and less heap use.

edit: if you use that code as a basis for refactoring, you will undo a lot of the performance improvements i made a few weeks ago. :?
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. ;)
User avatar
Braids
Programmer
 
Posts: 556
Joined: 22 Jun 2011, 00:39
Location: Unknown. Hobby: Driving myself and others to constructive madness.
Has thanked: 1 time
Been thanked: 1 time

Re: Deck Generation Code

Postby jendave » 16 Aug 2011, 17:15

Braids wrote:
jendave wrote:I did a real quick and dirty Generate5ColorDeck class. Please try it out from the NewGame screen. I figure that if it works OK, then I use it as a basis for refactoring.
it is a pity that i don't see a single Generator<Card> in there. one can use it almost interchangeably with CardList and get much better performance and less heap use.

edit: if you use that code as a basis for refactoring, you will undo a lot of the performance improvements i made a few weeks ago. :?
The class will server as a basis for functionality, not implementation. The Generate5ColorDeck does indeed generate a 60 card deck with 5 colors. I tend to develop in an iterative way. The next step is to use the generators to make it faster, then pull out the dependencies to make it testable and flexible. Considering I spent about 15 minutes creating the class not much is lost if I completely redo it in the end :-).
jendave
 
Posts: 307
Joined: 01 Jun 2008, 07:19
Has thanked: 8 times
Been thanked: 21 times

Re: Deck Generation Code

Postby Braids » 16 Aug 2011, 22:57

jendave wrote:The class will server as a basis for functionality, not implementation . . . I tend to develop in an iterative way. The next step is to use the generators to make it faster, then pull out the dependencies to make it testable and flexible.
oh, ok. thanks for clarifying. that's some nice work for 15 minutes!

i've been thinking about deprecating CardList.filter. but i suspect that would be massively unpopular. :wink:

i usually bounce back and forth between test driven development and coding in a top-down way, sometimes using methods and classes that don't yet exist. combine that with needing to change code incrementally on the trunk, and things get interesting!
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. ;)
User avatar
Braids
Programmer
 
Posts: 556
Joined: 22 Jun 2011, 00:39
Location: Unknown. Hobby: Driving myself and others to constructive madness.
Has thanked: 1 time
Been thanked: 1 time

Re: Deck Generation Code

Postby Accountancy » 27 Aug 2011, 04:21

Just wondering if there's any specific benefits for the new deck generator code? I know jendave says they generate "better" decks, but I'm not sure what metric is being used for this? They include more vanillas and bad cards on average than the original deck generator, less dual lands (which, though I'm glad to see less shocks and alpha lands, it makes GOOD spells impossible to cast in anything more than two coloured decks) and the decks are just boring.

The only reason I used the random deck generator was to get wacky under-powered decks with crazy older cards so that the computer actually stood a chance for once and I could still have fun with the weird cards, but now the decks are boring and the computer always wins, so I'm not sure what the improvement is.
Feel free to tell me if I'm wrong, but that's just how I feel and I would like wackier decks please, thank you.
Accountancy
 
Posts: 230
Joined: 14 Aug 2009, 12:39
Has thanked: 22 times
Been thanked: 2 times

Re: Deck Generation Code

Postby Sloth » 27 Aug 2011, 06:46

Accountancy wrote:Just wondering if there's any specific benefits for the new deck generator code? I know jendave says they generate "better" decks, but I'm not sure what metric is being used for this? They include more vanillas and bad cards on average than the original deck generator, less dual lands (which, though I'm glad to see less shocks and alpha lands, it makes GOOD spells impossible to cast in anything more than two coloured decks) and the decks are just boring.

The only reason I used the random deck generator was to get wacky under-powered decks with crazy older cards so that the computer actually stood a chance for once and I could still have fun with the weird cards, but now the decks are boring and the computer always wins, so I'm not sure what the improvement is.
Feel free to tell me if I'm wrong, but that's just how I feel and I would like wackier decks please, thank you.
I'm on Accountancy's side here. My personal taste concerning multiples of cards in a random deck aside, there are two issues I have with the new random deck generators:

1. Cards with RemAIDeck:True are removed from all decks (even those of the human). It was a lot of work for me (and other people) to split RemAIDeck:True and RemRandomDeck:True (just for the use in random deck generators) and now they are lumped together again in the only random deck generator available. :(

2. No non-creature artifacts are added.

Because of this, nearly 2000 cards are omitted from the current random card pool for the human (and as Accountancy noted most of the interesting ones). Are you ok with me fixing these two issues in the random deck generators?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Deck Generation Code

Postby Accountancy » 27 Aug 2011, 13:26

If the deck generator code does get another look (and I'm hoping it does) I think it would be a good idea to actually figure out what people want and what makes a fun deck to play. Personally I think having a pretty truly random spread of cards in the colours the deck plays would be nice and including more non-basic lands (as I said, maybe 2-3 random non-basics, including duals, but excluding off-colour lands), for spells it's good to have a curve with a few expensive spells to top it off.
Rough statistical break-down:
Coloured cards
3-8 one drops
4-11 two drops
3-10 three drops
3-7 four drops
3-7 five drops
4-8 six to sixteen drops
Lands
At least 2 basics of each colour
In more than one coloured decks, at least 30% should be duals, preferably random duals (including lorwyn hybrids, painlands, saclands, vivids and future sights)
2-5 completely random, but not off-colour non-basics, single-coloured deck should have a bit more than multicoloured
Finally, it would be nice to see artifacts turning up a bit more too, maybe dual-coloured decks could get a couple colour-making artifacts and otherwise just a random spread.

Sorry for the essay, I just love playing randomly generated decks against the AI and I want to help make it as good as it can be.
Accountancy
 
Posts: 230
Joined: 14 Aug 2009, 12:39
Has thanked: 22 times
Been thanked: 2 times

Re: Deck Generation Code

Postby Rob Cashwalker » 28 Aug 2011, 00:08

The new random deck generators I originally wrote, (2 and 3 color) did the curve thing. Having more consistent decks that were still randomly selected seemed like a good idea.

Adding artifacts was a bit difficult, because there wasn't an easy way to determine if an artifact had color associations that wouldn't fit with the colors of the deck. Hoepfully we will soon have the oracle text included in the card object, so checking for colors in the artifact will be easier.

What jendave wanted to do was to clean them up, make them consistent with some of our recent developments. The old generators used old code that wouldn't work well with these advances. We can certainly make additional generators that restore the singleton preference or remove vanilla creatures...
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Deck Generation Code

Postby jendave » 29 Aug 2011, 07:32

Since I have not been able to work as much on Forge lately as I would like, I'll add them back. The classes were still there. I just removed the code that allowed you to use them.
jendave
 
Posts: 307
Joined: 01 Jun 2008, 07:19
Has thanked: 8 times
Been thanked: 21 times

Re: Deck Generation Code

Postby Sloth » 29 Aug 2011, 10:33

jendave wrote:Since I have not been able to work as much on Forge lately as I would like, I'll add them back. The classes were still there. I just removed the code that allowed you to use them.
I don't know if that was necessary. I've added support for artifacts and cards with RemAIDeck:True to the new deck generators. The only big difference is:
strictly singleton vs some multiple copies

As a long term goal we can aim for a generate deck window where the user can set some parameters and the preferences are saved.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Deck Generation Code

Postby Rob Cashwalker » 29 Aug 2011, 11:54

Sloth... I was wondering why I was suddenly seeing artifacts in the new 2 color generator....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Deck Generation Code

Postby Sloth » 29 Aug 2011, 14:02

Rob Cashwalker wrote:Sloth... I was wondering why I was suddenly seeing artifacts in the new 2 color generator....
Sorry Rob. Maybe I was a bit quick in adding that. I looked through all artifacts though and added RemRandomDeck to the really bad stuff.

EDIT: I'm currently working on expanding the nonbasic lands.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 21 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 21 users online :: 0 registered, 0 hidden and 21 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 21 guests

Login Form