2023-08-03 21:07:58 +02:00
|
|
|
package maze
|
|
|
|
|
2023-08-09 17:44:59 +02:00
|
|
|
import "math"
|
|
|
|
|
2023-08-04 19:11:26 +02:00
|
|
|
type Coordinates struct {
|
|
|
|
X, Y int
|
|
|
|
}
|
2023-08-09 17:44:59 +02:00
|
|
|
|
|
|
|
func (c Coordinates) Distance(o Coordinates) float64 {
|
|
|
|
x, y := float64(o.X-c.X), float64(o.Y-c.Y)
|
|
|
|
|
|
|
|
if y == 0 {
|
|
|
|
if x < 0 {
|
|
|
|
return -x
|
|
|
|
}
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == 0 {
|
|
|
|
if y < 0 {
|
|
|
|
return -y
|
|
|
|
}
|
|
|
|
return y
|
|
|
|
}
|
|
|
|
|
|
|
|
return math.Sqrt(x*x + y*y)
|
|
|
|
}
|
|
|
|
|
2023-08-04 19:11:26 +02:00
|
|
|
type Node struct {
|
|
|
|
Coords Coordinates
|
|
|
|
Up, Down *Node
|
|
|
|
Left, Right *Node
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewNode(coords Coordinates) *Node {
|
|
|
|
return &Node{
|
|
|
|
Coords: coords,
|
|
|
|
Up: nil,
|
|
|
|
Down: nil,
|
|
|
|
Left: nil,
|
|
|
|
Right: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Maze struct {
|
2023-08-07 18:22:04 +02:00
|
|
|
Width, Height int
|
2023-08-04 19:11:26 +02:00
|
|
|
Nodes []*Node
|
2023-08-03 21:07:58 +02:00
|
|
|
}
|
|
|
|
|
2023-08-04 19:11:26 +02:00
|
|
|
type SolvedMaze struct {
|
2023-08-03 21:07:58 +02:00
|
|
|
Maze
|
2023-08-04 19:11:26 +02:00
|
|
|
Solution []*Node
|
2023-08-03 21:07:58 +02:00
|
|
|
}
|