world.cells.each_with_index do |cell, index|
puts "#{index} out of #{world.cells.size}"
# Use this variable in the if branches for "Rule 1" to "Rule 4"
count = world.live_neighbours_around_cell(cell).count
live_cells
but to directly index the @cell_board
array. That way your whole algorithm runs in O(n) complexity and should be real-time.Gosu::Window
's needs_cursor?
method to return true, this will stop the cursor from being hidden. The default value (false) is only really good for (some) games and I regret it. =/
live_cells.each
call is the problem - also, the comment is wrong :) ): def live_neighbours_around_cell(cell)
live_neighbours = []
live_cells.each do |live_cell|
# Neighbour to the North
if live_cell.x == cell.x - 1 && live_cell.y == cell.y
live_neighbours << live_cell
end
...
def live_neighbours_around_cell(cell)
live_neighbours = []
# Neighbour to the North
if cell.y > 0
candidate = self.cell_board[cell.x, cell.y - 1]
live_neighbours << candidate if candidate.alive
end
...
Fixnum
s are easier on the garbage collector than Array
s.live_neighbours_around_cell
.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill