Class: Codenjoy::Client::Games::Loderunner::Board

Inherits:
BaseBoard
  • Object
show all
Defined in:
lib/codenjoy/games/loderunner/board.rb

Constant Summary collapse

ELEMENTS =
{
  # a void
  NONE: ' ',

  # walls
  BRICK: '#',
  PIT_FILL_1: '1',
  PIT_FILL_2: '2',
  PIT_FILL_3: '3',
  PIT_FILL_4: '4',
  UNDESTROYABLE_WALL: '',

  DRILL_PIT: '*',

  # this is enemy
  ENEMY_LADDER: 'Q',
  ENEMY_LEFT: '«',
  ENEMY_RIGHT: '»',
  ENEMY_PIPE_LEFT: '<',
  ENEMY_PIPE_RIGHT: '>',
  ENEMY_PIT: 'X',

  # gold ;)
  GOLD: '$',

  # this is you
  HERO_DIE: 'Ѡ',
  HERO_DRILL_LEFT: 'Я',
  HERO_DRILL_RIGHT: 'R',
  HERO_LADDER: 'Y',
  HERO_LEFT: '',
  HERO_RIGHT: '',
  HERO_FALL_LEFT: ']',
  HERO_FALL_RIGHT: '[',
  HERO_PIPE_LEFT: '{',
  HERO_PIPE_RIGHT: '}',

  # this is other players
  OTHER_HERO_DIE: 'Z',
  OTHER_HERO_LEFT: ')',
  OTHER_HERO_RIGHT: '(',
  OTHER_HERO_LADDER: 'U',
  OTHER_HERO_PIPE_LEFT: 'Э',
  OTHER_HERO_PIPE_RIGHT: 'Є',

  # ladder and pipe - you can walk
  LADDER: 'H',
  PIPE: '~'
}
HERO =
[
  :HERO_DIE, :HERO_DRILL_LEFT, :HERO_DRILL_RIGHT,
  :HERO_FALL_RIGHT, :HERO_FALL_LEFT, :HERO_LADDER,
  :HERO_LEFT, :HERO_RIGHT, :HERO_PIPE_LEFT, :HERO_PIPE_RIGHT
]
OTHER_HERO =
[
  :OTHER_HERO_LEFT, :OTHER_HERO_RIGHT, :OTHER_HERO_LADDER, :OTHER_HERO_PIPE_LEFT, :OTHER_HERO_PIPE_RIGHT
]
ENEMY =
[
  :ENEMY_LADDER, :ENEMY_LADDER, :ENEMY_LEFT, :ENEMY_PIPE_LEFT, :ENEMY_PIPE_RIGHT, :ENEMY_RIGHT, :ENEMY_PIT
]
PIPE =
[
  :PIPE, :HERO_PIPE_LEFT, :HERO_PIPE_RIGHT, :OTHER_HERO_PIPE_LEFT, :OTHER_HERO_PIPE_RIGHT
]

Instance Method Summary collapse

Methods inherited from BaseBoard

#any_of_at?, #at?, #board_to_s, #count_near, #find_all, #find_by_list, #get_at, #near?, #size, #xyl

Instance Method Details

#barrier_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
159
# File 'lib/codenjoy/games/loderunner/board.rb', line 156

def barrier_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  !get_barriers.index([x, y]).nil?
end

#enemy_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
164
# File 'lib/codenjoy/games/loderunner/board.rb', line 161

def enemy_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  any_of_at?(x, y, ENEMY.map{ |e| ELEMENTS[e] })
end

#game_over?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/codenjoy/games/loderunner/board.rb', line 148

def game_over?
  !@raw.index(ELEMENTS[:HERO_DIE]).nil?
end

#get_barriersObject



152
153
154
# File 'lib/codenjoy/games/loderunner/board.rb', line 152

def get_barriers
  [get_enemies, get_other_heroes, get_walls].flatten(1)
end

#get_enemiesObject



128
129
130
# File 'lib/codenjoy/games/loderunner/board.rb', line 128

def get_enemies
  find_by_list(ENEMY.map{ |e| ELEMENTS[e] })
end

#get_goldObject



132
133
134
# File 'lib/codenjoy/games/loderunner/board.rb', line 132

def get_gold
  find_by_list([ELEMENTS[:GOLD]])
end

#get_laddersObject



140
141
142
# File 'lib/codenjoy/games/loderunner/board.rb', line 140

def get_ladders
  find_by_list([ELEMENTS[:LADDER], ELEMENTS[:HERO_LADDER], ELEMENTS[:ENEMY_LADDER]])
end

#get_meObject



120
121
122
# File 'lib/codenjoy/games/loderunner/board.rb', line 120

def get_me
  find_by_list(HERO.map{ |e| ELEMENTS[e] })
end

#get_other_heroesObject



124
125
126
# File 'lib/codenjoy/games/loderunner/board.rb', line 124

def get_other_heroes
  find_by_list(OTHER_HERO.map{ |e| ELEMENTS[e] })
end

#get_pipesObject



144
145
146
# File 'lib/codenjoy/games/loderunner/board.rb', line 144

def get_pipes
  find_by_list(PIPE.map{ |e| ELEMENTS[e] })
end

#get_wallsObject



136
137
138
# File 'lib/codenjoy/games/loderunner/board.rb', line 136

def get_walls
  find_by_list([ELEMENTS[:BRICK], ELEMENTS[:UNDESTROYABLE_WALL]])
end

#gold_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
184
# File 'lib/codenjoy/games/loderunner/board.rb', line 181

def gold_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  at?(x, y, ELEMENTS[:GOLD])
end

#ladder_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
179
# File 'lib/codenjoy/games/loderunner/board.rb', line 176

def ladder_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  any_of_at?(x, y, [ELEMENTS[:LADDER], ELEMENTS[:HERO_LADDER], ELEMENTS[:ENEMY_LADDER]])
end

#other_hero_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
169
# File 'lib/codenjoy/games/loderunner/board.rb', line 166

def other_hero_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  any_of_at?(x, y, OTHER_HERO.map{ |e| ELEMENTS[e] })
end

#pipe_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


186
187
188
189
# File 'lib/codenjoy/games/loderunner/board.rb', line 186

def pipe_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  any_of_at?(x, y, PIPE.map{ |e| ELEMENTS[e] })
end

#process(data) ⇒ Object



105
106
107
# File 'lib/codenjoy/games/loderunner/board.rb', line 105

def process(data)
  @raw = data
end

#to_sObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/codenjoy/games/loderunner/board.rb', line 109

def to_s
  [
    "Board:",
    board_to_s,
    "Me at: #{get_me}",
    "Other heroes at: #{get_other_heroes}",
    "Enemies at: #{get_enemies}",
    "Gold at: #{get_gold}"
  ].join("\n")
end

#wall_at?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


171
172
173
174
# File 'lib/codenjoy/games/loderunner/board.rb', line 171

def wall_at?(x, y)
  return false if Point.new(x, y).out_of?(size)
  any_of_at?(x, y, [ELEMENTS[:BRICK], ELEMENTS[:UNDESTROYABLE_WALL]])
end