我在这里遵循此指南:http://www.mazeworks.com/mazegen/mazetut/index.htm

或更具体地


create a CellStack (LIFO) to hold a list of cell locations
set TotalCells = number of cells in grid
choose a cell at random and call it CurrentCell
set VisitedCells = 1

while VisitedCells < TotalCells

find all neighbors of CurrentCell with all walls intact
if one or more found
    choose one at random
    knock down the wall between it and CurrentCell
    push CurrentCell location on the CellStack
    make the new cell CurrentCell
    add 1 to VisitedCells else
    pop the most recent cell entry off the CellStack
    make it CurrentCell endIf

endWhile



我用java写这个,我的问题是。

我应该如何存储访问的单元格,以便可以按放置它们时的相反顺序访问它们。

像这样?

List<Location> visitedCells = new ArrayList<Location>();

Then do I grab with visitedCells.get(visitedCells.size()-1)?


位置存储x,y和z。
我没想问你什么。

最佳答案

您可以为此使用Stack

Stack<Location> visitedCells = new Stack<Location>();
visitedCells.push(myLocation1);
visitedCells.push(myLocation2);

// Get last one in but DONT remove
Location location2 = visitedCells.peek();

// Get last one in and remove
location2 = visitedCells.pop();

09-27 23:00