424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
# File 'lib/cem/cruzzles.rb', line 424
def adja_index(x,y=nil)
if y == nil
if x.respond_to?(:x) && x.respond_to?(:y)
y = x.y
x = x.x
else
raise "Need Point2D with :x and :y or two parameters"
end
end
result = []
if x > 0
if y > 0
result << Point2D.new(x-1,y-1)
end
result << Point2D.new(x-1,y)
if y + 1 < @data.size - 1
result << Point2D.new(x-1, y+1)
end
end
if y > 0
result << Point2D.new(x,y-1)
end
if y + 1 < @data.size - 1
result << Point2D.new(x, y+1)
end
if x + 1 < @data[0].size - 1
if y > 0
result << Point2D.new(x+1,y-1)
end
result << Point2D.new(x+1,y)
if y + 1 < @data.size - 1
result << Point2D.new(x+1, y+1)
end
end
return result
end
|