octachrome / treason

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

Added randomness to AI's decision which influence to reveal. #11

Closed einsteinsfool closed 7 years ago

einsteinsfool commented 7 years ago

Before this commit, AI's first revealed influence tells us a lot about the second one. E.g. if it reveals a duke, we're 100% sure that the other card is duke. If it reveals an assassin, then the other card is either a duke or also an assassin. Etc.

Now, AI will still probably choose to reveal ambassador over duke but we're not 100% sure.

Feel free to modify rank probabilities as you please. All tests pass.

octachrome commented 7 years ago

This looks fine. I raised a couple of very minor points, but there's no need to fix them in this pull request.

einsteinsfool commented 7 years ago

I'll add spaces in the next PR, sorry. As for the nullifying, I thought it will allow garbage collector to dispose the array. But I don't normally write in JS, so I'm not sure. Just what I read on SO. Should I remove it in the next PR?

octachrome commented 7 years ago

I thought it will allow garbage collector to dispose the array

influenceProbablility is a local variable, so as soon as the function returns it will go out of scope and garbage collection can occur.

You only need to worry about nulling a reference when it is a global variable and will live for a long time.