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