carykh / PrisonersDilemmaTournament

Watch This Place's awesome video about iterated Prisoner's Dilemma for context! https://www.youtube.com/watch?v=BOvAbjfJ0x0
MIT License
205 stars 160 forks source link

Minimum length of game is 50 or 200? #3

Closed cai-lw closed 3 years ago

cai-lw commented 3 years ago

The code contradicts with the comment

https://github.com/carykh/PrisonersDilemmaTournament/blob/2a4b657365618bb443127157622ca81350c97805/code/prisonersDilemma.py#L44

BTW, a nit: random.random() can return 0 (although very unlikely) and crash the program. Consider using 1 - random.random() as that will never be zero (See https://docs.python.org/3/library/random.html#random.random)

In [9]: int(200-40*np.log(0))
C:\Users\cai_l\Anaconda3\Scripts\ipython3:1: RuntimeWarning: divide by zero encountered in log
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-9-abafa11aae74> in <module>
----> 1 int(200-40*np.log(0))

OverflowError: cannot convert float infinity to integer
nobody5050 commented 3 years ago
  1. See #11
carykh commented 3 years ago

Thanks for pointing this out, cai-lw! I fixed the comment to reflect what the line of code says (lengthening it from 50 to 200 was a last-minute change I made, oops) And I went with the 1-random.random() approach. cool cool