Dominion Strategy Forum

Please login or register.

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

Author Topic: A Dominion Simulator in Haskell  (Read 5279 times)

0 Members and 1 Guest are viewing this topic.

egonschiele

  • Pawn
  • **
  • Offline Offline
  • Posts: 2
  • Respect: +3
    • View Profile
A Dominion Simulator in Haskell
« on: January 22, 2014, 02:31:21 am »
+2

Hi there,
I'm new to this forum. I recently got into Dominion strategy after getting trashed by "big money". I decided to write my own simulator for fun, and here is a quick demo! https://vimeo.com/84722179

Right now it supports all the cards from the original version. It is implemented as a DSL in Haskell, so you can write absolutely any kind of logic you want. It seems like a lot of simulators use a "non-programmer friendly" approach, so I went in the opposite direction...if you are a programmer this gives you a lot of power in an easy-to-use DSL.

I'm hoping to add more cards from the expansions soon. Hopefully this is relevant to somebody's interests :)
Logged

qmech

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1918
  • Shuffle iT Username: qmech
  • What year is it?
  • Respect: +2320
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #1 on: January 22, 2014, 03:35:21 am »
0

Haskell and Dominion?  This is simply too exciting.

I'll definitely be looking at this when I've got time to do it justice.

(It might just be me, but the video was a bit glitchy, and I had to click around a bit at the start to get the images to update; the sound was fine.)
Logged

flies

  • Minion
  • *****
  • Offline Offline
  • Posts: 629
  • Shuffle iT Username: flies
  • Statistical mechanics of hard rods on a 1D lattice
  • Respect: +348
    • View Profile
    • ask the atheists
Re: A Dominion Simulator in Haskell
« Reply #2 on: January 22, 2014, 11:54:42 am »
0


I <3 schiele
Logged
Gotta be efficient when most of your hand coordination is spent trying to apply mascara to your beard.
flies Dominionates on youtube

florrat

  • Minion
  • *****
  • Offline Offline
  • Posts: 542
  • Shuffle iT Username: florrat
  • Respect: +748
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #3 on: January 27, 2014, 11:33:37 pm »
0

It seems like a lot of simulators use a "non-programmer friendly" approach, so I went in the opposite direction...
You have seen Dominiate, right? That is pretty non-programmer unfriendly to me, IMO.

But nice job making another simulator!
Logged

qmech

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1918
  • Shuffle iT Username: qmech
  • What year is it?
  • Respect: +2320
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #4 on: January 28, 2014, 03:38:02 am »
+1

The great thing about Haskell is that you get source code that looks like this:

Code: [Select]
throneRoom = Card "Throne Room" 4 [Action] [PlayActionCard 2]
village = Card "Village" 3 [Action] [PlusCard 1, PlusAction 2]
witch = Card "Witch" 5 [Action, Attack] [PlusCard 2, OthersGainCurse 1]
woodcutter = Card "Woodcutter" 3 [Action] [PlusCoin 2, PlusBuy 1]

The scary thing about Haskell is that sooner or later you run up against a monad.

Code: [Select]
run :: T.GameState -> [T.Strategy] -> IO T.Result
run state strategies = do
              (_, newState) <- runStateT (game strategies) state
              let cards = newState ^. T.cards
              if gameOver cards
                then returnResults newState
                else run (over T.round (+1) newState) strategies
Logged

egonschiele

  • Pawn
  • **
  • Offline Offline
  • Posts: 2
  • Respect: +3
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #5 on: January 28, 2014, 05:11:14 pm »
+1

Yup! This package uses the State monad to keep track of the game state. If you're interested, I had written a visual guide to monads a while back: http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Logged

amalloy

  • Witch
  • *****
  • Offline Offline
  • Posts: 453
  • Respect: +620
    • View Profile
    • Twitch stream
Re: A Dominion Simulator in Haskell
« Reply #6 on: January 30, 2014, 01:09:09 am »
+1

I want to look at the code, but not watch anything on vimeo. Perhaps a link to the source here would be a good idea?
Logged

qmech

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1918
  • Shuffle iT Username: qmech
  • What year is it?
  • Respect: +2320
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #7 on: January 30, 2014, 04:21:39 am »
0

Hackage and GitHub.

Trivia: isotropic is still my browser's first suggestion for "dominion".
Logged

amalloy

  • Witch
  • *****
  • Offline Offline
  • Posts: 453
  • Respect: +620
    • View Profile
    • Twitch stream
Re: A Dominion Simulator in Haskell
« Reply #8 on: February 01, 2014, 06:06:47 pm »
+1

Reading over this, it looks like the support for a number of the cards is not really right. For example, with Cellar you have to discard all N cards at once, and then draw N replacements, rather than doing a discard/draw pair N times. That one's easy enough for me to fix, and I'll probably send over a pull request soonish. But some of them run into more fundamental problems, mostly that of an opponent making a choice mid-turn: eg, Militia's current "you must discard the cheapest cards" behavior is obviously wrong. Bureaucrat is more subtly wrong, because there are very few scenarios in base where it matters which card you put back, so not offering a choice isn't so bad; but for example I might have a Remodel in hand, and need to keep the Province to end the game next turn, rather than keeping my useless Estate.

It looks like you forgot to finish Moat: apparently at the moment it only works against Bureaucrat, and no other attacks. There's the same problem of mid-turn choices, of course: mostly I'm happy to block an attack, but maybe I want to accept the Curse from Witch so as to empty the third pile sooner, or let you Thief away one of my Coppers.

I briefly tried to write my own Dominion engine in Haskell, but I still only really dabble in Haskell, and I gave up when I couldn't figure out how to model the many choices that have to be made, especially with reaction cards. I like your "followup" model, and it handles a lot of the issues, but there are still a lot of things left that I don't know how to handle and it looks like you haven't planned for (cards in other expansions, mostly).
Logged

skinpenthar

  • Pawn
  • **
  • Offline Offline
  • Posts: 1
  • Respect: 0
    • View Profile
Re: A Dominion Simulator in Haskell
« Reply #9 on: February 26, 2015, 11:28:39 pm »
0

You have seen Dominiate, right? That is pretty non-programmer unfriendly to me, IMO.???
Logged
We provide guarantee to pass Testking oracle certification with online exam Testking cpa course itil and northwestern you can also get best quality Jacksonville University for your guaranteed success.
Pages: [1]
 

Page created in 1.034 seconds with 21 queries.