-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdraw_tree.py
74 lines (60 loc) · 2.04 KB
/
draw_tree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from argparse import Action
import math
import os
import sqlite3
from pyvis.network import Network
import networkx as nx
conn = sqlite3.connect(os.getcwd() +'/cardData.cdb')
c = conn.cursor()
c.execute('SELECT Count(Visited) FROM MCST WHERE CardId != \"Result\" and Visited > 0')
total = c.fetchone()[0]
print("Total search made=" + str(total))
nx_graph = nx.DiGraph()
const = 0.5
c.execute('SELECT rowid, * FROM MCST')
records = c.fetchall()
group_count = 0
for record in records:
rowid = record[0]
name = record[1]
parentid = record[2]
childid = record[3]
cardid = record[4]
action = record[5]
avgturn = record[6]
reward = record[7]
visited = max(0.0001, record[8])
isFirst = record[9]
isTraining = record[10]
if visited < 1:
continue
activation = reward + const * math.sqrt((math.log(total + 1) + 1) / visited)
activation = min(activation, 25)
nx_graph.add_node(rowid, label=f'{rowid} {isFirst} {isTraining} {action} {cardid}', group=1)
if parentid != -4:
nx_graph.add_edge(parentid, rowid, weight=activation, group=2)
if childid != -4:
nx_graph.add_edge(rowid, childid, weight=activation, group=3)
if (action == "GoToEndPhase"):
group_count += 1
# Get Best average moves?
# c.execute("Select cardId,Action, SUM(Reward) as r,SUM(Visited) as v from MCST WHERE IsTraining='False' group by cardid, action order by cardid, action")
# records = c.fetchall()
# for record in records:
# cardid = record[0]
# action = record[1]
# reward = record[2]
# visited =record[3]
# #const = 0
# activation = 0
# activation2 = 0
# if (visited > 0):
# actication = round((reward + const * math.sqrt((math.log(total + 1) + 1) / (visited))) * 100)/100
# activation2 = round(reward / (visited) * 1000)/10
# print(f"{activation}| {activation2} | {cardid} | {action}")
c.close()
nt = Network('1000px', '1000px', directed=True)
# populates the nodes and edges data structures
nt.from_nx(nx_graph)
nt.show_buttons(filter_=['physics'])
nt.show('nx.html')