summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrom <romangraef@gmail.com>2021-04-26 20:55:19 +0200
committerrom <romangraef@gmail.com>2021-04-26 20:55:19 +0200
commit9bd876beab4c131a57bcffc066c2e0bd1e8c0907 (patch)
treed6c9f1f8b2809a93a620503d327ca49972621b4f
parent0b49ed720d9cee1cae9ce26a8685992a187078d0 (diff)
downloadldjam48-9bd876beab4c131a57bcffc066c2e0bd1e8c0907.tar.gz
ldjam48-9bd876beab4c131a57bcffc066c2e0bd1e8c0907.tar.bz2
ldjam48-9bd876beab4c131a57bcffc066c2e0bd1e8c0907.zip
shuffling
-rw-r--r--scenes/levels/puzzle/puzzle.gd25
1 files changed, 21 insertions, 4 deletions
diff --git a/scenes/levels/puzzle/puzzle.gd b/scenes/levels/puzzle/puzzle.gd
index 219907f..ffebcab 100644
--- a/scenes/levels/puzzle/puzzle.gd
+++ b/scenes/levels/puzzle/puzzle.gd
@@ -10,7 +10,6 @@ var parts = []
onready var order = range(dim*dim)
func _ready():
- order.shuffle()
for i in range(dim*dim-1):
var button = _button_comp.instance()
var label = Label.new()
@@ -25,6 +24,7 @@ func _ready():
button.connect("on_click", self, "on_anybutton_click", [i+1])
parts.append(button)
$Pieces.add_child(button)
+ _initial_shuffle(100)
_render_state()
func _position_from_index(idx):
@@ -33,6 +33,8 @@ func _position_from_index(idx):
func on_anybutton_click(piece_name):
var pos = _button_position(piece_name)
_do_push(pos, _hole_position())
+ _render_state()
+ _check_state()
func _render_state():
for i in range(dim*dim):
@@ -78,6 +80,21 @@ func _do_push(from, to):
order[i] = order[next_pos]
i = next_pos
order[from] = 0
- _render_state()
- _check_state()
-
+
+func _initial_shuffle(it):
+ var hp = _hole_position()
+ for i in range(it):
+ var dir
+ var p = _position_from_index(hp)
+ if randi() % 2 ==0:
+ var m = range(p.x+1, dim)
+ m.append_array(range(p.x))
+ m.shuffle()
+ dir = m[0] - p.x
+ else:
+ var m = range(p.y+1, dim)
+ m.append_array(range(p.y))
+ m.shuffle()
+ dir = (m[0]-p.y)* dim
+ _do_push(int(hp + dir), hp)
+ hp = int(hp+dir)