-
Notifications
You must be signed in to change notification settings - Fork 1
/
x7.py
131 lines (116 loc) · 3.38 KB
/
x7.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'''
Simplest
=> do_something()
'''
def actions(self, _g, _thisid):
_result = []
_result.append(do_something())
return _result
'''
Builder
=> build ConsumeOperands(1, 2, 3)
'''
def actions(self, _g, _thisid):
_result = []
_result.append(do_something())
return _result
'''
Scout4
see t1 := NodeOfClass(Target)
=> add_tag(Found, t1)
else t2 := NodeOfClass(Found)
=> add_tag(Done, t2)
else t3 := NodeOfClass(SomethingElse)
=> do_something(Found, t2, t3)
'''
def actions(self, _g, _thisid):
_result = []
t1 = NodeOfClass(Target).see_one()
if t1 is not None:
_result.append(add_tag(Found, t1))
else:
t2 = NodeOfClass(Found)
if t2 is not None:
result.append(add_tag(Done, t2))
else:
t3 = NodeOfClass(SomethingElse)
if t3 is not None:
result.append(do_something(Found, t2, t3))
return _result
'''
OperandsScout(target)
see p1 := NodeWithTag(Number, Avail)
p2 := NodeWithTag(Number, Avail)
op := NodeWithTag(Operator, Allowed)
=> build ConsumeOperands(consume_operands=[p1, p2], proposed_operator=op)
'''
def actions(self, _g, _thisid):
_result = []
p1 = p2 = op = None
_found_tup = CartesianProduct(
NodeWithTag(Number, Avail),
NodeWithTag(Number, Avail),
NodeWithTag(Operator, Allowed),
whole_tuple_criterion=TupAnd(
no_dups,
NotAlreadyBuilt(ConsumeOperands)
)
).see_one(_g)
if _found_tup:
p1, p2, op = _found_tup
if _found_tup:
_result.append(Build2.maybe_make(ConsumeOperands, _g, kwargs={'consume_operands': [p1, p2], 'proposed_operator': op}))
return _result
'''
tags -- taggees
Brick, Block : Number(n)
OperandsScout(behalf_of, target)
see p1 := NodeWithTag(Number, Avail),
p2 := NodeWithTag(Number, Avail),
op := NodeWithTag(Operator, Allowed)
=> build ConsumeOperands(op, p1, p2)
else block := NodeWithTag(Block, Avail), block != target
=> Fail(block)
'''
def actions(self, _g, _thisid):
_result = []
p1 = p2 = op = None
_found_tup = CartesianProduct(
NodeWithTag(Number, Avail),
NodeWithTag(Number, Avail),
NodeWithTag(Operator, Allowed),
whole_tuple_criterion=TupAnd(
no_dups,
NotAlreadyBuilt(ConsumeOperands)
)
).see_one(_g)
if _found_tup:
p1, p2, op = _found_tup
if _found_tup:
_result.append(Build2.maybe_make(ConsumeOperands, _g, kwargs={'consume_operands': [p1, p2], 'proposed_operator': op}))
else:
block = NodeWithTag(Block, Avail).see_one(_g)
if block is not None and block != _g.neighbor(_thisid, 'target'):
_result.append(Fail(block))
return _result
_found_tup = CartesianProduct(
NodeOfClass((Brick, Block)),
whole_tuple_criterion=TupAnd(
no_dups,
NotAlreadyBuilt(CouldBeOperand, ('_args', 0))
).see_one(_g)
_found_tup = CartesianProduct(
NodeOfClass((Brick, Block)),
whole_tuple_criterion=TupAnd(
no_dups,
NotAlreadyBuilt(CouldBeOperand, [('_args', 0), ('whatever', _Literal('abc'))]).see_one(_g)
target = _g.neighbor(_thisid, 'target')
def _f2(_g, _tup):
block, = _tup
return block != target
_found_tup_2 = CartesianProduct(
NodeWithTag(Block, Avail),
whole_tuple_criterion=TupAnd(
no_dups,
TupFunc(_f2)
)).see_one(_g)