Dominion Strategy Forum

Dominion => Dominion General Discussion => Topic started by: () | (_) ^/ on October 29, 2012, 10:27:03 am

Title: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: () | (_) ^/ on October 29, 2012, 10:27:03 am
DISCLAIMER: Yes, I know other Dominion Randomizers exist, even in excel.  Yes, I'm attempting to reinvent the wheel.

======

I'm having trouble coding the interactions of Young Witch (specifically the bane requirement) and Black Market.

As of now, I am:

Selecting the Kingdom
Checking for Young Witch, if so, assigning a bane.
Checking the new kingdom (which includes a bane, if there is one) for Black Market, if so assigning Black Market cards.
If Young Witch is in the Black Market, assigning a Bane which cannot be in the Black Market deck.

The red text is what I'm having trouble with, coming up with circular references.

Any help?

I'm good at Excel, and good at translating code into English and vice versa, so don't feel like you need my code to check for silly errors.  In real life when one plays with YW/BM, there are several "common sense" things that we do that don't easily translate into code.  Any thoughts?  Anyone know how iso/DougZ codes this interaction?
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: Captain_Frisk on October 29, 2012, 10:36:31 am
I don't think there's an explicit rule on how to build the black market deck.

If it was me, I'd put all of the cards in a big collection. (Disclaimer - I'm a brute force programmer)

First - pick 10 randomly (removing the card from the collection at each pick)
If Young Witch, get the sub selection of 2-3 cost cards remaining in master collection, pick one, remove it
If Black Market, build black market deck (remove cards from master collection as you do this - just as you did for the random pick 10)
If Black Market deck has YW, get sub selection of 2-3 cost cards remaining in master collection, pick one, remove it

Now - there is an edge case in which the black market deck has ALL of the 2-3 cost cards remaining.  In that case, I'd probably rip one out of the BM deck - and then insert another one to take its place.
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: Qvist on October 29, 2012, 11:25:49 am
I don't know if I got your problem right, but I can't see the problem. I don't know much about Excel programming, but I would solve it like that in pseudo code.
Code: [Select]
randomizer = array( 'Adventurer', ..., 'Black Market', ..., 'Young Witch' );
randomizer.shuffle();
kingdom = randomizer.pop( 10 );
handle_YW( kingdom );
bm_deck = handle_BM( );
handle_YW( bm_deck );

if( kingdom.contains( 'Black Market' ) ){
  bm_deck = randomizer.pop( bm_size );
}

function handle_YW( deck ){
  if( deck.contains( 'Young Witch' ) ){
    kingdom.push( randomizer.filter( 'Cost<=3' ).pop( 1 ) );
  }
}

function handle_BM( ){
  bm_size = 20;
  if( kingdom.contains( 'Black Market' ) ){
    bm_deck = randomizer.pop( bm_size );
  }
  return bm_deck;
}


Edit: Haha, CF, basically the same solution, but in other output.
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: Jimmmmm on October 29, 2012, 12:02:45 pm
Anyone know how iso/DougZ codes this interaction?

Not sure, but I know I once finished a game with 11 Schemes (http://forum.dominionstrategy.com/index.php?topic=972.msg14895#msg14895).
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: ycz6 on October 29, 2012, 02:36:36 pm
http://forum.dominionstrategy.com/index.php?topic=2883.0
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: Davio on October 29, 2012, 03:00:53 pm
There's a reason BM is a promo card, I mean, look at all the hoops it makes us jump through!

There aren't even clear rules on how many cards you need to put in there, just some general guidelines and "as long as both players agree".
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: meandering mercury on October 29, 2012, 05:02:16 pm
Hm, here's how I would have done it:

Column A: card name
Column B: boolean variable, 1 if the card is $2 or $3, 0 otherwise
Column C: random number from 0 to 1

-------------

Sort the table by table by Column C, the random number, from largest to smallest. The first ten cards are your kingdom and they'll be randomly chosen.

If BM is in the kingdom, then cards 11 to (10 + N) are in the BM deck, where N is the size of the BM deck.

If either YW is in the kingdom or YW is in the BM deck and BM is in the kingdom, then the first card from card #(11 + N) to the end which satisfies Column B == 1 is the bane card. There are a couple of ways I think you can do this, but I'm sure you can come up with one.

(If there are no $2 or $3 cards in the remainder of the deck ... uhh ... throw an error and try again, I guess)
Title: Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
Post by: Grujah on October 29, 2012, 06:49:12 pm
Simple way:
Choose 10.
Choose Bane from remaining N-10, irregardless wheter YW is chosen or not.
If BM is chosen, choose M BM cards from remaining N-11.
If YW, include preselected Bane.

This has a sideeffect that you cannot have all 2s and 3s selected as kingdom+BM at same time, but I don't think it matters that much.

I don't know much about what excell can do, but I'd do it in this way in higher programming language:
Choose 10.
If BM is in, choose BM deck.
If YW is in, check if any 2s or 3s are free, if yes, choose one as bane. If not, choose one from BM as bane and replace it with something else not chosen yet.

You probably have some kind of structure for each card, which contains name, cost, and whether it is chosen as kingdom/BM/non-chosen.