Implementing a game status check

In this section, we will work on functions that will help us figure out the winner of our game.

Start by adding the following function to the MainActivity class:

private fun isBoardFull(gameBoard:Array<CharArray>): Boolean {    for (i in 0 until gameBoard.size) {         for (j in 0 until gameBoard[i].size) {             if(gameBoard[i][j] == ' ') {                return false            }        }    }    return true}

This function is used to check whether the game board is full. Here, we go through all the cells on the board and return false if any of them are empty. If none of the cells are empty, we return true

Next, add the isWinner() method:

private fun isWinner(gameBoard:Array<CharArray>, w: Char): Boolean {    for (i in 0 until gameBoard.size) {        if (gameBoard[i][ ...

Get Learning Kotlin by building Android Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.