【農家は Replace() されました】迷路_02
概要
右手の法則を用いて迷路を探索するコード。
https://gyazo.com/0a06d4c912927b5bd1055c4466584dea
ソースコード
code:right_gold_harvest.python
clear()
size = 10
index = 0 # directions.len()
def next_index(i):
for o in offsets:
ni = (i + o) % directions.len()
if can_move(directionsni): return ni
while True:
plant(Entities.Bush)
substance = size * 2**(num_unlocked(Unlocks.Mazes) - 1)
use_item(Items.Weird_Substance, substance)
while get_entity_type() != Entities.Treasure:
index = next_index(index)
harvest()
clear()
コードの解説
いわゆる、右手の法則。
メインルーチン
迷路の基準サイズを10に設定
方向配列(北, 東, 南, 西)を定義
探査方向を初期化
探査優先順位(右, 前, 左, 後)を定義
無限ループ
迷路を生成
宝箱を見つけるまでループ
進行方向の決定
移動
宝箱を収穫
ワールドをクリア
進行方向の決定
現在の向きを基準に、探査優先順位に次の方向を判定
移動可能な方向を見つけた時点で、その方向インデックスを返す