egonSchiele / dominion

A Dominion simulator in Haskell
Other
111 stars 11 forks source link

Make it easy to test simple interactions? #5

Open amalloy opened 10 years ago

amalloy commented 10 years ago

I don't really know how to run any of this code right now "in isolation" - things seem geared towards playing entire games with a specified strategy. But there are a number of effects that I think have issues, and I'd like a way to write a test like "Here is a player's hand. After he does XYZ, his hand should change as follows, and the supply/trash should change as follows." This would help me verify my understanding of how things are put together, so that I can properly direct my efforts at improving them.

One example is that I think you're discarding cards immediately after playing them, rather than putting them into the play area and then discarding post-turn, which would be quite bad. Additionally, some trash/discard effects are not judicious enough, and can affect other cards in hand unintentionally. I'd like to test a player holding Throne Room and three Feast cards, and throning one of them. It should be the case that the played Feast is trashed while the other two stay in hand, and the player gains two cards. But I suspect that instead two Feasts will be trashed and one will be discarded.

ajwheeler commented 10 years ago

I think a good strategy might be to start writing HSpec tests, ensuring that functions to state them concisely are available. This is good because (1) testing is good and (2) writing a lot of code to use the library will help to asses where its design could be better.

egonSchiele commented 10 years ago

What about this?

withHand lets you play one round with a hand of your choice. Then you return a boolean value indicating whether the test passed or failed. You can examine the player / the state etc, so it gives some flexibility.

I added a silly usage example with market.

amalloy commented 10 years ago

Thanks, that's great. It will probably be important to be able to also specify the kingdom cards, so that it's possible to test things like "play Workshop, gaining Feast, then Village drawing Feast, then play Feast".

egonSchiele commented 10 years ago

Implemented in 534f26cca3bff32cdc427e776abf22908b8b5579. You can pass options in to withHand now, so you can specify the cards on the table with something like:

withHand [workshop, village, estate, estate, copper] [Card [feast]].

You also have the full game state, so you could modify the user's deck to place a feast on top for when you play village?