Hacker News new | ask | show | jobs
by carb 4941 days ago
So it's more of a 10x10 room than a 10x10 maze?
1 comments

adding barriers to make a room into a maze is trivial. So if you were forking my scala code, you see 4 filters -

      val res = Seq(x-1,x,x+1).map( a => Seq(y-1,y,y+1).map( b=> (a,b))).flatten
      .filterNot( ab => ab._1 == x && ab._2 == y)  // don't include me
      .filterNot( ab=> ab._1 < leftTop._1 || ab._1 > rightBottom._1) // don't include points outside the maze
      .filterNot( ab=> ab._2 < leftTop._2 || ab._2 > rightBottom._2)
      .filterNot( ab=> path.contains(ab)) // don't revisit points along your path

Now if you add 1 more filter, literally 1 more line of code, to eliminate paths that are prohibited because they intersect with a barrier, you are good to go. a room is simply a maze with zero barriers.