Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment