Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Board
  2. def initialize(size)
  3. @size = size
  4. @board = Array.new(@size, Array.new(@size))
  5. @state = nil
  6. end
  7. def put(x, y, color)
  8. @board[x][y] = color
  9. [[1,1],[1,0],[1,-1],[0,1]].each do |dir|
  10. pomx, pomy, counter = x+dir[0], y+dir[1], 1
  11. while @board[pomx][pomy] == color
  12. counter += 1
  13. pomx += dir[0]
  14. pomy += dir[1]
  15. end
  16. pomx, pomy = x-dir[0], y-dir[1]
  17. while @board[pomx][pomy] == color
  18. counter += 1
  19. pomx -= dir[0]
  20. pomy -= dir[1]
  21. end
  22. if counter == 5
  23. return color
  24. else
  25. return nil
  26. end
  27. end
  28. end
  29. def state
  30. @state
  31. end
  32. end
Add Comment
Please, Sign In to add comment