class Gobstones::Runner::Head
Constants
- MAX_COLS
- MAX_ROWS
Attributes
board[R]
x_pos[R]
y_pos[R]
Public Class Methods
at_random()
click to toggle source
# File lib/gobstones/runner/head.rb, line 12 def self.at_random new.at_random end
new()
click to toggle source
# File lib/gobstones/runner/head.rb, line 20 def initialize with_position_and_board(0, 0, Board.new(MAX_ROWS, MAX_COLS)) end
with_position_and_board(x_pos, y_pos, board)
click to toggle source
# File lib/gobstones/runner/head.rb, line 16 def self.with_position_and_board(x_pos, y_pos, board) new.with_position_and_board(x_pos, y_pos, board) end
Public Instance Methods
are_there_balls?(color)
click to toggle source
# File lib/gobstones/runner/head.rb, line 97 def are_there_balls?(color) @board.are_there_balls?(x_pos, y_pos, color) end
at_random()
click to toggle source
# File lib/gobstones/runner/head.rb, line 24 def at_random @x_pos = rand(MAX_ROWS) @y_pos = rand(MAX_COLS) self end
can_move?(dir)
click to toggle source
# File lib/gobstones/runner/head.rb, line 37 def can_move?(dir) check dir dir.can_move?(self) end
can_move_east?()
click to toggle source
# File lib/gobstones/runner/head.rb, line 50 def can_move_east? @x_pos < MAX_ROWS - 1 end
can_move_north?()
click to toggle source
# File lib/gobstones/runner/head.rb, line 42 def can_move_north? @y_pos < MAX_COLS - 1 end
can_move_south?()
click to toggle source
# File lib/gobstones/runner/head.rb, line 46 def can_move_south? @y_pos.positive? end
can_move_west?()
click to toggle source
# File lib/gobstones/runner/head.rb, line 54 def can_move_west? @x_pos.positive? end
clone()
click to toggle source
# File lib/gobstones/runner/head.rb, line 101 def clone self.class.with_position_and_board(x_pos, y_pos, board.clone) end
go_to_origin()
click to toggle source
# File lib/gobstones/runner/head.rb, line 80 def go_to_origin @x_pos = 0 @y_pos = 0 end
move(dir)
click to toggle source
# File lib/gobstones/runner/head.rb, line 58 def move(dir) raise OutOfBoardError unless can_move?(dir) dir.move self end
move_east()
click to toggle source
# File lib/gobstones/runner/head.rb, line 72 def move_east @x_pos += 1 end
move_north()
click to toggle source
# File lib/gobstones/runner/head.rb, line 64 def move_north @y_pos += 1 end
move_south()
click to toggle source
# File lib/gobstones/runner/head.rb, line 68 def move_south @y_pos -= 1 end
move_west()
click to toggle source
# File lib/gobstones/runner/head.rb, line 76 def move_west @x_pos -= 1 end
number_of_balls(color)
click to toggle source
# File lib/gobstones/runner/head.rb, line 93 def number_of_balls(color) @board.number_of_balls(x_pos, y_pos, color) end
put(color)
click to toggle source
# File lib/gobstones/runner/head.rb, line 85 def put(color) @board.put x_pos, y_pos, color end
take_out(color)
click to toggle source
# File lib/gobstones/runner/head.rb, line 89 def take_out(color) @board.take_out x_pos, y_pos, color end
with_position_and_board(x_pos, y_pos, board)
click to toggle source
# File lib/gobstones/runner/head.rb, line 30 def with_position_and_board(x_pos, y_pos, board) @x_pos = x_pos @y_pos = y_pos @board = board self end
Private Instance Methods
check(dir)
click to toggle source
# File lib/gobstones/runner/head.rb, line 107 def check(dir) raise GobstonesTypeError, "#{dir} is not a direction" unless [Norte, Sur, Este, Oeste].include?(dir.class) end