Beispiel #1
0
func main() {
	var dungeonMapName = flag.String("dungeon", "", "Dungeon map file")
	flag.Parse()

	if *dungeonMapName == "" {
		flag.Usage()
		os.Exit(1)
	}

	dungeonMap, err := dungeon.Load(*dungeonMapName)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	strategy := strategy.Dijkstra{}
	solver := solver.New(dungeonMap, &strategy)
	minHP, bestRoute, err := solver.Solve()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Printf("MIN HP: %d\n", minHP)
	fmt.Printf("BEST ROUTE: %s\n", strings.Join(bestRoute, " -> "))

}
Beispiel #2
0
package dungeon_test

import (
	"github.com/tscolari/dungeon_game/dungeon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Load", func() {
	Context("when there's an error opening the file", func() {
		It("returns an error", func() {
			_, err := dungeon.Load("/tmp/this_file_doesnt_exist")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(MatchRegexp("Failed to open dungeon file"))
		})
	})

	Context("when the file is not in the correct format", func() {

		Context("when the room rows have different dimensions", func() {
			dungeonFileName := "./fixtures/invalid_dungeon-wrong_dimensions.yml"

			It("returns an invalid file error", func() {
				_, err := dungeon.Load(dungeonFileName)
				Expect(err).To(MatchError("Invalid dungeon file: All rows must have the same size"))
			})
		})

		Context("when the file is not a valid yaml", func() {
			dungeonFileName := "./fixtures/invalid_dungeon-invalid_YAML.yml"