コード例 #1
0
ファイル: main.go プロジェクト: tscolari/dungeon_game
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, " -> "))

}
コード例 #2
0
ファイル: solver_test.go プロジェクト: tscolari/dungeon_game
	"github.com/tscolari/dungeon_game/solver"
	"github.com/tscolari/dungeon_game/solver/fakes"

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

var _ = Describe("Solver", func() {
	var strategy *fakes.FakeStrategy
	var dungeonMap dungeon.Dungeon
	var subject *solver.Solver

	BeforeEach(func() {
		dungeonMap = dungeon.Dungeon{}
		strategy = new(fakes.FakeStrategy)
		subject = solver.New(dungeonMap, strategy)
	})

	Describe("#Solve", func() {
		It("converts the strategy value to actually minHP points", func() {
			strategy.FindBestRouteReturns(-10, []string{}, nil)

			minHP, _, _ := subject.Solve()
			Expect(minHP).To(Equal(11))
		})

		It("forwards the error if the strategy returns one", func() {
			expectedError := errors.New("something bad happened")
			strategy.FindBestRouteReturns(0, []string{}, expectedError)

			_, _, err := subject.Solve()