Skip to content

Instantly share code, notes, and snippets.

@passingloop
Created September 26, 2011 03:55
Show Gist options
  • Save passingloop/1241581 to your computer and use it in GitHub Desktop.
Save passingloop/1241581 to your computer and use it in GitHub Desktop.
7l7w scala day1
class Board(board: List[Char]) {
val lines = List(
(0, 1, 2), (3, 4, 5), (6, 7, 8),
(0, 3, 6), (1, 4, 7), (2, 5, 8),
(0, 4, 8), (2, 4, 6)
)
var winner = ' '
def showWinner {
check
println(winner)
}
def check {
for(i <- 0 until lines.length) {
var piece = board(lines(i)._1)
if (piece != ' ' && piece == board(lines(i)._2) && piece == board(lines(i)._3)) {
winner = piece
return
}
}
}
}
val board = new Board(List('O', ' ', ' ', ' ', 'O', ' ', 'X', 'X', 'O'))
board.showWinner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment