Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: 1 2 [3] 4 5 ... 13  All

Author Topic: Dominiate: a Dominion simulator that runs on the Web  (Read 57028 times)

0 Members and 2 Guests are viewing this topic.

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #50 on: September 13, 2011, 09:41:50 pm »
0

I've been thinking of having a "state.current.activeCards" variable, which contains the stack of cards that are currently being resolved. Kind of like state.current.inPlay, but excluding the cards that have been completely resolved.

So it might be ["Apprentice"] or ["Golem", "Tactician"] or ["King's Court", "King's Court", "Masquerade"], to name a few relevant situations.
Logged

danshep

  • Navigator
  • ****
  • Offline Offline
  • Posts: 70
  • Respect: +13
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #51 on: September 13, 2011, 11:30:07 pm »
0

I think you might need to be able to pass in the current trasher to the trash rules, if only so that you can let the trash rules be checked from the play rules, so just knowing the active cards is play isn't going to cut it.

The default play rule for bishop/apprentice/salvager is going to need to check if there is a trash target for card first, so it's going to need to be able to call the trash rules, asking whether there is a card that could be trashed.

You could get around this with a 'theoriticalTrashPriority' method which messes with the activeCards array before calling the trashPriority method, but I think that might make for some confusing code.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #52 on: September 14, 2011, 12:24:29 am »
0

If I understand what you're suggesting, there's already the equivalent for Shanty Town. To check whether a Shanty Town will succeed, you have to not count the Shanty Town itself, so there's a flag that determines this. I think it's worth the extra code to determine whether an action is useful.
« Last Edit: September 14, 2011, 12:32:53 am by rspeer »
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #53 on: September 15, 2011, 03:41:30 am »
0

I made some updates to the simulator:
  • The interface is shinier, it includes "stop" and "reset" buttons, and "play 100" does what it's supposed to.
  • There is a "win-o-meter" that graphically shows who has won how many games, including the margin of error. There's a decisive winner when the margin of error crosses the 50% mark.
  • Decision functions now take a new argument called "my" that the AI can use to refer to its own PlayerState, instead of "state.current", which is in fact wrong if it's reacting on someone else's turn! This leads to nice idioms such as my.hand or my.countInDeck("Platinum").
Note that "state.current" can only be replaced by "my" on AI decision functions, not when defining cards. Cards don't have a "my".

Here's a new list of relatively easy cards for people to try implementing:
  • Cutpurse
  • Fortune Teller
  • Vault
  • Feast
  • Talisman (use a buyInPlayEffect)
  • Hoard (I'd left this one off the list accidentally)
  • Lookout
  • Bishop (you don't have to write a good AI strategy for it yet, that's hard)
  • Watchtower
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4733
  • Respect: +3300
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #54 on: September 15, 2011, 03:55:56 am »
0

I'll do Watchtower today, that's a bit of a challenge (AI part), yet easy enough to plow through with some infallible Vulcan logic.

Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #55 on: September 15, 2011, 11:55:45 am »
0

I forgot the card effect of Watchtower isn't that easy because of the two decisions you make (reveal Watchtower? Put the card on the deck or trash it?) upon gaining a card.

These decisions could be modeled after chooseBaronDiscard.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #56 on: September 15, 2011, 12:03:55 pm »
0

Speaking of adding AI code, there's now literate documentation for basicAI.coffee. It both explains the default strategies, and it describes how the decision functions work. So if anyone (in addition to Davio) wants to take on a card that requires a new kind of decision, go ahead!

Some suggestions of cards that just need a new decision type: Apothecary, Bureaucrat, Chancellor, Hamlet, Herbalist, Island, Jester, Library, Loan, Mine, Mining Village, Minion, Mint, Pearl Diver, Pirate Ship, Royal Seal, Rabble, Scout, Spy, Torturer, Wishing Well

Also, Counting House, Navigator, and Trading Post are still out there and don't need new decision types.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #57 on: September 15, 2011, 08:25:33 pm »
0

Tactician is finally in, and so is Wishing Well. We're up to 80 out of 141 cards!
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #58 on: September 16, 2011, 02:55:20 am »
0

And an important update: Dominiate now has error handling.

Okay, so it just pops up a JavaScript alert, which I recognize is design straight out of 1995, but as with other aspects of the design it'll get better. At least it doesn't just silently brood when it hits an error anymore.
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4733
  • Respect: +3300
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #59 on: September 16, 2011, 03:28:55 am »
0

I ran into some complications with Watchtower.

- First of all, it's not "really" a Reaction card in the sense that it doesn't do anything when an opponent plays an attack card. It's currently the only of the 4 (Moat, SC, HT are the others) that does this.
- How to decide whether to trash or put on deck or do nothing?

I guess it should follow these basic rules:
- If the card's in the trashpriority list, trash it
- If it's a pure victory card, don't reveal (let it go to discard)
- Else put it on deck

This doesn't catch the edge cases of Ambassadoring players, Gardening players (and perhaps Golem/Counting House) wanting Coppers & Curses and Tournament players wanting Provinces on top, but these can built in if need be.
Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #60 on: September 16, 2011, 04:18:25 am »
0

Those rules sound right to me.

I don't know what I was thinking when I said Watchtower would be straightforward. But anyway, you can define what it does as a "gainReaction" function (where the other reaction cards have "attackReaction") -- which I hadn't actually hooked into the game state until now. You should 'git pull' to get that new code.

To see if an AI wants to trash a card, you can give it a trash decision between that card and null: if this.chooseTrash(state, [card, null]) is card... This is what wantsToTrash() does to count the number of cards the AI would like to trash.
« Last Edit: September 16, 2011, 04:20:27 am by rspeer »
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4733
  • Respect: +3300
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #61 on: September 16, 2011, 06:00:18 am »
0

Those rules sound right to me.

I don't know what I was thinking when I said Watchtower would be straightforward. But anyway, you can define what it does as a "gainReaction" function (where the other reaction cards have "attackReaction") -- which I hadn't actually hooked into the game state until now. You should 'git pull' to get that new code.

To see if an AI wants to trash a card, you can give it a trash decision between that card and null: if this.chooseTrash(state, [card, null]) is card... This is what wantsToTrash() does to count the number of cards the AI would like to trash.
Isn't there a bug?

# - What happens when this card is in hand and its owner gains a card?
  gainReaction: (state) ->

  reactToGain: (player, card) ->
    this.gainReaction(player, card)


You use (state) and (player,card), I think the first one needs to be edited.
Also in gameState.coffee you only pass player, not card...
Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #62 on: September 16, 2011, 08:37:44 am »
0

Gah, yes.

It should probably take (state, player, card).
« Last Edit: September 16, 2011, 08:44:36 am by rspeer »
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4733
  • Respect: +3300
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #63 on: September 16, 2011, 08:49:23 am »
0

How about this for passing the actual card?
I was wondering if passing 'card' instead of the top card of the discard pile would create a duplicate...

Code: [Select]
gainCard: (player, card, suppressMessage=false) ->
    if card in @prizes or @supply[card] > 0
      if not suppressMessage
        this.log("#{player.ai} gains #{card}.")
      player.discard.push(card)
      if card in @prizes
        @prizes.remove(card)
      else
        @supply[card] -= 1
      if @supply["Trade Route"]? and card.isVictory and card not in @tradeRouteMat
        @tradeRouteMat.push(card)
        @tradeRouteValue += 1
      for i in [player.hand.length-1...-1]
        reactCard = player.hand[i]
        if reactCard.isReaction
          reactCard.reactToGain(state, player, player.discard[player.discard.length-1])
    else
      this.log("There is no #{card} to gain.")


How's this for a rudimentary Watchtower:
Code: [Select]
makeCard 'Watchtower', action {
cost: 3
isReaction: true
playEffect: (state) ->
handLength = state.current.hand.length
if handLength < 6
state.drawCards(state.current, 6 - handLength)
gainReaction: (state, player, card) ->
if player.ai.chooseTrash(state, [card, null])
player.discard.remove(card)
if (not card.isVictory) or (card.isVictory and (card.isAction or card.isTreasure))
player.discard.remove(card)
player.draw.push(card)
}
« Last Edit: September 16, 2011, 09:09:56 am by Davio »
Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1476
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #64 on: September 16, 2011, 10:39:22 am »
0

Quote
Code: [Select]
if (not card.isVictory) or (card.isVictory and (card.isAction or card.isTreasure))

Why do you want (!Vic) or (Vic and (Ac or Tr)) ?
a) doesn't that put Curses on the Draw, given you don't want to trash them (for what ever reason, say Gardens)
b) isn't what you really want
Code: [Select]
if (card.isAction or card.isTreasure)
Or what am I missing?
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #65 on: September 16, 2011, 11:51:55 am »
0

Code: [Select]
I was wondering if passing 'card' instead of the top card of the discard pile would create a duplicate...

A key decision I made early on in the code is that cards are singleton objects. So, for example, you can refer to c.Estate in multiple places without worrying if it's this c.Estate or that c.Estate, just like multiple arrays can contain the number 3 without caring whether it's this 3 or that 3.

The main thing you need to make sure of is that when you add a card to one list, you remove it from another (or from the supply). And you're doing that correctly when you do
Code: [Select]
player.discard.remove(card)
player.draw.push(card)
Logged

Davio

  • 2012 Dutch Champion
  • *
  • Offline Offline
  • Posts: 4733
  • Respect: +3300
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #66 on: September 16, 2011, 05:30:46 pm »
0

Quote
Code: [Select]
if (not card.isVictory) or (card.isVictory and (card.isAction or card.isTreasure))

