Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Board(board: List[Char]) {
  2. val lines = List(
  3. (0, 1, 2), (3, 4, 5), (6, 7, 8),
  4. (0, 3, 6), (1, 4, 7), (2, 5, 8),
  5. (0, 4, 8), (2, 4, 6)
  6. )
  7.  
  8. var winner = ' '
  9.  
  10. def showWinner {
  11. check
  12. println(winner)
  13. }
  14.  
  15. def check {
  16. for(i <- 0 until lines.length) {
  17. var piece = board(lines(i)._1)
  18. if (piece != ' ' && piece == board(lines(i)._2) && piece == board(lines(i)._3)) {
  19. winner = piece
  20. return
  21. }
  22. }
  23. }
  24. }
  25.  
  26. val board = new Board(List('O', ' ', ' ', ' ', 'O', ' ', 'X', 'X', 'O'))
  27. board.showWinner
Add Comment
Please, Sign In to add comment