Class: TTT::FourByFour
Instance Attribute Summary collapse
-
#block_arr ⇒ Object
Returns the value of attribute block_arr.
-
#diag_arr ⇒ Object
Returns the value of attribute diag_arr.
-
#x_arr ⇒ Object
Returns the value of attribute x_arr.
Attributes inherited from Board
Instance Method Summary collapse
- #block_winner? ⇒ Boolean
- #board_type ⇒ Object
- #diag_winner? ⇒ Boolean
- #horizontal_winner? ⇒ Boolean
-
#initialize ⇒ FourByFour
constructor
A new instance of FourByFour.
- #vertical_winner? ⇒ Boolean
- #winner? ⇒ Boolean
Methods inherited from Board
#[], #[]=, #draw_game?, #empty?, #finished?, #free?, #full?, #update
Constructor Details
#initialize ⇒ FourByFour
Returns a new instance of FourByFour.
5 6 7 8 9 10 |
# File 'lib/ttt/four_by_four.rb', line 5 def initialize self.board = Array.new(16, " ") self.x_arr = [[0,1,2,3], [4,5,6,7], [8,9,10,11], [12,13,14,15]] self.diag_arr = [[0, 5, 10, 15], [3, 6, 9, 12]] self.block_arr = [[0,1,4,5], [1,2,5,6], [2,3,6,7], [4,5,8,9], [5,6,9,10], [6,7,10,11], [8,9,12,13], [9,10,13,14], [10,11,14,15]] end |
Instance Attribute Details
#block_arr ⇒ Object
Returns the value of attribute block_arr.
4 5 6 |
# File 'lib/ttt/four_by_four.rb', line 4 def block_arr @block_arr end |
#diag_arr ⇒ Object
Returns the value of attribute diag_arr.
4 5 6 |
# File 'lib/ttt/four_by_four.rb', line 4 def diag_arr @diag_arr end |
#x_arr ⇒ Object
Returns the value of attribute x_arr.
4 5 6 |
# File 'lib/ttt/four_by_four.rb', line 4 def x_arr @x_arr end |
Instance Method Details
#block_winner? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ttt/four_by_four.rb', line 47 def block_winner? block_arr.each do |block_win| return true if board[block_win[0]] != " " && board[block_win[0]] == board[block_win[1]] && board[block_win[1]] == board[block_win[2]] && board[block_win[2]] == board[block_win[3]] end false end |
#board_type ⇒ Object
58 59 60 |
# File 'lib/ttt/four_by_four.rb', line 58 def board_type "four_by_four" end |
#diag_winner? ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ttt/four_by_four.rb', line 36 def diag_winner? diag_arr.each do |diag_win| return true if board[diag_win[0]] != " " && board[diag_win[0]] == board[diag_win[1]] && board[diag_win[1]] == board[diag_win[2]] && board[diag_win[2]] == board[diag_win[3]] end false end |
#horizontal_winner? ⇒ Boolean
16 17 18 19 20 21 22 23 24 |
# File 'lib/ttt/four_by_four.rb', line 16 def horizontal_winner? x_arr.each do |x_win| return true if board[x_win[0]] != " " && board[x_win[0]] == board[x_win[1]] && board[x_win[1]] == board[x_win[2]] && board[x_win[2]] == board[x_win[3]] end false end |
#vertical_winner? ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'lib/ttt/four_by_four.rb', line 26 def vertical_winner? x_arr.transpose.each do |y_win| return true if board[y_win[0]] != " " && board[y_win[0]] == board[y_win[1]] && board[y_win[1]] == board[y_win[2]] && board[y_win[2]] == board[y_win[3]] end false end |
#winner? ⇒ Boolean
12 13 14 |
# File 'lib/ttt/four_by_four.rb', line 12 def winner? horizontal_winner? || vertical_winner? || diag_winner? || block_winner? end |