I have the following snippet of Scala code, part of a larger source file with more classes, which comprises of private field, method and public method:
class Grid {
private val cells = Vector(
Vector(new Cell, new Cell, new Cell),
Vector(new Cell, new Cell, new Cell),
Vector(new Cell, new Cell, new Cell)
)
private def tranpose(grid:Vector[Vector[Cell]]) : Vector[Vector[Cell]] = {
val newgrid = Vector(
Vector(grid(0)(0), grid(1)(0), grid(2)(0)),
Vector(grid(0)(1), grid(1)(1), grid(2)(1)),
Vector(grid(0)(2), grid(1)(2), grid(2)(2))
)
newgrid
}
// Determine winner or draw
def wins(symbol:Char):Boolean = {
val fullvec = Vector(symbol, symbol, symbol)
for(r<-cells)
if(r.equals(fullvec))
true
// Transpose the grid into a new one and make the same check again
val transpgrid = transpose(cells)
for(r<-transpgrid)
if(r.equals(fullvec))
true
// Now check diagonals
val maindiag = Vector(cells(0)(0), cells(1)(1), cells(2)(2))
val seconddiag = Vector(cells(0)(2), cells(1)(1), cells(2)(0))
if(maindiag.equals(fullvec) || seconddiag.equals(fullvec))
true
false
}
In the line of code val transpgrid = transpose(cells)
inside the wins
method, scala
gives me the following message:
jasonfil@hp ~/AtomicScala/examples $ scala TicTacToe.scala
TicTacToe.scala:69: error: not found: value transpose
val transpgrid = transpose(cells)
I have tried adding the keyword this
in front of the call to transpose
, yet I have had no luck. I'm new to the language and presume I'm making some kind of mistake at call-time.
// Edit: I have since flagged this post for moderator approval and deletion, since it's obvious that I wasn't paying enough attention in creating the minimal example (obvious typo). However, I have since realized that another thing wrong with this code of mine is the liberal non-use of the "return" keyword from areas of the code that are clearly not the last line of their respective methods. This caused me a lot of heartache yesterday, yet I learnt from said heartache.
You have a spelling error - private def tranpose
should be private def transpose