Why do you want (!Vic) or (Vic and (Ac or Tr)) ?
a) doesn't that put Curses on the Draw, given you don't want to trash them (for what ever reason, say Gardens)
b) isn't what you really want
Code: [Select]
if (card.isAction or card.isTreasure)
Or what am I missing?
There should have been an else there.

The second part can indeed be simplified by (card.isAction or card.isTreasure), guess it was just the regular Friday screen-stare blindness.
I constructed some weird condition worrying about mixed Victory cards.

So this is better:
Code: [Select]
makeCard 'Watchtower', action {
cost: 3
isReaction: true
playEffect: (state) ->
handLength = state.current.hand.length
if handLength < 6
state.drawCards(state.current, 6 - handLength)
gainReaction: (state, player, card) ->
if player.ai.chooseTrash(state, [card, null])
player.discard.remove(card)
else if card.isAction or card.isTreasure
player.discard.remove(card)
player.draw.push(card)
}
Logged

BSG: Cagprezimal Adama
Mage Knight: Arythea

michaeljb

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1361
  • Shuffle iT Username: michaeljb
  • Respect: +1953
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #67 on: September 16, 2011, 05:56:48 pm »
0

rspeer, I have a question about something I actually already asked you about on github, but I think it would be beneficial to post the question here as well.

How exactly should the output (via state.log) be formatted? Obviously Isotropic is a great standard to look at, but I'm specifically curious about the use of ellipses--Isotropic constantly uses them, and some of the cards in cards.coffee use them, but not all of them.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #68 on: September 16, 2011, 06:15:07 pm »
0

If you want to be more consistent than me about output, that's great.

I generally use the ellipses when I'm adding more output to an effect that I know has already output something. Isotropic uses them to represent the depth of the action stack, which is a fancier and better idea. I haven't made an action stack yet.

That second Watchtower reaction will work, but it never consults the AI. Here's one possible solution that could be re-used for Royal Seal:
Code: [Select]
if player.ai.chooseToGainOnDeck(state, card)
And the default chooseToGainOnDeck on the BasicAI would then be:
Code: [Select]
(state, card) -> card.isAction or card.isTreasure
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #69 on: September 17, 2011, 04:33:47 am »
0

Updates: Watchtower is finally in, Followers is fixed to have its full effect, and AIs can now make their own hypothetical copies of the state to play with: "What happens if I draw three cards? I'll guess at what they are. Do they help?"
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #70 on: September 19, 2011, 04:01:15 am »
0

Updates from this weekend:

I optimized one of the most frequently-called functions, gainsToEndGame(), yielding a 2-4x speedup in simulation speed.

Royal Seal, Mint, and Masquerade are in.

The AI decision framework is reworked somewhat. Now an AI can have both an xPriority and an xValue for any decision 'x'; it will use the xValue if it runs off the priority list. This makes it possible, for example, to define discard preferences better: its first choice is to discard a pure Victory card. After that the value function kicks in, and it tries to discard a terminal action it won't get to play, or otherwise the card with the lowest base cost.

With this new framework, it's possible to define cards that make new kinds of decisions without adding so much plumbing to BasicAI.coffee. Asking for ai.choose('foo', state, choices) will go straight to the fooValue and fooPriority functions, without having to define two more functions as middlemen.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +869
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #71 on: September 24, 2011, 05:22:35 pm »
0

We're up to 100 cards! A great occasion to commemorate with my 100th post to the forum. Recent cards include Remodel, Expand, Remake, Upgrade, Mine, Herbalist, Lookout, Bureaucrat, Apothecary, Scout, and Library.

I notice that contributions from others have trailed off... If anyone wants help getting set up with GitHub or CoffeeScript, PM me.

As something that might help a number of people to contribute, I've just added a batch file for compiling the code on Windows without node.js! You won't be able to run the command-line version, but you should be able to edit the code and run the edited version in your browser. I haven't tested this process yet, though.
« Last Edit: September 24, 2011, 05:25:22 pm by rspeer »
Logged

michaeljb

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1361
  • Shuffle iT Username: michaeljb
  • Respect: +1953
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #72 on: September 25, 2011, 12:03:10 am »
0

This past week was really busy for me in school and as much as I wanted to spend time coding more Dominion cards, homework had to be the priority :o

Working on some cards right now though  :)

edit: Treasury and Cutpurse are done  ;)
« Last Edit: September 25, 2011, 02:32:59 am by michaeljb »
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1476
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #73 on: September 25, 2011, 05:42:20 am »
0

Finally got myself into all of this and did Counting House
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1476
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #74 on: September 25, 2011, 10:51:47 am »
0

One Coffeescript question:

The actionPriority is implemented by a function that returns an array, if I interpret
Code: [Select]
actionPriority: (state,my) -> [
...
]
correctly? On the other hand, when I follow what happens with the returnvalue of this function, it seems to be a single element...
Logged
Pages: 1 2 [3] 4 5 ... 13  All
 

Page created in 0.084 seconds with 22 queries.