DFS アルゴリズムの擬似コードは次のとおりです http://www.mazeworks.com/mazegen/mazetut/index.htm
セル位置のリストを保持する CellStack (LIFO) を作成します
TotalCells = グリッド内のセルの数を設定し
ます ランダムにセルを選択し、CurrentCell と呼びます
VisitedCells = 1 を設定 します
while VisitedCells < TotalCells 1つ以上が見つかった場合、すべての壁が無傷のCurrentCellのすべての隣人を見つけるランダムに1つを選択して、それと
CurrentCellの間の壁をノックダウンする
CellStackのCurrentCellの位置をプッシュ
する 新しいセルCurrentCell
がVisitedCellsに1を加える
そうしないと
CellStack から最新のセル エントリをポップし、
CurrentCell にします。
endIf endWhile
私のsmalltalkコード
Maze>>initialize
|sampleCell width height n sample |
super initialize.
self borderWidth: 0.
sampleCell := VisibleSquare new.
width := sampleCell width.
height := sampleCell height.
self bounds: (5@5 extent: ((width + n) @ (height + n)) + (2 * self borderWidth)).
visitedcell :=0.
cells := Matrix rows: 8 columns: 7 tabulate: [:i :j | self newCellAt: i at:j].
その他の方法はこちら。
Maze>>newCellAt:i at:j
|c|
celltotal:= 8*7.
[(visitedcell< celltotal)] whileTrue:
["Im stuck with selecting cells next to current cell to make it as
Invisible square"
"else do this"
c := VisibleSquare new.
origin := self innerBounds origin.
self addMorphBack: c.
c position: ((i - 1) * c width) @ ((j - 1) * c height) + origin.
^ c
私は 2 つのクラスを持っています。