Class: TTT::Board

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

Direct Known Subclasses

FourByFour, ThreeByThree, ThreeByThreeByThree

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boardObject

Returns the value of attribute board.



3
4
5
# File 'lib/ttt/board.rb', line 3

def board
  @board
end

Instance Method Details

#[]Object



5
6
7
# File 'lib/ttt/board.rb', line 5

def []
  board
end

#[]=(array) ⇒ Object



9
10
11
# File 'lib/ttt/board.rb', line 9

def []=(array)
  self.board = array
end

#draw_game?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ttt/board.rb', line 33

def draw_game?
  (!board.include? " ") && !winner?
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ttt/board.rb', line 17

def empty?
  !(board.include?("x") || board.include?("o"))
end

#finished?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ttt/board.rb', line 29

def finished?
  draw_game? || winner?
end

#free?(cell) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ttt/board.rb', line 25

def free?(cell)
  board[cell] == " "
end

#full?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ttt/board.rb', line 21

def full?
  !board.include?(" ")
end

#update(cell, side) ⇒ Object



13
14
15
# File 'lib/ttt/board.rb', line 13

def update cell, side
  self.board[cell.to_i] = side
end