July 2015
Intermediate to advanced
286 pages
6h 31m
English
The Sidewinder algorithm (from The Sidewinder Algorithm) is similar in many respects to the Binary Tree algorithm. You’ll recall that it has similar biases, and even a (conceptually) similar approach, randomly choosing at each step to either carve east from the current cell, or north from the current run of cells. In practice, though, Sidewinder feels like a very different beast.
In code, it looks something like this. Put the following in a file named sidewinder.rb.
| sidewinder.rb | |
| Line 1 | class Sidewinder |
| - | |
| - | def self.on(grid) |
| - | grid.each_row do |row| |
| 5 | run = [] |
| - | |
| - | row.each do |cell| |
| - | run << cell |
| - | |
| 10 | at_eastern_boundary = (cell.east == nil) |
| - | at_northern_boundary = (cell.north == nil) ... |
Read now
Unlock full access