Class: Alpha::Mover

Inherits:
Object
  • Object
show all
Defined in:
lib/alpha/mover.rb

Instance Method Summary collapse

Instance Method Details

#go_down(row, column, grid) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/alpha/mover.rb', line 25

def go_down(row, column, grid)
  i = 1
  while true
    index = grid.index_of(row)

    square_candidate_value = grid.query("#{grid.letters[index + i]}#{column}")
    return "#{grid.letters[index + i]}#{column}" if square_candidate_value == :empty
    break unless square_candidate_value == :hit
    i += 1
  end
end

#go_left(row, column, grid) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/alpha/mover.rb', line 15

def go_left(row, column, grid)
  i = 1
  while true
    square_candidate_value = grid.query("#{row}#{column - i}")
    return "#{row}#{column - i}" if square_candidate_value == :empty
    break unless square_candidate_value == :hit
    i += 1
  end
end

#go_right(row, column, grid) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/alpha/mover.rb', line 5

def go_right(row, column, grid)
  i = 1
  while true
    square_candidate_value = grid.query("#{row}#{column + i}")
    return "#{row}#{column + i}" if square_candidate_value == :empty
    break unless square_candidate_value == :hit
    i += 1
  end
end

#go_up(row, column, grid) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/alpha/mover.rb', line 37

def go_up(row, column, grid)
  i = 1
  while true
    index = grid.index_of(row)

    square_candidate_value = grid.query("#{grid.letters[index - i]}#{column}")
    return "#{grid.letters[index - i]}#{column}" if square_candidate_value == :empty
    break unless square_candidate_value == :hit
    i += 1
  end
end