Class: ComputerRandom
- Inherits:
-
Object
- Object
- ComputerRandom
- 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
-
#enemy ⇒ Object
readonly
Returns the value of attribute enemy.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(enemy_type = "X") ⇒ ComputerRandom
constructor
A new instance of ComputerRandom.
- #place_piece(board) ⇒ Object
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
#enemy ⇒ Object (readonly)
Returns the value of attribute enemy.
2 3 4 |
# File 'lib/computer_random.rb', line 2 def enemy @enemy end |
#type ⇒ Object (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 |