Bạn có thể thấy rằng nó hỗ trợ nhiều loại câu trả lời có thể được chuyển đổi bao gồm Integer, Symbol, hoặc thậm chí gồm cả những phản hồi và những đề nghị, gợi ý có thể có bất kỳ giao diện, nhưng sẽ có thể chơi chống lại con người | Answer 11. Sokoban 139 sokoban module Sokoban class Crate def to_s o end end class Person def to_s @ end end end Then we get to the meat of the program which is the Level class sokoban module Sokoban class Level attr_reader move s def initialize str @grid n .map ln .map c c throw No player found on level if player_index throw No challenge if solved @move s 0 end def r c @grid r c end def to_s @ row oin .join n end returns a 2-element array with the row and column of the player s position respectively def player_index @ do row @grid row .each_index do col if @grid row col .respond_to resident Person @grid row col .resident return row col end end end nil end def solved a level is solved when every Storage tile has a Crate @ tile Storage tile end def move dir if NORTH SOUTH EAST WEST .include dir Report erratum Answer 11. Sokoban 140 pos player_index target @grid pos 0 dir 0 pos 1 dir 1 if Floor target if Crate indirect_target @grid pos 0 2 dir 0 pos 1 2 dir 1 if Floor indirect_target @grid pos 0 2 dir 0 pos 1 2 dir 1 @grid pos 0 dir 0 pos 1 dir 1 .clear @grid pos 0 dir 0 pos 1 dir 1 @grid pos 0 pos 1 .clear return @moves 1 end else @grid pos 0 dir 0 pos 1 dir 1 @grid pos 0 pos 1 .clear return @moves 1 end end end nil end end end Level objects build a @grid of Tile objects in initialized to manage their state. The methods and to_s provide indexing and display for the @grid. You can also easily locate the Person object in the @grid with player_index and see whether the Level is complete with solved . The final method of Level is move which works roughly the same as Dennis s version. It finds the player and checks the square in the direction the player is trying to move. If a crate is found there it also checks the square behind that one. The rest of Dave s solution is an .