field

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: GPL-3.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// BaseUnit is used to increase the integer units scale and improve the precision when the integer numbers
	// come from float  calculations. Some units have to be integer to avoid infinite intervals (e.g. a point in the field)
	BaseUnit = 100

	// PlayerSize is the size of each player
	PlayerSize = 4 * BaseUnit

	// PlayerReconnectionWaitTime is a penalty time imposed to the player that needs to reconnect during the match.
	// this interval ensure players won't drop connection in purpose to be reallocated to their initial position.
	PlayerReconnectionWaitTime = 20 * time.Second

	// max number of players in a team by mach
	MaxPlayers = 11

	// min number of players in a team by mach, if a team gets to have less to this number, the team loses by W.O.
	MinPlayers = 6

	// PlayerMaxSpeed is the max speed that a play may move  by frame
	PlayerMaxSpeed = 100.0

	// MaxXCoordinate help us to remember that we should not use the field width to check the field boundaries!
	// The field dimensions counts the total number of coordinates, but the coordinates are zero-indexed.
	// e.g. If the field width is 10, so the max coordinate will be 9
	MaxXCoordinate = 200 * BaseUnit

	// MaxYCoordinate help us to remember that we should not use the field width to check the field boundaries!
	// The field dimensions counts the total number of coordinates, but the coordinates are zero-indexed.
	// e.g. If the field height is 10, so the max coordinate will be 9
	MaxYCoordinate = 100 * BaseUnit

	// FieldWidth is the width of the field (horizontal view)
	// This value must be an odd number because the central coordinate must be neutral, and we want to have the same number
	// of coordinates on both sides.
	// e.g. If the field width is 10, and the coordinates go from 0 to 9, there is no precise middle.
	// Thus, the field width would have to be 11, so the coordinate 5 is at the precise center
	FieldWidth = MaxXCoordinate + 1

	// FieldHeight is the height of the field (horizontal view)
	// This value must be an odd number because we cant to a coordinate at the perfect middle of the field
	// e.g. If the field height is 10, and the coordinates go from 0 to 9, there is no precise middle.
	// Thus, the field height would have to be 11, so the coordinate 5 is at the precise center
	FieldHeight = MaxYCoordinate + 1

	// FieldNeutralCenter is the radius of the neutral circle in the center of the field
	FieldNeutralCenter = 1000

	// BallSize size of the element ball
	BallSize = 2 * BaseUnit

	// BallDeceleration is the deceleration rate of the ball speed  by frame
	BallDeceleration = 10.0

	// BallMaxSpeed is the max speed of the ball by frame
	BallMaxSpeed = 4.0 * BaseUnit

	// BallMinSpeed is the minimal speed of the ball  by frame. When the ball was at this speed or slower, it will be considered stopped.
	BallMinSpeed = 2

	// BallTimeInGoalZone is the max number of turns that the ball may be in a goal zone. After that, the ball will be auto kicked
	// towards the center of the field.
	BallTimeInGoalZone = 40 // 40 / 20 fps = 2 seconds

	// GoalWidth is the goal width
	GoalWidth = 30 * BaseUnit

	// GoalMinY is the coordinate Y of the lower pole of the goals
	GoalMinY = (MaxYCoordinate - GoalWidth) / 2

	// GoalMaxY is the coordinate Y of the upper pole of the goals
	GoalMaxY = GoalMinY + GoalWidth

	// GoalZoneRange is the minimal distance that a player can stay from the opponent goal
	GoalZoneRange = 14 * BaseUnit

	// GoalKeeperJumpDuration is the number of turns that the jump takes. A jump cannot be interrupted after has been requested
	GoalKeeperJumpDuration = 3

	// GoalKeeperJumpSpeed is the max speed of the goalkeeper during the jump
	GoalKeeperJumpSpeed = 2 * PlayerMaxSpeed

	// GoalkeeperNumber defines the goalkeeper number
	GoalkeeperNumber = uint32(1)

	// Number of turns each teams has on attack before losing the ball possession.
	ShotClockTime = 300
)
View Source
const (
	// MinCols Define the min number of cols allowed on the field division by the Map
	MinCols uint = 4
	// MinRows Define the min number of rows allowed on the field division by the Map
	MinRows uint = 2
	// MaxCols Define the max number of cols allowed on the field division by the Map
	MaxCols uint = 200
	// MaxRows Define the max number of rows allowed on the field division by the Map
	MaxRows uint = 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")
)

