class MinesweeperBoard(val inputBoard: List<String>) {
    val board by lazy {
        val board: MutableList<Cell> = mutableListOf()
        for (i in 0..inputBoard.size - 1){
            for (j in 0..inputBoard[i].length - 1){
                if (inputBoard[i][j] == '*'){
                    board.add(Cell(x = i, y = j, mine = true, neighbors = 0))
                }else {
                    var neighbors: Int = 0
                    for (xOffset in -1..1) {
                        for (yOffset in -1..1) {
                            if ((xOffset + i >= 0)
                                    and (xOffset + i < inputBoard.size)
                                    and (yOffset + j >= 0)
                                    and (yOffset + j < inputBoard[i].length)
                                    ) {
                                if (inputBoard[i + xOffset][j + yOffset] == '*') {
                                    neighbors += 1
                                }
                            }
                        }
                    }
                    board.add(Cell(x = i, y = j, mine = false, neighbors = neighbors))
                }

            }
        }
        board
    }

    fun withNumbers(): List<String>{
        val returnList = mutableListOf<String>()
        for (i in 0..inputBoard.size - 1){
            val stringBuilder: StringBuilder = StringBuilder()
            for (j in 0..inputBoard[i].length - 1){
                stringBuilder.append(board[(i*inputBoard[i].length)+j])
            }
            returnList.add(String(stringBuilder))
        }

        return returnList
    }
}

data class Cell(val x: Int, val y: Int, val mine: Boolean, val neighbors: Int){
    override fun toString(): String {
        if (mine){
            return "*"
        } else if (neighbors == 0) {
            return " "
        } else {
            return neighbors.toString()
        }                       }
}