Class: TTT::ThreeByThree
Instance Attribute Summary collapse
-
#win_arr ⇒ Object
Returns the value of attribute win_arr.
-
#win_block ⇒ Object
Returns the value of attribute win_block.
Attributes inherited from Board
Instance Method Summary collapse
- #block_winner? ⇒ Boolean
- #board_type ⇒ Object
-
#initialize ⇒ ThreeByThree
constructor
A new instance of ThreeByThree.
- #winner? ⇒ Boolean
Methods inherited from Board
#[], #[]=, #draw_game?, #empty?, #finished?, #free?, #full?, #update
Constructor Details
#initialize ⇒ ThreeByThree
Returns a new instance of ThreeByThree.
6 7 8 9 10 |
# File 'lib/ttt/three_by_three.rb', line 6 def initialize self.board = Array.new(9, " ") self.win_arr = [[0,1,2], [0,4,8], [0,3,6], [1,4,7], [2,5,8], [2,4,6], [3,4,5], [6,7,8]] self.win_block = [[0,1,3,4], [1,2,4,5], [3,4,6,7], [4,5,7,8]] end |
Instance Attribute Details
#win_arr ⇒ Object
Returns the value of attribute win_arr.
5 6 7 |
# File 'lib/ttt/three_by_three.rb', line 5 def win_arr @win_arr end |
#win_block ⇒ Object
Returns the value of attribute win_block.
5 6 7 |
# File 'lib/ttt/three_by_three.rb', line 5 def win_block @win_block end |
Instance Method Details
#block_winner? ⇒ Boolean
21 22 23 24 25 26 27 28 29 |
# File 'lib/ttt/three_by_three.rb', line 21 def block_winner? win_block.each do |win_combo| return true if board[win_combo[0]] == board[win_combo[1]] && board[win_combo[1]] == board[win_combo[2]] && board[win_combo[2]] == board[win_combo[3]] && board[win_combo[0]] != " " end false end |
#board_type ⇒ Object
31 32 33 |
# File 'lib/ttt/three_by_three.rb', line 31 def board_type "three_by_three" end |
#winner? ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/ttt/three_by_three.rb', line 12 def winner? win_arr.each do |win_combo| return true if board[win_combo[0]] == board[win_combo[1]] && board[win_combo[1]] == board[win_combo[2]] && board[win_combo[0]] != " " end block_winner? end |