field

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinCols Define the min number of cols allowed on the field division by the Map
	MinCols int = 4
	// MinRows Define the min number of rows allowed on the field division by the Map
	MinRows int = 2
	// MaxCols Define the max number of cols allowed on the field division by the Map
	MaxCols int = 200
	// MaxRows Define the max number of rows allowed on the field division by the Map
	MaxRows int = 100
)

Variables

View Source
var (
	// ErrMinCols defines an error for invalid number of cols
	ErrMinCols = errors.New("number of cols lower the minimum")
	// ErrMaxCols defines an error for invalid number of cols
	ErrMaxCols = errors.New("number of cols higher the maximum")
	// ErrMinRows defines an error for invalid number of rows
	ErrMinRows = errors.New("number of rows lower the minimum")
	// ErrMaxRows defines an error for invalid number of rows
	ErrMaxRows = errors.New("number of rows higher the maximum")
)
View Source
var (
	North = Orientation(proto.North())
	South = Orientation(proto.South())
	East  = Orientation(proto.East())
	West  = Orientation(proto.West())

	NorthEast = Orientation(proto.NorthEast())
	SouthEast = Orientation(proto.SouthEast())
	NorthWest = Orientation(proto.NorthWest())
	SouthWest = Orientation(proto.SouthWest())
)

Functions

func FieldCenter

func FieldCenter() proto.Point

Types

type Direction

type Direction string
const (
	Forward       Direction = "forward"
	Backward      Direction = "backward"
	Left          Direction = "left"
	Right         Direction = "right"
	BackwardLeft  Direction = "backward_left"
	BackwardRight Direction = "backward_right"
	ForwardLeft   Direction = "forward_left"
	ForwardRight  Direction = "forward_right"
)

type Goal

type Goal struct {
	// Center the is coordinate of the center of the goal
	Center proto.Point
	// Place identifies the team of this goal (the team that should defend this goal)
	Place proto.Team_Side
	// TopPole is the coordinates of the pole with a higher Y coordinate
	TopPole proto.Point
	// BottomPole is the coordinates of the pole  with a lower Y coordinate
	BottomPole proto.Point
}

Goal is a set of value about a goal from a team

func AwaySideTeamGoal

func AwaySideTeamGoal() Goal

func GetGoal

func GetGoal(side proto.Team_Side) Goal

func HomeSideTeamGoal

func HomeSideTeamGoal() Goal

type Map

type Map struct {
	TeamSide proto.Team_Side
	// contains filtered or unexported fields
}

func NewMapper

func NewMapper(cols, rows int, sideRef proto.Team_Side) (*Map, error)

NewMapper creates a new Mapper that will map the field to provide Regions

func (*Map) GetAttackGoal

func (m *Map) GetAttackGoal() Goal

func (*Map) GetDefenseGoal

func (m *Map) GetDefenseGoal() Goal

func (*Map) GetMyTeamSide

func (m *Map) GetMyTeamSide() proto.Team_Side

func (*Map) GetOpponentSide

func (m *Map) GetOpponentSide() proto.Team_Side

func (*Map) GetPointRegion

func (m *Map) GetPointRegion(point *proto.Point) (Region, error)

func (*Map) GetRegion

func (m *Map) GetRegion(col, row int) (Region, error)

type MapArea

type MapArea struct {
	// contains filtered or unexported fields
}

func (MapArea) Back

func (r MapArea) Back() Region

func (MapArea) Center

func (r MapArea) Center() *proto.Point

func (MapArea) Col

func (r MapArea) Col() int

func (MapArea) Eq

func (r MapArea) Eq(region Region) bool

func (MapArea) Front

func (r MapArea) Front() Region

func (MapArea) Left

func (r MapArea) Left() Region

func (MapArea) Right

func (r MapArea) Right() Region

func (MapArea) Row

func (r MapArea) Row() int

func (MapArea) String

func (r MapArea) String() string

type Mapper

type Mapper interface {
	// GetRegion Returns a MapArea based on the coordinates and on the current field division
	GetRegion(col, row int) (Region, error)
	// GetPointRegion returns the MapArea where that point is in
	GetPointRegion(point *proto.Point) (Region, error)

	GetDefenseGoal() Goal
	GetAttackGoal() Goal

	GetMyTeamSide() proto.Team_Side
	GetOpponentSide() proto.Team_Side
}

Mapper Helps the bots to see the fields from their team perspective instead of using the cartesian plan provided by the game server. Instead of base your logic on the axes X and Y, the Map create a MapArea map based on the team side. The MapArea coordinates uses the defensive field's right corner as its origin. This mechanism if specially useful to define players regions based on their roles, since you do not have to mirror the coordinate, neither do extra logic to define regions on the field where the player should be.

type Orientation

type Orientation proto.Vector

type Region

type Region interface {
	fmt.Stringer
	// Col The col coordinate based on the field division
	Col() int
	// Row The row coordinate based on the field division
	Row() int
	// Center Return the point at the center of the quadrant represented by this Region. It is not always precise.
	Center() *proto.Point

	// Front is the MapArea immediately in front of this one from the player perspective
	// Important: The same MapArea is returned if the requested MapArea is not valid
	Front() Region
	// Back is the MapArea immediately behind this one from the player perspective
	// Important: The same MapArea is returned if the requested MapArea is not valid
	Back() Region
	// Left is the MapArea immediately on left of this one from the player perspective
	// Important: The same MapArea is returned if the requested MapArea is not valid
	Left() Region
	// Right is the MapArea immediately on right of this one from the player perspective
	// Important: The same MapArea is returned if the requested MapArea is not valid
	Right() Region

	// Eq does not check if the passed region is on a map of same size!
	Eq(region Region) bool
}

Region represent a quadrant on the field. It is not always squared form because you may define how many cols/rows the field will be divided in. So, based on that division (e.g. 4 rows, 6 cols) there will be a fixed number of regions and their coordinates will be zero-index (e.g. from 0 to 3 rows when divided in 4 rows).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL