• API
• FAQ
• Tools
• Archive
SHARE
TWEET Untitled a guest Sep 10th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def getSquaresWithNeighbors(board:Board):List[Square] = {
2.     (for(square <- squares if square.neighbors.nonEmpty) yield square)
3.         .sortWith((s1, s2) => s1.x < s2.x)
4.         .sortWith((s1, s2) => s1.y < s2.y)
5.   }
6.
7.   def getPossibleNeighborValues(square:Square):List[Int] = {
8.     var possible_neighbor_values: List[Int] = List[Int]()
9.
10.     for (value <- square.values) {
11.       possible_neighbor_values :+= value + 1
12.       possible_neighbor_values :+= value - 1
13.     }
14.
15.     possible_neighbor_values.filter((x: Int) => x > 0 && x <= Puzzle.size).distinct
16.   }
17.
18.   def getImpossibleNeighborValues(square:Square, neighbor:Square):List[Int] = {
19.     val possible_neighbor_values:List[Int] = getPossibleNeighborValues(square)
20.     neighbor.values.diff(possible_neighbor_values)
21.   }
22.
23.   def resolveImpossibleNeighborValues(board:Board):Board = {
24.     var temp_board = board
25.     val squares_with_neighbors = getSquaresWithNeighbors(temp_board)
26.
27.     squares_with_neighbors.foreach((square:Square) => {
28.       val neighbors = getNeighbours(square)
29.
30.       neighbors.foreach((neighbor:Square) => {
31.         temp_board = temp_board.replaceSquare(
32.           neighbor.removeSolution(getImpossibleNeighborValues(square, neighbor))
33.         )
34.       })
35.     })
36.
37.     temp_board
38.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top