Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns path in wrong direction #6

Open
avivey opened this issue Feb 27, 2021 · 1 comment
Open

Returns path in wrong direction #6

avivey opened this issue Feb 27, 2021 · 1 comment

Comments

@avivey
Copy link

avivey commented Feb 27, 2021

While defined as func Path(from, to Pather) ..., the resulting path actually starts at to node and ends at from.

This can be seen using this patch to pather_test.go:

diff --git pather_test.go pather_test.go
index b9d78bd..331ee0d 100644
--- pather_test.go
+++ pather_test.go
@@ -159,18 +159,19 @@ func (w World) RenderPath(path []Pather) string {
                return ""
        }
        height := len(w[0])
-       pathLocs := map[string]bool{}
-       for _, p := range path {
+       pathLocs := map[string]rune{}
+       for i, p := range path {
                pT := p.(*Tile)
-               pathLocs[fmt.Sprintf("%d,%d", pT.X, pT.Y)] = true
+               nr := []rune("0123456789abc")[i%12] // "clever" rendering of node index in path.
+               pathLocs[fmt.Sprintf("%d,%d", pT.X, pT.Y)] = nr
        }
        rows := make([]string, height)
        for x := 0; x < width; x++ {
                for y := 0; y < height; y++ {
                        t := w.Tile(x, y)
                        r := ' '
-                       if pathLocs[fmt.Sprintf("%d,%d", x, y)] {
-                               r = KindRunes[KindPath]
+                       if nr := pathLocs[fmt.Sprintf("%d,%d", x, y)]; nr != 0 {
+                               r = nr
                        } else if t != nil {
                                r = KindRunes[t.Kind]
                        }

which renders 0 on T and 9 on F:

=== RUN   TestStraightLine
    path_test.go:14: Input world
        .....~......
        .....MM.....
        .F........T.
        ....MMM.....
        ............
    path_test.go:19: Resulting path
        .....~......
        .....MM.....
        .9876543210.
        ....MMM.....
        ............
--- PASS: TestStraightLine (0.01s)
@beefsack
Copy link
Owner

Hi @avivey, thanks for the issue and the investigation. This could potentially be a breaking change for users, so will have to be fixed in a major version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants