66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
|
"""Assess a betting strategy.
|
||
|
|
||
|
Copyright 2018, Georgia Institute of Technology (Georgia Tech)
|
||
|
Atlanta, Georgia 30332
|
||
|
All Rights Reserved
|
||
|
|
||
|
Template code for CS 4646/7646
|
||
|
|
||
|
Georgia Tech asserts copyright ownership of this template and all derivative
|
||
|
works, including solutions to the projects assigned in this course. Students
|
||
|
and other users of this template code are advised not to share it with others
|
||
|
or to make it available on publicly viewable websites including repositories
|
||
|
such as github and gitlab. This copyright statement should not be removed
|
||
|
or edited.
|
||
|
|
||
|
We do grant permission to share solutions privately with non-students such
|
||
|
as potential employers. However, sharing with other current or future
|
||
|
students of CS 7646 is prohibited and subject to being investigated as a
|
||
|
GT honor code violation.
|
||
|
|
||
|
-----do not edit anything above this line---
|
||
|
|
||
|
Student Name: Tucker Balch (replace with your name)
|
||
|
GT User ID: tb34 (replace with your User ID)
|
||
|
GT ID: 900897987 (replace with your GT ID)
|
||
|
"""
|
||
|
|
||
|
import numpy as np
|
||
|
|
||
|
def author():
|
||
|
return 'tb34' # replace tb34 with your Georgia Tech username.
|
||
|
|
||
|
def gtid():
|
||
|
return 900897987 # replace with your GT ID number
|
||
|
|
||
|
def get_spin_result(win_prob):
|
||
|
result = False
|
||
|
if np.random.random() <= win_prob:
|
||
|
result = True
|
||
|
return result
|
||
|
|
||
|
def test_code():
|
||
|
win_prob = 18 / 38 # 18 black numbers out of 38 total numbers
|
||
|
np.random.seed(gtid()) # do this only once
|
||
|
|
||
|
episode_winnings = 0
|
||
|
winnings = [0]
|
||
|
while episode_winnings < 80:
|
||
|
won = False
|
||
|
bet_amount = 1
|
||
|
while not won:
|
||
|
won = get_spin_result(win_prob)
|
||
|
if won:
|
||
|
episode_winnings += bet_amount
|
||
|
else:
|
||
|
episode_winnings -= bet_amount
|
||
|
bet_amount *= 2
|
||
|
winnings.append(episode_winnings)
|
||
|
|
||
|
print(winnings)
|
||
|
|
||
|
# add your code here to implement the experiments
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
test_code()
|