Class: Computer
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#piece ⇒ Object
readonly
Returns the value of attribute piece.
Instance Method Summary collapse
- #computer_turn(board) ⇒ Object
-
#initialize(board) ⇒ Computer
constructor
A new instance of Computer.
Methods included from Indexable
Constructor Details
#initialize(board) ⇒ Computer
Returns a new instance of Computer.
7 8 9 10 |
# File 'lib/computer.rb', line 7 def initialize(board) @piece = 'o' @board = board end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
5 6 7 |
# File 'lib/computer.rb', line 5 def board @board end |
#piece ⇒ Object (readonly)
Returns the value of attribute piece.
5 6 7 |
# File 'lib/computer.rb', line 5 def piece @piece end |
Instance Method Details
#computer_turn(board) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/computer.rb', line 12 def computer_turn(board) # puts "The computer will now make a turn." column = @board.columns.sample integer = index_column(column) until @board.valid_column(column) == true column = @board.columns.sample end #if @board.valid_column(column) == true && @board.column_full(integer) == false integer = index_column(column) until @board.column_full(integer) == false column = @board.columns.sample integer = index_column(column) end board.drop_disc(integer, @piece) end |