Documentation
¶
Overview ¶
Package algor provides multiple algorithm that implements algor interface
Index ¶
Constants ¶
View Source
const ( UP = "u" DOWN = "d" LEFT = "l" RIGHT = "r" )
Keyboard input keys for algor.NoAlgor
Variables ¶
View Source
var ( NoFunc = func(s *state.State) *int { return nil } //GH1 sums up the cost to s and the manhattan distance from all unsolved boxes //to the nearest unsolved goal. GH1 = func(s *state.State) *int { unsolvedBoxes := make([][2]int, 0) unsolvedGoals := make([][2]int, 0) for i, a := range s.Tiles { for j, v := range a { if v == state.BOX { unsolvedBoxes = append(unsolvedBoxes, [2]int{i, j}) } if v == state.GOAL { unsolvedGoals = append(unsolvedGoals, [2]int{i, j}) } } } heuristic := 0 for _, g := range unsolvedGoals { minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(g, b)))) } heuristic += minDist } heuristicNCost := heuristic + s.Moves return &heuristicNCost } //GH2 sums up the cost to s, the manhattan distance from all unsolved boxes //to the nearest unsolved goal, and the manhattan distance from the player to //the nearest unsolved box. GH2 = func(s *state.State) *int { unsolvedBoxes := make([][2]int, 0) unsolvedGoals := make([][2]int, 0) for i, a := range s.Tiles { for j, v := range a { if v == state.BOX { unsolvedBoxes = append(unsolvedBoxes, [2]int{i, j}) } if v == state.GOAL { unsolvedGoals = append(unsolvedGoals, [2]int{i, j}) } } } heuristic := 0 for _, g := range unsolvedGoals { minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(g, b)))) } heuristic += minDist } player := s.Pos() minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(player, b)))) } heuristic += minDist heuristicNCost := heuristic + s.Moves return &heuristicNCost } //H1 sums up the manhattan distance from all unsolved boxes //to the nearest unsolved goal. H1 = func(s *state.State) *int { unsolvedBoxes := make([][2]int, 0) unsolvedGoals := make([][2]int, 0) for i, a := range s.Tiles { for j, v := range a { if v == state.BOX { unsolvedBoxes = append(unsolvedBoxes, [2]int{i, j}) } if v == state.GOAL { unsolvedGoals = append(unsolvedGoals, [2]int{i, j}) } } } heuristic := 0 for _, g := range unsolvedGoals { minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(g, b)))) } heuristic += minDist } return &heuristic } //H2 sums up the manhattan distance from all unsolved boxes //to the nearest unsolved goal, and the manhattan distance from the player to //the nearest unsolved box. H2 = func(s *state.State) *int { unsolvedBoxes := make([][2]int, 0) unsolvedGoals := make([][2]int, 0) for i, a := range s.Tiles { for j, v := range a { if v == state.BOX { unsolvedBoxes = append(unsolvedBoxes, [2]int{i, j}) } if v == state.GOAL { unsolvedGoals = append(unsolvedGoals, [2]int{i, j}) } } } heuristic := 0 for _, g := range unsolvedGoals { minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(g, b)))) } heuristic += minDist } player := s.Pos() minDist := math.MaxInt for _, b := range unsolvedBoxes { minDist = int(math.Min(float64(minDist), float64(manhattanDist(player, b)))) } heuristic += minDist return &heuristic } )
Cost functions.
On screen prompt when using algor.NoAlgor
Functions ¶
This section is empty.
Types ¶
type AStar ¶
type AStar struct {
// contains filtered or unexported fields
}
AStart implements a heuristic-agnostic A* algorithm.
type Algor ¶
Algor is an interface for sokoban solving algorithms Search method is the core of the interface, it takes the start state as start and returns the final state. Steps returns the number of steps the algorithms had to take to get to the returned state.
type Bfs ¶
type Bfs struct {
// contains filtered or unexported fields
}
Bfs implements BFS algorithm.
type Dfs ¶
type Dfs struct {
// contains filtered or unexported fields
}
Dfs implements the DFS algorithm.
type HillClimbing ¶
type HillClimbing struct {
// contains filtered or unexported fields
}
HillClimbing implements itself.
func (*HillClimbing) Steps ¶
func (hc *HillClimbing) Steps() int
Click to show internal directories.
Click to hide internal directories.