class Board
Attributes
cells[RW]
Public Class Methods
new()
click to toggle source
# File lib/tictactoe_tracypholmes/board.rb, line 4 def initialize() reset! end
Public Instance Methods
display()
click to toggle source
# File lib/tictactoe_tracypholmes/board.rb, line 12 def display puts " #{cells[0]} | #{cells[1]} | #{cells[2]} " puts '-----------' puts " #{cells[3]} | #{cells[4]} | #{cells[5]} " puts '-----------' puts " #{cells[6]} | #{cells[7]} | #{cells[8]} " puts "\n" end
full?()
click to toggle source
define full here - every element on the board contains “X” or “O”
# File lib/tictactoe_tracypholmes/board.rb, line 31 def full? @cells.all? do |mark| mark == 'X' || mark == 'O' end end
input_index(input)
click to toggle source
# File lib/tictactoe_tracypholmes/board.rb, line 21 def input_index(input) # this one line is all over the place! input.to_i - 1 end
position(input)
click to toggle source
position method
# File lib/tictactoe_tracypholmes/board.rb, line 26 def position(input) @cells[input_index(input)] end
reset!()
click to toggle source
# File lib/tictactoe_tracypholmes/board.rb, line 8 def reset! @cells = Array.new(9, " ") end
taken?(input)
click to toggle source
taken? method
# File lib/tictactoe_tracypholmes/board.rb, line 47 def taken?(input) exxo = position(input) exxo != " " ? true:false end
turn_count()
click to toggle source
define turn_count
here
# File lib/tictactoe_tracypholmes/board.rb, line 38 def turn_count counter = 0 @cells.each do |occupied_spot| counter += 1 if occupied_spot != ' ' end counter end
update(input, player)
click to toggle source
define update
# File lib/tictactoe_tracypholmes/board.rb, line 62 def update(input, player) @cells[input_index(input)] = player.token end
valid_move?(input)
click to toggle source
valid_move? method here
# File lib/tictactoe_tracypholmes/board.rb, line 53 def valid_move?(input) if position(input) == " " && input.to_i.between?(1, 9) true # input on the board && input not taken else false # return false or nil here for invalid move end end