Class: ComputerRandom

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

Constant Summary collapse

OPPONENT =
{"O"=>"X", "X"=>"O"}
COLUMNS =
[:A, :B, :C, :D, :E, :F, :G]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enemy_type = "X") ⇒ ComputerRandom

Returns a new instance of ComputerRandom.



3
4
5
6
# File 'lib/computer_random.rb', line 3

def initialize(enemy_type = "X")
  @type = OPPONENT[enemy_type]
  @enemy = enemy_type
end

Instance Attribute Details

#enemyObject (readonly)

Returns the value of attribute enemy.



2
3
4
# File 'lib/computer_random.rb', line 2

def enemy
  @enemy
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/computer_random.rb', line 2

def type
  @type
end

Instance Method Details

#place_piece(board) ⇒ Object



11
12
13
# File 'lib/computer_random.rb', line 11

def place_piece(board)
  board.place_piece(COLUMNS[rand(0..6)], @type)
end