I have an assignment where I need to develop N in a row in Scala. For the representation of the board I want to loop through the 2d Array and print the X' en O's. This is the code for that:
override def toString(): String = {
val repres = ""
for (rowIndex <- 0 until board.length - 1) {
for (columnIndex <- 0 until board(rowIndex).length - 1) {
if (board(rowIndex)(columnIndex) == Player.Player1) {
repres + "X"
} else if (board(rowIndex)(columnIndex) == Player.Player2) {
repres + "O"
} else if (board(rowIndex)(columnIndex) == Player.NoPlayer) {
repres + "_"
} else {
throw new IllegalArgumentException
}
}
repres + Properties.lineSeparator
}
repres
}
This is the board:
var board = Array.fill[Player](rows,columns) {Player.NoPlayer}
For some reason it is not going through the for loop even though board.length is 6 in debugging.
I am new to scala so there is probably something very obvious wrong that I am just not seeing.
Thanks for the help