Exemplo n.º 1
0
def cust():
    global F
    tp = read_data.get_data(CURR, custom=True)
    gd = tp['game_data']
    cd = tp['content_data']
    number = int(request.form['number'])
    data = play_game.play(number, CURR, custom=True)
    print(data)
    if number == 6  :
        F = O
    if "options" not in data:
        F = O
        return data
    ops = data['options']
    tdct = {}
    counter = ['y','n']
    for i in ops:
        tdct[counter[0]] = {
            'val': cd[i],
            'next': ops[i]['next'],
            'more':cd[ops[i]['more']]
        }
        del counter[0]
    res = {
        'question':cd[data['question']],
        'fact':F,
        'chap':cd[data['chapter']],
        'options':tdct
    }
    F = cd[data['fact']]
    print(res)
   # ans = {"question":"Second"}
    return res
Exemplo n.º 2
0
def my_view_func(name):
    global CURR
    CURR = name 
    tp = read_data.get_data(name, custom=True)
    gd = tp['game_data']
    cd = tp['content_data']
    res = play_game.play(1, name, custom=True)
    ops = res['options']
    tdct = {}
    counter = ['y','n']
    for i in ops:
        tdct[counter[0]] = {
            'val': cd[i],
            'next': ops[i]['next'],
            'more':cd[ops[i]['more']]
        }
        del counter[0]
    global F,O
    F,O = [cd[res['fact']]]*2
    res = {
        'question':cd[res['question']],
        'fact':None,
        'chap':cd[res['chapter']],
        'options':tdct
    }
    print(res)
   # ans = {"question":"Second"}
    res['name'] = name
    return render_template('play_custom.html', val=res)
Exemplo n.º 3
0
def act():
    global CURR
    CURR = None
    global FACT
    tp = read_data.get_data('ww1_f')
    gd = tp['game_data']
    cd = tp['content_data']
    number = int(request.form['number'])
    data = play_game.play(number, 'ww1_f')
    # print(data)
    if number == 6  :
        FACT = OG
    if "options" not in data:
        FACT = OG
        print(data)
        return data
    ops = data['options']
    tdct = {}
    counter = ['y','n']
    for i in ops:
        tdct[counter[0]] = {
            'val': cd[i],
            'next': ops[i]['next'],
            'more':cd[ops[i]['more']]
        }
        del counter[0]
    res = {
        'question':cd[data['question']],
        'fact':FACT,
        'chap':cd[data['chapter']],
        'options':tdct
    }
    FACT = cd[data['fact']]
    # print(res)
   # ans = {"question":"Second"}
    return res
Exemplo n.º 4
0
from get_quotes import get_quotes
from play_game import play


while True:
    play(get_quotes())
    while True:
        replay = input("Do you want to play again? (y/n): ")
        if replay in ("Y", "y", "N", "n"):
            break
    if replay in ("N", "n"):
        break
Exemplo n.º 5
0
 def test_case_sample1_shoul_be_1001(self):
     stack = [999, 1, 1, 1, 0]
     expected = 1001
     result = play_game.play(stack)
     self.assertEqual(expected, result)
Exemplo n.º 6
0
 def test_case1_shoul_be_1999(self):
     stack = [0, 1, 1, 1, 999, 1, 1, 1, 1000]
     expected = 1999
     result = play_game.play(stack)
     self.assertEqual(expected, result)
Exemplo n.º 7
0
 def test_case_sample2_shoul_be_999(self):
     stack = [0, 1, 1, 1, 999]
     expected = 999
     result = play_game.play(stack)
     self.assertEqual(expected, result)
Exemplo n.º 8
0
                the door in step 3).
                The result are depicted on figures below (.ipynb).
                
             Result:
                 The best strategy is to change...


"""
import matplotlib.pyplot as plt
from play_game import *
import play_game


# play nb_parts games by calling the play function of play_game module
nb_parts = 100
res_CHANGE = play_game.play(Strategy.CHANGE, nb_parts)
res_KEEP = play_game.play(Strategy.KEEP, nb_parts)

plt.bar([1,2], (sum(res_CHANGE), sum(res_KEEP)), tick_label=["Change","Keep"])
plt.show()

gains_change = []
gains_keep = []
samples =  [1000, 10000, 20000, 50000, 80000, 100000]
for tours in samples:
    gains_change.append(play_game.play(Strategy.CHANGE, tours))
    gains_keep.append(play_game.play(Strategy.KEEP, tours))
    
figure = plt.figure()
plot = plt.scatter(samples, [sum(x) for x in gains_change])
plot = plt.scatter(samples, [sum(x) for x in gains_keep])