⚙️ method Game.NearestObject(...)

Last updated:4/16/2026

URL

https://github.com/42core-team/monorepo/blob/dev/bots/go/client_lib/game/game.go

Description

Get the nearest object to a given position matching a custom filtering predicate.

Manhattan distance is used to determine distance. If two objects or more have the same distance, either could be picked.

Signature

func (g *Game) NearestObject(fromPos Position, predicate func(*Object) bool) *Object

Parameters

  • fromPos Position: Position to search from
  • predicate func(*Object) bool: Function returning true if the object should be considered

Return

  • *Object: The nearest object that matches the predicate or nil if no such object exists.

Examples

isDeposit := func(obj *game.Object) bool {
	return obj.Type == game.ObjectDeposit
}
nearestDeposit := g.NearestObject(miner.Pos, isDeposit)