def test_state_index_number_2_5(self):
     """
     Basic Test - test for anger
     """
     root_state = State(ACTORS, PLACES, ITEMS)
     root_state.actors["CHARLIE"]["kill_desire"]["DAPHNE"] = 1
     assert state_index_number_2(root_state) == 0b10000001000
 def test_state_index_number_2_4(self):
     """
     Basic Test - test for death
     """
     root_state = State(ACTORS, PLACES, ITEMS)
     root_state.actors["CHARLIE"]["health"] = 0
     assert state_index_number_2(root_state) == 0b01100000000
 def test_state_index_number_2_3(self):
     """
     Basic Test - test for same place
     """
     root_state = State(ACTORS, PLACES, ITEMS)
     root_state.actors["CHARLIE"]["place"] = PLACES["DAPHNES_HOUSE"]
     assert state_index_number_2(root_state) == 0b10001000000
 def test_state_index_number_2_2(self):
     """
     Basic Test - test for items
     """
     root_state = State(ACTORS, PLACES, ITEMS)
     root_state.actors["ALICE"]["items"].append(ITEMS["GUN"])
     assert state_index_number_2(root_state) == 0b10000000001
Beispiel #5
0
def q_value_for_node(node, table2):
    state_index_num = state_index_number_2(node.state)
    if state_index_num not in table2:
        return 0.1
    ans = table2[state_index_num][0]
    for _, val in enumerate(table2[state_index_num]):
        if val > ans:
            ans = val
    return ans
def run_reinforce(depth = 15):
    with open("table2.pickle","rb") as table2file:
        table2 = pickle.load(table2file)
    root_state = State(ACTORS, PLACES, ITEMS)
    root_node = TreeNode(root_state, parent_edge = None, possible_methods = True)
    current_node = root_node
    
    for _ in range(depth):
        qvals = deepcopy(table2[state_index_number_2(current_node.state)])
        pidx = prob_index(softmax(qvals))
        edge = expand_index_edge(current_node, pidx)
        while edge.method.believability == 0:
            qvals.pop(pidx)
            pidx = prob_index(softmax(qvals))
            edge = expand_index_edge(current_node, pidx)
        current_node = edge.next_node
            
    return Story(current_node)
def table2_test(): 
    with open("table2.pickle", "rb") as table2file:
        table2 = pickle.load(table2file)
    root_state = State(ACTORS, PLACES, ITEMS)
    print(table2[state_index_number_2(root_state)])
 def test_state_index_number_2_1(self):
     """
     Basic Test
     """
     root_state = State(ACTORS, PLACES, ITEMS)
     assert state_index_number_2(root_state) == 0b10000000000