You don't check if you won (check_win
) and you don't change @win_combo
while g.win_status != true
#puts g.check_win
g.set_turn
g.make_move
g.show_board
g.win_combo #this line
g.check_win #and this line
end
And in your @win_combo suppose to be array of strings not array of arrays of strings. For example, your old code:
[["ooo"], ["_xx"], [" "], ["o_ "], ["ox "], ["ox "], ["ox "], ["ox "]]
new one:
["ooo", ["_x_"], [" "], ["o_ "], ["ox "], ["o_ "], ["ox "], ["ox "]]
Just add *
ad the beginning(as I did here) or just don't make arrays:
@win_combo = [*[@board[1][1] + @board[2][1] + @board[3][2]], [@board[4][2] + @board[5][1] + @board[6][2]], [@board[7][1] + @board[8][1] + @board[9][1]],[@board[1][1] + @board[4][2] + @board[7][1]], [@board[2][1] + @board[5][1] + @board[8][1]], [@board[3][2] + @board[6][2] + @board[9][1]], [@board[1][1] + @board[5][1] + @board[9][1]], [@board[3][2] + @board[5][1] + @board[7][1]]]
Edit:
Ok, *
applied only to the first array, my bad.
This is a correct version.
You can see where I've put ()
instead of []
; By this I made array of strings.
Additionally you had you have checked wrong position on following combinations.
@win_combo = [
(@board[1][1] + @board[2][1] + @board[3][2]), # ok
(@board[4][2] + @board[5][1] + @board[6][2]), # ok
(@board[7][2] + @board[8][1] + @board[9][1]), # this # [7][2] not [7][1]
(@board[1][1] + @board[4][2] + @board[7][2]), # this # [4][2] not [4][1]; [7][2]
(@board[2][1] + @board[5][1] + @board[8][1]), # ok
(@board[3][2] + @board[6][2] + @board[9][1]), # ok
(@board[1][1] + @board[5][1] + @board[9][1]), # ok
(@board[3][2] + @board[5][1] + @board[7][2]) # this [7][2] not [7][1]
]
puts "\n#@win_combo\n"
@win_combo
end
ps. puts "\n#@win_combo\n"
is for debuging your application. Delete it in release version.