Functions

func FieldCenter

func FieldCenter() proto.Point

FieldCenter works as a constant value to help to retrieve a Point struct with the values of the center of the court

func GetOpponentSide

func GetOpponentSide(side proto.Team_Side) proto.Team_Side

func GetPlayer

func GetPlayer(s *proto.GameSnapshot, side proto.Team_Side, number uint32) *proto.Player

func GetTeam

func GetTeam(s *proto.GameSnapshot, side proto.Team_Side) *proto.Team

func GoBackward

func GoBackward(side proto.Team_Side) *proto.Order_Move

func GoForward

func GoForward(side proto.Team_Side) *proto.Order_Move

func GoLeft

func GoLeft(side proto.Team_Side) *proto.Order_Move

func GoRight

func GoRight(side proto.Team_Side) *proto.Order_Move

func IsBallHolder

func IsBallHolder(s *proto.GameSnapshot, player *proto.Player) bool

func MakeOrderCatch

func MakeOrderCatch() *proto.Order_Catch

func MakeOrderJump

func MakeOrderJump(origin, target proto.Point, speed float64) (*proto.Order_Jump, error)

func MakeOrderKick

func MakeOrderKick(ball proto.Ball, target proto.Point, speed float64) (*proto.Order_Kick, error)

func MakeOrderKickMaxSpeed

func MakeOrderKickMaxSpeed(ball proto.Ball, target proto.Point) (*proto.Order_Kick, error)

func MakeOrderMove

func MakeOrderMove(origin, target proto.Point, speed float64) (*proto.Order_Move, error)

func MakeOrderMoveMaxSpeed

func MakeOrderMoveMaxSpeed(origin, target proto.Point) (*proto.Order_Move, error)

Types

type FieldArea

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

func (FieldArea) Back

func (r FieldArea) Back() Region

func (FieldArea) Center

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

func (FieldArea) Col

func (r FieldArea) Col() int

func (FieldArea) Eq

func (r FieldArea) Eq(region Region) bool

func (FieldArea) Front

func (r FieldArea) Front() Region

func (FieldArea) Left

func (r FieldArea) Left() Region

func (FieldArea) Right

func (r FieldArea) Right() Region

func (FieldArea) Row

func (r FieldArea) Row() int

func (FieldArea) String

func (r FieldArea) String() string

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 AwayTeamGoal

func AwayTeamGoal() Goal

AwayTeamGoal works as a constant value to help to retrieve a Goal struct with the values of the Away team goal

func GetOpponentGoal

func GetOpponentGoal(mySide proto.Team_Side) Goal

func GetTeamsGoal

func GetTeamsGoal(side proto.Team_Side) Goal

GetTeamsGoal returns the goal struct to the team side passed as argument

func HomeTeamGoal

func HomeTeamGoal() Goal

HomeTeamGoal works as a constant value to help to retrieve a Goal struct with the values of the Home team goal

type Map

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

func NewMapper

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

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

func (*Map) GetPointRegion

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

func (*Map) GetRegion

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

type Mapper

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

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 FieldArea map based on the team side. The FieldArea 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 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 FieldArea immediately in front of this one from the player perspective
	// Important: The same FieldArea is returned if the requested FieldArea is not valid
	Front() Region
	// Back is the FieldArea immediately behind this one from the player perspective
	// Important: The same FieldArea is returned if the requested FieldArea is not valid
	Back() Region
	// Left is the FieldArea immediately on left of this one from the player perspective
	// Important: The same FieldArea is returned if the requested FieldArea is not valid
	Left() Region
	// Right is the FieldArea immediately on right of this one from the player perspective
	// Important: The same FieldArea is returned if the requested FieldArea 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