本文整理匯總了Golang中github.com/edgarweto/puzzlopia/puzzle-solvers/finder.SbpBfsFinder.GetResult方法的典型用法代碼示例。如果您正苦於以下問題:Golang SbpBfsFinder.GetResult方法的具體用法?Golang SbpBfsFinder.GetResult怎麽用?Golang SbpBfsFinder.GetResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/edgarweto/puzzlopia/puzzle-solvers/finder.SbpBfsFinder
的用法示例。
在下文中一共展示了SbpBfsFinder.GetResult方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CheckChrisEye
// Result: 52
// Should be: 52
func CheckChrisEye() {
// Define the game
var myPuzzle = &games.SBGame{}
// SuperCompo
myPuzzle.Define(&grids.Matrix2d{
[]int{0, 2, 2, 0},
[]int{3, 7, 8, 4},
[]int{3, 1, 1, 4},
[]int{9, 1, 1, 10},
[]int{5, 5, 6, 6},
})
myPuzzle.AutoAlikePieces()
// Check the puzzle is well created, and let it build its internals
myPuzzle.Build()
// Params for finder/solver
const (
// Max depth reached by finder/solver
MAX_DEPTH = 200
// Max number of states to be processed. If 0, then ignored.
// Can be combined with MAX_DEPTH: if either of these two values is exceeded, the algorithm stops.
//MAX_STATES = 4525252
MAX_STATES = 250000
// (Experimental),Used internally to force the algorithm to revisit some states
// Actually, disabling it makes Pennant to be solved with non-optimal path.
HARD_OPTIMAL = true
// Used for tests: enables/disables console output
SILENT_MODE = false
// Enables/disables debug options (console output, etc.)
DEBUG = false
)
// FINDER ---------------------
var sbpFinder finder.SbpBfsFinder
sbpFinder.SilentMode(SILENT_MODE)
sbpFinder.SetDebug(DEBUG)
sbpFinder.SetLimits(MAX_DEPTH, MAX_STATES)
sbpFinder.SetHardOptimal(HARD_OPTIMAL)
// Objective
sbpFinder.Detect(&grids.Matrix2d{
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{0, 1, 1, 0},
[]int{0, 1, 1, 0},
})
sbpFinder.SolvePuzzle(myPuzzle)
found, solutionLen, _ := sbpFinder.GetResult()
if !found {
fmt.Println("Chris-Eye not solved!")
}
if solutionLen != 52 {
fmt.Printf("Chris-Eye solution not optimal: found len = %d\n\n", solutionLen)
}
}
示例2: CheckRedditQuest4hj6nb
// Result: 123
// Should be:
func CheckRedditQuest4hj6nb() {
// Define the game
var myPuzzle = &games.SBGame{}
// From reddit https://www.reddit.com/r/puzzles/comments/4hj6nb/has_anyone_any_info_on_this_sliding_tile_puzzle/
myPuzzle.Define(&grids.Matrix2d{
[]int{0, 1, 1, 0},
[]int{2, 1, 1, 4},
[]int{2, 7, 9, 4},
[]int{3, 8, 10, 5},
[]int{3, 6, 6, 5},
})
myPuzzle.AutoAlikePieces()
// Check the puzzle is well created, and let it build its internals
myPuzzle.Build()
// Params for finder/solver
const (
// Max depth reached by finder/solver
MAX_DEPTH = 200
// Max number of states to be processed. If 0, then ignored.
// Can be combined with MAX_DEPTH: if either of these two values is exceeded, the algorithm stops.
//MAX_STATES = 4999999
MAX_STATES = 1999999
// (Experimental),Used internally to force the algorithm to revisit some states
// Actually, disabling it makes Pennant to be solved with non-optimal path.
HARD_OPTIMAL = true
// Used for tests: enables/disables console output
SILENT_MODE = false
// Enables/disables debug options (console output, etc.)
DEBUG = false
)
// FINDER ---------------------
var sbpFinder finder.SbpBfsFinder
sbpFinder.SilentMode(SILENT_MODE)
sbpFinder.SetDebug(DEBUG)
sbpFinder.SetLimits(MAX_DEPTH, MAX_STATES)
sbpFinder.SetHardOptimal(HARD_OPTIMAL)
// // BrokenPennant
sbpFinder.Detect(&grids.Matrix2d{
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{0, 1, 1, 0},
[]int{0, 1, 1, 0},
})
sbpFinder.SolvePuzzle(myPuzzle)
found, solutionLen, _ := sbpFinder.GetResult()
if !found {
fmt.Println("P_4hj6nb not solved!")
}
if solutionLen != 123 {
fmt.Printf("P_4hj6nb solution not optimal: found len = %d\n\n", solutionLen)
}
}
示例3: TestEquivalence
func TestEquivalence(t *testing.T) {
var myPuzzle = &games.SBGame{}
// Pennant
myPuzzle.Define(&grids.Matrix2d{
[]int{2, 2, 1, 1},
[]int{2, 2, 3, 3},
[]int{5, 4, 0, 0},
[]int{6, 7, 8, 8},
[]int{6, 7, 9, 9},
})
myPuzzle.AutoAlikePieces()
//myPuzzle.SetNotAlikePiece(5)
// Check the puzzle is well created, and let it build its internals
myPuzzle.Build()
const (
// Max depth reached by finder/solver
MAX_DEPTH = 83
// Max number of states to be processed. If 0, then ignored.
// Can be combined with MAX_DEPTH: if either of these two values is exceeded, the algorithm stops.
MAX_STATES = 0
// (Experimental) Used internally to force the algorithm to revisit some states
// Actually, disabling it makes Pennant to be solved with non-optimal path.
HARD_OPTIMAL = true
// Used for tests: enables/disables console output
SILENT_MODE = true
// Enables/disables debug options (console output, etc.)
DEBUG = false
)
// FINDER ---------------------
var sbpFinder finder.SbpBfsFinder
sbpFinder.SilentMode(SILENT_MODE)
sbpFinder.SetDebug(DEBUG)
sbpFinder.SetLimits(MAX_DEPTH, MAX_STATES)
sbpFinder.SetHardOptimal(HARD_OPTIMAL)
// Pennant
sbpFinder.Detect(&grids.Matrix2d{
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{0, 0, 0, 0},
[]int{2, 2, 0, 0},
[]int{2, 2, 0, 0},
})
sbpFinder.SolvePuzzle(myPuzzle)
found, solutionLen, duration := sbpFinder.GetResult()
if !found {
t.Errorf("Pennant not solved!")
}
if solutionLen != 59 {
t.Errorf("Pennant solution not optimal: found len = %d", solutionLen)
}
if duration.Seconds() > 0.1 {
t.Errorf("Should solve in less than 0.1 seconds. Current: %v", duration)
}
}