Exemple #1
0
# 1'.  (! X plays $a ∨ has_fork) ⇒ play $a

# play randomly:
q = net.add_production(Rule(Has('□', '$x')))
q.postcondition = Has("random_play", '$x')
q.truth = 0.4
p.append(q)

# [note to myself:
# Solved: The problem here is that the π1(x,1) proposition needs to
# be checked for x != y, but it has no "Has" representation.
# Now the problem is a "None" token passed down to the Join Node.
# Why is it None?]

f = open("rete.dot", "w+")
f.write(net.dump())
f.close()
os.system("dot -Tpng rete.dot -orete.png")
DEBUG("\nRete graph saved as rete.png\n")

# **** Background knowledge ****
net.add_wme(WME('diag', (0, 0)))
net.add_wme(WME('diag', (1, 1)))
net.add_wme(WME('diag', (2, 2)))
net.add_wme(WME('back_diag', (0, 2)))
net.add_wme(WME('back_diag', (1, 1)))
net.add_wme(WME('back_diag', (2, 0)))


def show_board(board):
    for i in [0, 3, 6]:
Exemple #2
0
c02 = Has('□', '$y', '$z')
c03 = Has('>', '$y', '$z')
p0 = rete_net.add_production(Rule(c01, c02, c03))

wmes = [
    WME('X', '0', '2'),
    WME('X', '1', '1'),
    WME('X', '2', '1'),
    WME('O', '0', '0'),
    WME('O', '1', '0'),
    WME('O', '1', '2'),
    WME('O', '2', '2'),
    WME('□', '0', '1'),
    WME('□', '2', '0'),
]
for wme in wmes:
    rete_net.add_wme(wme)

print("# of results = ", len(p0.items))
print("Results:")
for i in p0.items:
    print(i)

print("\n\x1b[32m——`—,—{\x1b[31;1m@\x1b[0m\n")  # Genifer logo ——`—,—{@

f = open("rete.dot", "w+")
f.write(rete_net.dump())
f.close()
os.system("dot -Tpng rete.dot -orete.png")
print("Rete graph saved as rete.png\n")