Megrez v1.0.8 // Disable score-balancing by default.

This commit is contained in:
ShikiSuen 2022-05-12 12:18:48 +08:00
parent 69b8c36186
commit a747a51afc
1 changed files with 16 additions and 8 deletions

View File

@ -31,9 +31,12 @@ extension Megrez {
mutGrid = grid mutGrid = grid
} }
public func reverseWalk(at location: Int, score accumulatedScore: Double = 0.0, nodesLimit: Int = 0) public func reverseWalk(
-> [NodeAnchor] at location: Int,
{ score accumulatedScore: Double = 0.0,
nodesLimit: Int = 0,
balanced: Bool = false
) -> [NodeAnchor] {
if location == 0 || location > mutGrid.width() { if location == 0 || location > mutGrid.width() {
return [] as [NodeAnchor] return [] as [NodeAnchor]
} }
@ -41,8 +44,10 @@ extension Megrez {
var paths: [[NodeAnchor]] = [] var paths: [[NodeAnchor]] = []
var nodes: [NodeAnchor] = mutGrid.nodesEndingAt(location: location) var nodes: [NodeAnchor] = mutGrid.nodesEndingAt(location: location)
nodes.sort { if balanced {
$0.balancedScore > $1.balancedScore // NodeAnchor nodes.sort {
$0.balancedScore > $1.balancedScore // NodeAnchor
}
} }
// X NodeAnchor node // X NodeAnchor node
@ -58,10 +63,13 @@ extension Megrez {
continue continue
} }
n.accumulatedScore = accumulatedScore + nNode.score()
// Spanning Length // Spanning Length
// //
let weightedScore: Double = (Double(n.spanningLength) - 1) * 2 if balanced {
n.accumulatedScore = accumulatedScore + nNode.score() + weightedScore let weightedScore: Double = (Double(n.spanningLength) - 1) * 2
n.accumulatedScore += weightedScore
}
var path: [NodeAnchor] = reverseWalk( var path: [NodeAnchor] = reverseWalk(
at: location - n.spanningLength, at: location - n.spanningLength,
@ -72,7 +80,7 @@ extension Megrez {
paths.append(path) paths.append(path)
// 使 // 使
if nNode.score() >= 0 { if balanced, nNode.score() >= 0 {
break break
} }
} }