Strategies run forever and buy nothing #59

Closed
jaredbeck opened this Issue Jan 7, 2012 · 9 comments

Projects

None yet

4 participants

@jaredbeck

First time trying this simulator, but no matter what strategies I choose, they run forever and don't seem to ever buy anything.

$ ./play.coffee strategies/SillyAI.coffee strategies/SillyAI.coffee 
strategies/SillyAI.coffee
strategies/SillyAI.coffee
(SillyAI shuffles.)
SillyAI draws 5 cards: [Estate, Estate, Estate, Copper, Copper].
(SillyAI shuffles.)
SillyAI draws 5 cards: [Copper, Copper, Estate, Copper, Copper].
Tableau: [Pawn, Workshop, Venture, Nomad Camp, Herbalist, Pirate Ship, Scout, Tactician, Peddler, Quarry]

== SillyAI's turn 1 ==
SillyAI plays Copper.
SillyAI plays Copper.
Coins: 2, Potions: 0, Buys: 1
SillyAI draws 5 cards: [Copper, Copper, Copper, Copper, Copper].

== SillyAI's turn 1 ==
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
Coins: 4, Potions: 0, Buys: 1
SillyAI draws 5 cards: [Copper, Copper, Copper, Estate, Estate].

== SillyAI's turn 2 ==
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
Coins: 5, Potions: 0, Buys: 1
(SillyAI shuffles.)
SillyAI draws 5 cards: [Estate, Copper, Copper, Copper, Copper].

== SillyAI's turn 2 ==
SillyAI plays Copper.
SillyAI plays Copper.
SillyAI plays Copper.
Coins: 3, Potions: 0, Buys: 1
(SillyAI shuffles.)
SillyAI draws 5 cards: [Copper, Copper, Estate, Copper, Copper].
@bilts

I suspect this is related to Issue 56. First, try running with something other than SillyAI, just in case it's that.

If that doesn't work, try downgrading your CoffeeScript version

npm uninstall -g coffee-script
npm install -g coffee-script@1.1.0

@rspeer
Owner

I'm assuming this is only in the command-line version, right? Your bug report made it sound like it's the Web version which had me alarmed.

But yeah, it sounds like the CoffeeScript 1.2 problem manifesting itself differently.

@jaredbeck

Thanks for the quick response, but unfortunately I am already using 1.1:

$ coffee --version
CoffeeScript version 1.1.0

Trying with something other than SillyAI, same issue:

$ ./play.coffee strategies/BigMoney.coffee strategies/ChapelWitch.coffee | head -n 40
strategies/BigMoney.coffee
strategies/ChapelWitch.coffee
(ChapelWitch shuffles.)
ChapelWitch draws 5 cards: [Estate, Estate, Copper, Estate, Copper].
(Big Money shuffles.)
Big Money draws 5 cards: [Estate, Copper, Estate, Copper, Copper].
Tableau: [Chapel, Witch, Talisman, Hunting Party, Bazaar, Jester, Pearl Diver, Philosopher's Stone, Cellar, Mint, Potion]

== ChapelWitch's turn 1 ==
ChapelWitch plays Copper.
ChapelWitch plays Copper.
Coins: 2, Potions: 0, Buys: 1
ChapelWitch draws 5 cards: [Copper, Copper, Copper, Copper, Copper].

== Big Money's turn 1 ==
Big Money plays Copper.
Big Money plays Copper.
Big Money plays Copper.
Coins: 3, Potions: 0, Buys: 1
Big Money draws 5 cards: [Copper, Estate, Copper, Copper, Copper].

== ChapelWitch's turn 2 ==
ChapelWitch plays Copper.
ChapelWitch plays Copper.
ChapelWitch plays Copper.
ChapelWitch plays Copper.
ChapelWitch plays Copper.
Coins: 5, Potions: 0, Buys: 1
(ChapelWitch shuffles.)
ChapelWitch draws 5 cards: [Copper, Estate, Estate, Copper, Copper].

== Big Money's turn 2 ==
Big Money plays Copper.
Big Money plays Copper.
Big Money plays Copper.
Big Money plays Copper.
Coins: 4, Potions: 0, Buys: 1
(Big Money shuffles.)
Big Money draws 5 cards: [Copper, Copper, Copper, Copper, Copper].
@bilts

Interesting. I saw this exact problem with CoffeeScript 1.2, after fixing the exceptions being thrown, but downgrading my CoffeeScript version resolved it. Clearly something else must have been going on.

@Narmical

This issue is caused by a bug in coffee script i think. I fixed it in a very kludgey way. The issue is that the formulation of the priority function ends up returning a one element array containing the priority array. The issue is coffee script is inserting an extra '[' and ']' around the output. I added some regex to strip those out. Its not a 'good' solution but it works

@bilts

I'd like to investigate the problem and come up with a less kludgey fix.

Narmical, could you point me to the commit/file where you fixed it? Also, any details you have on how to reproduce it would be helpful. Thanks!

@Narmical

You can check out what i did here https://github.com/Narmical/dominiate/blob/master/bigEvo.coffee#L44 lines 44 - 61 in the loadStrategey function.

To reproduce the error, in the loadStrategey method in play.coffee, print out the compiled JS to the screen. compare this to the output of coffee -c on the same file, you will see that they are different.

If you need more detail let me know, ill write up something better this weekend

@bilts

I fixed this in Pull Request #69.

It turns out the CoffeeScript compiler sometimes relies on the output of Array::toString, which Dominiate overrides. Normally toString produces a comma-separated list of array elements. We wrap it in square brackets. Hence, the CoffeeScript output sometimes has an extra set of square brackets.

I updated things so that the Dominiate code still sees the overridden Array::toString, but code that's not in the game state or called by the game state sees the original function.

@Narmical
@rspeer rspeer pushed a commit that closed this issue Jan 26, 2012
@bilts bilts Prevent Array.prototype.toString from interfering with other modules
The CoffeeScript compiler depends on the output from Array::toString
being formatted in a specific way.  Our changes, which wrapped the
output in square brackets, were causing the CoffeeScript compiler to
double-wrap some arrays (particularly the ones returned by player
strategies).

This commit makes it so that the change to Array::toString is applied
when the program enters Dominiate's top-level API methods and is
reverted when program control leaves those methods.

Fixes #56
Fixes #59
5023ded
@rspeer rspeer closed this in 5023ded Jan 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment