-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.rb
More file actions
26 lines (23 loc) · 1.06 KB
/
rules.rb
File metadata and controls
26 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Rules
def game_over?(moves_remaining)
if moves_remaining == 0
return true
else
return false
end
end
def win_check(board)
transposed_board = board.transpose
if board[0][0] == board[1][1] && board[0][0] == board[2][2] && board[0][0] != " "
return true
elsif board[0][2] == board[1][1] && board[0][2] == board[2][0] && board[0][2] != " "
return true
elsif board[0].all? {|x| x == board[0][0] } && board[0][0] != " " || board[1].all? {|x| x == board[1][0] } && board[1][0] != " " || board[2].all? {|x| x == board[2][0] } && board[2][0] != " "
return true
elsif transposed_board[0].all? {|x| x == transposed_board[0][0] } && transposed_board[0][0] != " " || transposed_board[1].all? {|x| x == transposed_board[1][0] } && transposed_board[1][0] != " " || transposed_board[2].all? {|x| x == transposed_board[2][0] } && transposed_board[2][0] != " "
return true
else
return false
end
end
end