-
Notifications
You must be signed in to change notification settings - Fork 10
/
copying_from_others.txt
42 lines (31 loc) · 1.41 KB
/
copying_from_others.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Notable improvement: Use int instead of {'x':x, 'y':y} for positions
// Notable improvement: If there are no negation symbols, edges between stones of the same color are forced.
// This can be pre-computed, as well -- so each validate() call can share the info.
findSolution(path, visited, required, edgeRequired, exitsRemaining, areas, segment)
step 1:
determineAuxilaryRequired(); // Determine lines which are required (owing to adjest stones of the same color)
required = getNodesByType(NODE_TYPE.REQUIRED)
edgeRequired = getEdgesByType(EDGE_TYPE.REQUIRED)
exitsRemaining = getNodesByType(NODE_TYPE.EXIT).length;
for each start point:
findSolution(path = [{x, y}], visited = [{x, y}], ...)
if (solution) return solution
return null
current_node = path.tail()
prev_node = path.tail() - 1
[areas, segment] = separateAreasStep() // *interesting*
if (!areas) // somehow determined that an area we're including is wrong.
if current_node.end == true:
if (!checkLastArea(previous_node, current_node, areas, segment)) // *interesting*
exitsRemaining--
else if (!checkRequiredNodes(path, required))
exitsRemaining--
else if (!checkRequiredEdges(path, edgeRequired))
exitsRemaining--
else
return path // success
if (exitsRemaining == 0) return false;
for next_node in [left, up, down, right]:
recurse
checkLastArea(previous_node, current_node, areas, segment) {
if previous_node is on an edge: