Skip to content

Commit 2d2f17f

Browse files
author
Zerline
committed
Debugging flipping dominos. Flipping programmatically, not yet interactively.
1 parent 9afe294 commit 2d2f17f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Diff for: examples/dominos/flipping_aztecdiamond.py

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def flip(self, other):
8282
self.second, other.first = other.first, self.second
8383
else:
8484
self.second, other.second = other.second, self.second
85+
self.compute()
86+
other.compute()
8587

8688

8789
class FlippingAztecDiamond(Graph):
@@ -127,6 +129,8 @@ def position_for_domino(d):
127129
@staticmethod
128130
def flip(d1, d2):
129131
"""d1 and d2 are dominos"""
132+
if d1==d2 or not d2 in d1.neighbors():
133+
return
130134
if d1 < d2:
131135
d1.flip(d2)
132136
else:

Diff for: examples/dominos/flipping_dominos.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ def set_cell(self, obj, pos, val=True, dirty={}):
2929
if not dirty[p]: # check this position is pressed
3030
continue
3131
d2 = obj.domino_for_position(p)
32-
if d2 == d1:
32+
if d2 == d1 or not d2 in d1.neighbors():
3333
continue
3434
if d2 in d1.neighbors():
3535
# Do the flip
3636
obj.flip(d1, d2)
37-
#obj.matching[d1.first] = d1
38-
#obj.matching[d2.first] = d2
3937
return obj
4038
return Exception("Please select a second domino!")
4139
else:
@@ -201,13 +199,25 @@ def is_pressed(self):
201199
"""Is the domino pressed?"""
202200
return self.value
203201

202+
def set_value(self, value):
203+
"""Set domino value
204+
As we have a directional link,
205+
the domino value will also be set.
206+
"""
207+
self.link.unlink()
208+
self.first.value = value
209+
self.second.value = value
210+
self.link = ddlink(((self.first, 'value'), (self.second, 'value')), (self, 'value'), logic='and', set_at_init=False) # Fresh ddlink
211+
204212
def reset(self):
205213
"""Full domino reset"""
206-
self.value = False
214+
self.set_value(False)
207215
self.link.unlink()
208216

209217
def flip(self, other):
210218
"""Flip self with some neighboring domino"""
219+
if other == self or other.geometry == self.geometry:
220+
return
211221
self.reset()
212222
other.reset()
213223
self.geometry.flip(other.geometry)
@@ -253,6 +263,7 @@ def update(self):
253263
self.apply_matching(self.value.matching)
254264
for k,d in self.dominos.items():
255265
d.compute(self.css_classes)
266+
d.set_value(False) # unpress buttons
256267

257268
def match(self, b1, b2):
258269
"""Match buttons b1 and b2, that is: create a domino"""

0 commit comments

Comments
 (0)