Skip to content

Instantly share code, notes, and snippets.

@tedwards
Created August 31, 2014 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedwards/381c3f44d2a48f38e8e8 to your computer and use it in GitHub Desktop.
Save tedwards/381c3f44d2a48f38e8e8 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/matburt/vindinium-go-engine"
"fmt"
)
var (
client vindinium.Client
)
type MatBot struct {}
func (m MatBot) Move(state *vindinium.State) vindinium.Direction {
game := vindinium.NewGame(state)
distance := 100000
goal := vindinium.Position{0,0}
//Go to the bar if we are getting thirsty
if state.Hero.Life <= 20 {
for tavern := range game.TavernsLocs {
if itemDistance := game.Board.ManhattanDistance(*state.Hero.Pos, tavern); itemDistance < distance {
distance = itemDistance
goal = tavern
}
}
} else { //Lets go get some gold!!
for mine := range game.MinesLocs {
if itemDistance := game.Board.ManhattanDistance(*state.Hero.Pos, mine); itemDistance < distance {
distance = itemDistance
goal = mine
}
}
}
pathSet, e := game.Board.ShortestPath(*state.Hero.Pos, goal)
if e != nil {
// Stay put if we can't find a way
return game.Board.GetDirection(*state.Hero.Pos, *state.Hero.Pos)
}
// Take the first step of the path
p, _ := pathSet.Pop()
return game.Board.GetDirection(*state.Hero.Pos, p)
}
func main() {
b := MatBot{}
c := vindinium.NewTrainingClient("bk7nu9em", "100", true, false, true, b)
c.Start()
c.Play()
fmt.Println("Game Finished")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment