Class: Codenjoy::Client::Games::Icancode::Board
- Inherits:
-
Object
- Object
- Codenjoy::Client::Games::Icancode::Board
- Defined in:
- lib/codenjoy/games/icancode/board.rb
Constant Summary collapse
- ELEMENT =
{ EMPTY: '-', FLOOR: '.', ANGLE_IN_LEFT: '╔', WALL_FRONT: '═', ANGLE_IN_RIGHT: '┐', WALL_RIGHT: '│', ANGLE_BACK_RIGHT: '┘', WALL_BACK: '─', ANGLE_BACK_LEFT: '└', WALL_LEFT: '║', WALL_BACK_ANGLE_LEFT: '┌', WALL_BACK_ANGLE_RIGHT: '╗', ANGLE_OUT_RIGHT: '╝', ANGLE_OUT_LEFT: '╚', SPACE: ' ', LASER_MACHINE_CHARGING_LEFT: '˂', LASER_MACHINE_CHARGING_RIGHT: '˃', LASER_MACHINE_CHARGING_UP: '˄', LASER_MACHINE_CHARGING_DOWN: '˅', LASER_MACHINE_READY_LEFT: '◄', LASER_MACHINE_READY_RIGHT: '►', LASER_MACHINE_READY_UP: '▲', LASER_MACHINE_READY_DOWN: '▼', START: 'S', EXIT: 'E', HOLE: 'O', BOX: 'B', ZOMBIE_START: 'Z', GOLD: '$', ROBOT: '☺', ROBOT_FALLING: 'o', ROBOT_FLYING: '*', ROBOT_LASER: '☻', ROBOT_OTHER: 'X', ROBOT_OTHER_FALLING: 'x', ROBOT_OTHER_FLYING: '^', ROBOT_OTHER_LASER: '&', LASER_LEFT: '←', LASER_RIGHT: '→', LASER_UP: '↑', LASER_DOWN: '↓', FEMALE_ZOMBIE: '♀', MALE_ZOMBIE: '♂', ZOMBIE_DIE: '✝' }
- WALLS =
[ :ANGLE_IN_LEFT, :WALL_FRONT, :ANGLE_IN_RIGHT, :WALL_RIGHT, :ANGLE_BACK_RIGHT, :WALL_BACK, :ANGLE_BACK_LEFT, :WALL_LEFT, :WALL_BACK_ANGLE_LEFT, :WALL_BACK_ANGLE_RIGHT, :ANGLE_OUT_RIGHT, :ANGLE_OUT_LEFT, :SPACE ]
Instance Attribute Summary collapse
-
#l1 ⇒ Object
short names for layers.
-
#l2 ⇒ Object
short names for layers.
-
#l3 ⇒ Object
short names for layers.
Instance Method Summary collapse
- #board_to_s ⇒ Object
- #command ⇒ Object
- #get_boxes ⇒ Object
- #get_exits ⇒ Object
- #get_gold ⇒ Object
- #get_holes ⇒ Object
- #get_laser_machines ⇒ Object
- #get_lasers ⇒ Object
- #get_me ⇒ Object
- #get_other_heroes ⇒ Object
- #get_starts ⇒ Object
- #get_walls ⇒ Object
- #get_zombies ⇒ Object
- #headfoot ⇒ Object
- #headlayers ⇒ Object
- #infoline(n) ⇒ Object
- #nline(i) ⇒ Object
- #numberinline(length) ⇒ Object
- #process(data) ⇒ Object
- #to_s ⇒ Object
- #wall_at?(x, y) ⇒ Boolean
Instance Attribute Details
#l1 ⇒ Object
short names for layers
104 105 106 |
# File 'lib/codenjoy/games/icancode/board.rb', line 104 def l1 @l1 end |
#l2 ⇒ Object
short names for layers
104 105 106 |
# File 'lib/codenjoy/games/icancode/board.rb', line 104 def l2 @l2 end |
#l3 ⇒ Object
short names for layers
104 105 106 |
# File 'lib/codenjoy/games/icancode/board.rb', line 104 def l3 @l3 end |
Instance Method Details
#board_to_s ⇒ Object
213 214 215 216 217 218 |
# File 'lib/codenjoy/games/icancode/board.rb', line 213 def board_to_s ([headlayers, headfoot] + Array.new(size).each_with_index.map do |e, n| @data["layers"].map{ |l| nline(size - n - 1) + l[(n * size)..((n + 1) * size - 1)] }.join + (n) end + [headfoot]).join("\n") end |
#command ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/codenjoy/games/icancode/board.rb', line 106 def command # 'up' // you can move # 'down' # 'left' # 'right' # 'act(1)' // jump # 'act(2)' // pull box # 'act(3)' // fire # 'act(0)' // die end |
#get_boxes ⇒ Object
165 166 167 |
# File 'lib/codenjoy/games/icancode/board.rb', line 165 def get_boxes l2.find_by_list([ELEMENT[:BOX]]) end |
#get_exits ⇒ Object
161 162 163 |
# File 'lib/codenjoy/games/icancode/board.rb', line 161 def get_exits l1.find_by_list([ELEMENT[:EXIT]]) end |
#get_gold ⇒ Object
153 154 155 |
# File 'lib/codenjoy/games/icancode/board.rb', line 153 def get_gold l1.find_by_list([ELEMENT[:GOLD]]) end |
#get_holes ⇒ Object
169 170 171 |
# File 'lib/codenjoy/games/icancode/board.rb', line 169 def get_holes l1.find_by_list([ELEMENT[:HOLE]]) end |
#get_laser_machines ⇒ Object
173 174 175 176 177 178 |
# File 'lib/codenjoy/games/icancode/board.rb', line 173 def get_laser_machines l1.find_by_list([:LASER_MACHINE_CHARGING_LEFT, :LASER_MACHINE_CHARGING_RIGHT, :LASER_MACHINE_CHARGING_UP, :LASER_MACHINE_CHARGING_DOWN, :LASER_MACHINE_READY_LEFT, :LASER_MACHINE_READY_RIGHT, :LASER_MACHINE_READY_UP, :LASER_MACHINE_READY_DOWN].map{ |e| ELEMENT[e] }) end |
#get_lasers ⇒ Object
180 181 182 |
# File 'lib/codenjoy/games/icancode/board.rb', line 180 def get_lasers l2.find_by_list([:LASER_LEFT, :LASER_RIGHT, :LASER_UP, :LASER_DOWN].map{ |e| ELEMENT[e] }) end |
#get_me ⇒ Object
143 144 145 |
# File 'lib/codenjoy/games/icancode/board.rb', line 143 def get_me [@data['heroPosition']['x'], @data['heroPosition']['y']] end |
#get_other_heroes ⇒ Object
147 148 149 150 151 |
# File 'lib/codenjoy/games/icancode/board.rb', line 147 def get_other_heroes l2.find_by_list([ :ROBOT_OTHER, :ROBOT_OTHER_FALLING, :ROBOT_OTHER_LASER ].map{ |e| ELEMENT[e] }) + l3.find_by_list([ELEMENT[:ROBOT_OTHER_FLYING]]) end |
#get_starts ⇒ Object
157 158 159 |
# File 'lib/codenjoy/games/icancode/board.rb', line 157 def get_starts l1.find_by_list([ELEMENT[:START]]) end |
#get_walls ⇒ Object
188 189 190 |
# File 'lib/codenjoy/games/icancode/board.rb', line 188 def get_walls l1.find_by_list(WALLS.map{ |e| ELEMENT[e] }) end |
#get_zombies ⇒ Object
184 185 186 |
# File 'lib/codenjoy/games/icancode/board.rb', line 184 def get_zombies l2.find_by_list([:FEMALE_ZOMBIE, :MALE_ZOMBIE, :ZOMBIE_DIE].map{ |e| ELEMENT[e] }) end |
#headfoot ⇒ Object
134 135 136 |
# File 'lib/codenjoy/games/icancode/board.rb', line 134 def headfoot Array.new(3).map{ |i| " " + numberinline(size) }.join end |
#headlayers ⇒ Object
138 139 140 141 |
# File 'lib/codenjoy/games/icancode/board.rb', line 138 def headlayers spaces = ([' '] * (size - 6)).join() @data["layers"].each_with_index.map{ |e, n| " Layers#{n + 1}#{spaces}" }.join('') end |
#infoline(n) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/codenjoy/games/icancode/board.rb', line 196 def (n) res = [ " Robots: #{get_me}, #{get_other_heroes}", " Gold: #{get_gold}", " Starts: #{get_starts}", " Exits: #{get_exits}", " Boxes: #{get_boxes}", " Holes: #{get_holes}", " LaserMachine: #{get_laser_machines}", " Lasers: #{get_lasers}", " Zombies: #{get_zombies}" ] d = 1 return res[n - d] if d <= n && n < res.size + d "" end |
#nline(i) ⇒ Object
125 126 127 128 |
# File 'lib/codenjoy/games/icancode/board.rb', line 125 def nline(i) return " 0" if 0 == i format("%02.0d", i) end |
#numberinline(length) ⇒ Object
130 131 132 |
# File 'lib/codenjoy/games/icancode/board.rb', line 130 def numberinline(length) Array.new(length) { |i| (i % 10).to_s }.join end |
#process(data) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/codenjoy/games/icancode/board.rb', line 117 def process(data) @data = JSON.parse(data) @raw = @data["layers"][0] @l1 = Layer.new(@data["layers"][0]) @l2 = Layer.new(@data["layers"][1]) @l3 = Layer.new(@data["layers"][2]) end |
#to_s ⇒ Object
220 221 222 |
# File 'lib/codenjoy/games/icancode/board.rb', line 220 def to_s board_to_s end |