Пример #1
0
func (d *Dijkstra) FindBestRoute(dungeon dungeon.Dungeon) (int, []string, error) {
	finder := dijkstra.NewRouteFinder(dungeon)
	maxX := len(dungeon.Rooms[0]) - 1
	maxY := len(dungeon.Rooms) - 1
	return finder.FindRoute(0, 0, maxX, maxY)
}
Пример #2
0
)

var _ = Describe("RouteFinder", func() {
	var dungeonMap dungeon.Dungeon
	var finder *dijkstra.RouteFinder

	BeforeEach(func() {
		dungeonMap = dungeon.Dungeon{
			Rooms: [][]int{
				[]int{1, 2, -5, -4},
				[]int{-5, -6, -7, 9},
				[]int{9, 10, 11, 12},
			},
		}

		finder = dijkstra.NewRouteFinder(dungeonMap)
	})

	Describe("#FindBestRoute", func() {
		Context("from 0,0 to 3,2", func() {
			It("returns the optimal path", func() {
				_, path, err := finder.FindRoute(0, 0, 3, 2)
				Expect(err).ToNot(HaveOccurred())
				Expect(path).To(Equal([]string{"RIGHT", "DOWN", "DOWN", "RIGHT", "RIGHT"}))
			})

			It("returns the correct minDamange for the path", func() {
				minDamange, _, err := finder.FindRoute(0, 0, 3, 2)
				Expect(err).ToNot(HaveOccurred())
				Expect(minDamange).To(Equal(-3))
			})