Trying to apply procedural generation in my project, but I've got confused with dictionary. I'm certainly doing something wrong. I'm inserting currenttile which is a vector2 (as a key) and var blockcombination which is array of one or two numbers (as a value). Code is inside while loop and works as intended on first go, but something not right happens on the next goes and output shows that dictionary gets the key but value is assigned onto the first of the keys and rest of the values in keys changes into this weird array with ellipsis inside. I would really appreciate any input.
This is the code:
if (clear_tile == 0 or next_tile in empties) and one_after in unvisited and not block_combination.has(0):
Map.set_cellv(next_tile, 4)
print("chose empty")
if neighbours.size()> 1 and not block_combination.has(2):
block_combination.append(0)
blocks_c[current_tile] = block_combination
print("current_tile : ", current_tile)
print("block_combination : ", block_combination)
print("blocks_c current's tile value: ", blocks_c[current_tile])
print("all of blocks_c: ", blocks_c)
print("blocks_c's keys: ", blocks_c.keys())
print("blocks_c's values: ", blocks_c.values())
blocks_d[current_tile] = direction
current_tile = next_tile
next_tile = one_after
empties.append(current_tile)
else:
print("got to Ds")
if not block_combination.has(2):
var two_ways = cell_walls[direction]
var lucky_dip = randi() % 2
var d_a = direction_after[two_ways[lucky_dip+2]]
if next_tile + d_a in unvisited:
print("turn d1")
Map.set_cellv(next_tile, two_ways[lucky_dip])
if neighbours.size() > 1:
if not block_combination.has(1):
block_combination.append(1)
blocks_c[current_tile] = block_combination
blocks_d[current_tile] = direction
print("current_tile : ", current_tile)
print("block_combination : ", block_combination)
print("blocks_c current's tile value: ", blocks_c[current_tile])
print("all of blocks_c: ", blocks_c)
print("blocks_c's keys: ", blocks_c.keys())
print("blocks_c's values: ", blocks_c.values())
print("block d1 given")
current_tile = next_tile
next_tile = next_tile + d_a
direction = d_a
unvisited.erase(current_tile)
else:
if lucky_dip == 1:
lucky_dip = 0
else:
lucky_dip = 1
var d_a2 = direction_after[two_ways[lucky_dip+2]]
if next_tile + d_a2 in unvisited:
print("turn d2")
Map.set_cellv(next_tile, two_ways[lucky_dip])
if neighbours.size()> 1 and not block_combination.has(0):
block_combination.append(2)
blocks_c[current_tile] = block_combination
blocks_d[current_tile] = direction
print("current_tile : ", current_tile)
print("block_combination : ", block_combination)
print("blocks_c current's tile value: ", blocks_c[current_tile])
print("all of blocks_c: ", blocks_c)
print("blocks_c's keys: ", blocks_c.keys())
print("blocks_c's values: ", blocks_c.values())
print("block d2 given")
current_tile = next_tile
next_tile = next_tile + d_a2
direction = d_a2
unvisited.erase(current_tile)
And this is output:
got to clear
chose empty
currenttile : (6, 2)
blockcombination : [0]
blocksc current's tile value: [0]
all of blocksc: {(6, 2):[0]}
blocksc's keys: [(6, 2)]
blocksc's values: [[0]]
current tile is: (5, 2)
neighbours are: [(5, 1), (5, 3), (4, 2)]
next tile is:(4, 2)
got to clear
chose empty
currenttile : (5, 2)
blockcombination : [0]
blocksc current's tile value: [0]
all of blocksc: {(5, 2):[...], (6, 2):[0]}
blocksc's keys: [(6, 2), (5, 2)]
blocksc's values: [[0], [...]]
got to clear
got to Ds
turn d1
currenttile : (4, 2)
blockcombination : [1]
blocksc current's tile value: [1]
all of blocksc: {(4, 2):[...], (5, 2):[...], (6, 2):[1]}
blocksc's keys: [(6, 2), (5, 2), (4, 2)]
blocksc's values: [[1], [...], [...]]
block d1 given