Anonymous user
Sokoban: Difference between revisions
→{{header|Ruby}}: refactering
(Added Elixir) |
(→{{header|Ruby}}: refactering) |
||
Line 2,755:
=={{header|Ruby}}==
===
{{trans|Python}}
<lang ruby>require 'set'
Line 2,761:
class Sokoban
def initialize(level)
board = level.each_line.map(&:
@nrows = board.map(&:size).max
board.each_with_index do |row, r|
row.each_char.with_index do |ch, c|
Line 2,769:
end
end
@goal = board.join.tr(' .@#$+*', ' . ..')
@
end
Line 2,778 ⟶ 2,779:
end
def push(x, y, dx, dy,
return
end
def solved?(
@goal.all?{|i|
end
DIRS = [[0, -1, 'u', 'U'], [ 1, 0, 'r', 'R'], [0, 1, 'd', 'D'], [-1, 0, 'l', 'L']]
def solve
visited = Set[@
until
for dx, dy, cmove, cpush in DIRS
next
when ' '
▲ temp[ps] = '@'
end
end
|