octachrome / treason

A clone of the card game Coup written in Node.js
Other
138 stars 79 forks source link

AI will choose player by random if there are players with the same amount of influences and money #8

Closed einsteinsfool closed 7 years ago

einsteinsfool commented 7 years ago

Sometimes I can make a decision based on knowing that AI will assasinate or coup the first player from the list if there is more than 1 player with most incluences and cash. I think I shouldn't be able to do that and that AIs should be less predictable. For more explanation check out comments in sort function.

After pulling this, a npm install is needed as I added a new module "md5" for calculating hash functions.

octachrome commented 7 years ago

Have you run the unit tests to make sure they still pass?

npm test
einsteinsfool commented 7 years ago

No, I didn't run the tests. I'll comment after I run them.

I think you can't just return -1 or 1 by random, because the function must be deterministic and return the same value every time for every input. And random numbers are based on time which changes. Read the last bullet point here.

einsteinsfool commented 7 years ago

All tests pass. I'll run them before every PR from now, thanks.

octachrome commented 7 years ago

You could generate a random number before calling sort, and append it to each player name before hashing (instead of the node modules). That way the tie will be broken differently every time the function is called.

einsteinsfool commented 7 years ago

Right. :D Good, idea. Fixed and tested both with npm and myself (once I was stolen from and once AI was stolen from).

octachrome commented 7 years ago

Thanks again for another pr!