Class: Board
- Inherits:
-
Object
show all
- Defined in:
- lib/board.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#row_length ⇒ Object
Returns the value of attribute row_length.
3
4
5
|
# File 'lib/board.rb', line 3
def row_length
@row_length
end
|
Instance Method Details
#board_is_full? ⇒ Boolean
45
46
47
|
# File 'lib/board.rb', line 45
def board_is_full?
!@board_array.include?(:open)
end
|
#check_for_tie ⇒ Object
deprecated, write tests for board_is_full?
37
38
39
|
# File 'lib/board.rb', line 37
def check_for_tie
if @board_array.include?(:open) then return :continue_game else return :tie end
end
|
#game_over? ⇒ Boolean
26
27
28
|
# File 'lib/board.rb', line 26
def game_over?
check_board_status != :continue_game
end
|
#get_open_spots ⇒ Object
9
10
11
12
13
|
# File 'lib/board.rb', line 9
def get_open_spots
open_spots = []
@board_array.each_index {|index| open_spots << index if @board_array[index] == :open}
open_spots
end
|
#get_print_results ⇒ Object
5
6
7
|
# File 'lib/board.rb', line 5
def get_print_results
[@board_array, @row_length]
end
|
#record_choice(choice, player) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/board.rb', line 19
def record_choice choice, player
if valid_choice?(choice) && @board_array[choice] == :open
@board_array[choice] = player
return true
else return false end
end
|
#remove_choice(choice) ⇒ Object
15
16
17
|
# File 'lib/board.rb', line 15
def remove_choice choice
@board_array[choice] = :open if valid_choice? choice
end
|
#reset_board ⇒ Object
49
50
51
|
# File 'lib/board.rb', line 49
def reset_board
@board_array.fill(:open)
end
|
#valid_choice?(choice) ⇒ Boolean
30
31
32
33
34
|
# File 'lib/board.rb', line 30
def valid_choice? choice
choice = choice.to_i
if choice >= 0 && choice <= @board_array.length
return true else return false end
end
|
#win_is_found(a) ⇒ Object
41
42
43
|
# File 'lib/board.rb', line 41
def win_is_found a
a.size == 1 && !a.include?(:open)
end
|