func (a *naiveAnt) Decide(env *antwar.Tile, brains []antwar.AntBrain) (decision antwar.Action, bringFood bool) { if env.FoodCount() > 0 { decision = a.directionHome() } else if env.North().FoodCount() > 0 { decision = antwar.NORTH } else if env.East().FoodCount() > 0 { decision = antwar.EAST } else if env.South().FoodCount() > 0 { decision = antwar.SOUTH } else if env.West().FoodCount() > 0 { decision = antwar.WEST } else { decision = a.directionOut() } a.update(decision) bringFood = env.FoodCount() > 0 return }
func extraFood(t *antwar.Tile) int { return t.FoodCount() - t.AntCount() }
func (me *ghengis) Decide(env *antwar.Tile, brains []antwar.AntBrain) (decision antwar.Action, bringFood bool) { tilePositions := me.tilePositions(env) bringFood = false if len(brains) > 0 { for _, brain := range brains { other, ok := brain.(*ghengis) if !ok { panic("Not a ghengis") } // Find the shortest way home if other.distanceHome() < me.distanceHome() { me.pos = other.pos } if me.destination == other.destination { if me.turnsSinceUpdate > other.turnsSinceUpdate { me.foodAtDestination = other.foodAtDestination me.turnsSinceUpdate = other.turnsSinceUpdate } else if me.turnsSinceUpdate < other.turnsSinceUpdate { other.foodAtDestination = me.foodAtDestination other.turnsSinceUpdate = me.turnsSinceUpdate } } if me.foodAtDestination == 0 && other.foodAtDestination > 0 { me.destination = other.destination me.foodAtDestination = other.foodAtDestination other.foodAtDestination-- } /*if me.foodAtDestination > 0 && me.distanceToDestinationAndHome() > other.distanceToDestinationAndHome() { me.destination = other.destination }*/ } } for tile, tilePos := range tilePositions { if moreFoodThanAnts(tile) { me.foodAtDestination = extraFood(tile) me.turnsSinceUpdate = 0 me.destination = tilePos } } if env.FoodCount() > 0 { bringFood = true decision = me.directionHome() } else { decision = me.directionToDestination() if decision == antwar.HERE { me.setRandomDestination() me.foodAtDestination = 0 me.turnsSinceUpdate = 1000 decision = me.directionToDestination() } } me.updatePosition(decision) if me.turnsSinceUpdate < 1000 { me.turnsSinceUpdate++ } return }
func moreFoodThanAnts(tile *antwar.Tile) bool { return tile.FoodCount() > tile.AntCount() // && tile.Team() != "ghengis" }