I am new to kotlin . I am trying to create simple tic tac toe game app.
In many tutorial i have seen most of them using if statement to find the winners.So i tried to modify with predefiend values and check them with players input.
\\ this funtion checks the winner , where player1 and player2 are arraylist.
\\ example : player1 = [1,2,8] and player2 = [4,5,6]
fun checkWinner(player1,player2){
var possibleCombos = arrayListOf(
arrayListOf(1,2,3), arrayListOf(4,5,6), arrayListOf(7,8,9),
arrayListOf(1,4,7), arrayListOf(2,5,8), arrayListOf(3,6,9),
arrayListOf(7,5,3), arrayListOf(1,5,9))
for(items in possibleCombos) {
if(a.containsAll(items)) {
Toast.makeText(this,"Winner is A $a",Toast.LENGTH_LONG).show()
}
else if (b.containsAll(items)) {
Toast.makeText(this,"Winner is B $b",Toast.LENGTH_LONG).show()
}
else {
Toast.makeText(this,"Game is tie",Toast.LENGTH_SHORT).show()
}
}
}
It is not working and the else part is executing always. I want to toast the result.
Any solution?