Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: [1]

Author Topic: Coding a Randomizer in Excel // How to Deal with YW & BM?  (Read 4401 times)

0 Members and 1 Guest are viewing this topic.

() | (_) ^/

  • Minion
  • *****
  • Offline Offline
  • Posts: 632
  • Shuffle iT Username: p4ddy0d00rs
  • Nemo dat quod non habet.
  • Respect: +526
    • View Profile
    • BGG profile
Coding a Randomizer in Excel // How to Deal with YW & BM?
« on: October 29, 2012, 10:27:03 am »
0

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?
Logged

Captain_Frisk

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1257
  • Respect: +1263
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #1 on: October 29, 2012, 10:36:31 am »
0

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.
Logged
I support funsockets.... taking as much time as they need to get it right.

Qvist

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2400
  • Shuffle iT Username: Qvist
  • Respect: +4085
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #2 on: October 29, 2012, 11:25:49 am »
0

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.
« Last Edit: October 29, 2012, 11:28:23 am by Qvist »
Logged

Jimmmmm

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1762
  • Shuffle iT Username: Jimmmmm
  • Respect: +2019
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #3 on: October 29, 2012, 12:02:45 pm »
0

Anyone know how iso/DougZ codes this interaction?

Not sure, but I know I once finished a game with 11 Schemes.
Logged

ycz6

  • Minion
  • *****
  • Offline Offline
  • Posts: 676
  • Respect: +412
    • View Profile
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4787
  • Respect: +3412
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #5 on: October 29, 2012, 03:00:53 pm »
0

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".
Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

meandering mercury

  • Ambassador
  • ***
  • Offline Offline
  • Posts: 34
  • Respect: +36
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #6 on: October 29, 2012, 05:02:16 pm »
0

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)
Logged

Grujah

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2237
  • Respect: +1177
    • View Profile
Re: Coding a Randomizer in Excel // How to Deal with YW & BM?
« Reply #7 on: October 29, 2012, 06:49:12 pm »
+1

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.
Logged
Pages: [1]
 

Page created in 0.039 seconds with 21 queries.