@@ -23,6 +23,8 @@ def PolyominoBuilder(genotype,build_strategy='random'):
23
23
24
24
if build_strategy == 'dfs' or build_strategy == 'bfs' :
25
25
possible_grid_order = []
26
+ else :
27
+ build_strategy = 'random'
26
28
27
29
def placeTile (tType ,position ,orientation ):
28
30
POLYOMINO_GRID [position ]= (tType ,orientation )
@@ -45,19 +47,27 @@ def identifyValidNeighbour(position,centerType,centerOrientation,checkPosition,i
45
47
if bindingEdge != 0 and cycleList (tile ,cycNum )[oppositeBindingEdgeIndex ]== InteractionMatrix (bindingEdge ):
46
48
POSSIBLE_GRID [checkPosition ].append ((i ,cycNum ))
47
49
if build_strategy == 'dfs' or build_strategy == 'bfs' :
48
- possible_grid_order .append (checkPosition )
50
+ if checkPosition not in possible_grid_order :
51
+ possible_grid_order .append (checkPosition )
52
+ else :
53
+ if build_strategy == 'dfs' :
54
+ possible_grid_order .remove (checkPosition )
55
+ possible_grid_order .append (checkPosition )
56
+ else :
57
+ pass
49
58
50
59
placement = placeTile (0 ,(0 ,0 ),0 )
51
60
identifyValidNeighbours ((0 ,0 ))
52
61
yield placement ,copy (POSSIBLE_GRID )
53
62
while len (POSSIBLE_GRID )> 0 :
54
63
if build_strategy == 'random' :
55
64
newPolyominoPosition ,newPolyominoDetails = choice ([(position , tileDetail ) for position , tileDetails in POSSIBLE_GRID .iteritems () for tileDetail in tileDetails ])
56
- if build_strategy == 'dfs' :
65
+ elif build_strategy == 'dfs' :
57
66
newPolyominoPosition ,newPolyominoDetails = (possible_grid_order [- 1 ],POSSIBLE_GRID [possible_grid_order .pop ()][- 1 ])
58
- if build_strategy == 'bfs' :
67
+ elif build_strategy == 'bfs' :
59
68
newPolyominoPosition ,newPolyominoDetails = (possible_grid_order [0 ],POSSIBLE_GRID [possible_grid_order .pop (0 )][0 ])
60
69
70
+
61
71
POSSIBLE_GRID .pop (newPolyominoPosition )
62
72
placement = placeTile (newPolyominoDetails [0 ],newPolyominoPosition ,newPolyominoDetails [1 ])
63
73
identifyValidNeighbours (newPolyominoPosition )
0 commit comments