159 lines
4.4 KiB
Go
159 lines
4.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bitbucket.org/hackerbots/vector"
|
|
"fmt"
|
|
)
|
|
|
|
type ClientConfig struct {
|
|
ID string `json:"id"`
|
|
Stats map[string]StatsRequest `json:"stats"`
|
|
}
|
|
|
|
type BoardSize struct {
|
|
Width float32 `json:"width"`
|
|
Height float32 `json:"height"`
|
|
}
|
|
|
|
type GameParam struct {
|
|
BoardSize BoardSize `json:"boardsize"`
|
|
name string
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
type StatsRequest struct {
|
|
Hp int `json:"hp"`
|
|
Speed int `json:"speed"`
|
|
Acceleration int `json:"acceleration"`
|
|
ScannerRadius int `json:"scanner_radius"`
|
|
TurnSpeed int `json:"turn_speed"`
|
|
FireRate int `json:"fire_rate"`
|
|
WeaponRadius int `json:"weapon_radius"`
|
|
WeaponDamage int `json:"weapon_damage"`
|
|
WeaponSpeed int `json:"weapon_speed"`
|
|
}
|
|
|
|
type Scanner struct {
|
|
Position govector.Point2d `json:"position"`
|
|
Stats StatsRequest `json:"stats"`
|
|
}
|
|
|
|
type Robot struct {
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Message string `json:"-"`
|
|
Stats Stats `json:"-"`
|
|
TargetSpeed float32 `json:"-"`
|
|
Speed float32 `json:"speed"`
|
|
Health int `json:"health"`
|
|
RepairCounter float32 `json:"repair"`
|
|
ScanCounter float32 `json:"scan_bonus"`
|
|
ActiveScan bool `json:"-"`
|
|
Position govector.Point2d `json:"position"`
|
|
Heading govector.Vector2d `json:"heading"`
|
|
MoveTo *govector.Point2d `json:"-"`
|
|
FireAt *govector.Point2d `json:"-"`
|
|
Scanners []Scanner `json:"scanners"`
|
|
LastFired int `json:"-"`
|
|
Collision bool `json:"collision"`
|
|
Hit bool `json:"hit"`
|
|
Probe *govector.Point2d `json:"probe"`
|
|
ProbeResult *govector.Point2d `json:"probe_result"`
|
|
}
|
|
|
|
type Stats struct {
|
|
Hp int `json:"-"`
|
|
Speed float32 `json:"-"`
|
|
Acceleration float32 `json:"-"`
|
|
WeaponRadius int `json:"-"`
|
|
ScannerRadius int `json:"-"`
|
|
TurnSpeed int `json:"-"`
|
|
FireRate int `json:"-"`
|
|
WeaponDamage int `json:"-"`
|
|
WeaponSpeed float32 `json:"-"`
|
|
}
|
|
|
|
type Projectile struct {
|
|
Id string `json:"id"`
|
|
Position govector.Point2d `json:"position"`
|
|
MoveTo govector.Point2d `json:"move_to"`
|
|
Radius int `json:"radius"`
|
|
Speed float32 `json:"speed"`
|
|
Damage int `json:"damage"`
|
|
}
|
|
|
|
type Splosion struct {
|
|
Id string `json:"id"`
|
|
Position govector.Point2d `json:"position"`
|
|
Radius int `json:"radius"`
|
|
MaxDamage int `json:"damage"`
|
|
MinDamage int `json:"damage"`
|
|
Lifespan int `json:"lifespan"`
|
|
}
|
|
|
|
type Instruction struct {
|
|
Message *string `json:"message,omitempty"`
|
|
MoveTo *govector.Point2d `json:"move_to,omitempty"`
|
|
FireAt *govector.Point2d `json:"fire_at,omitempty"`
|
|
Probe *govector.Point2d `json:"probe,omitempty"`
|
|
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
|
Repair *bool `json:"repair,omitempty"`
|
|
Scan *bool `json:"scan,omitempty"`
|
|
}
|
|
|
|
type Boardstate struct {
|
|
MyRobots []Robot `json:"my_robots"`
|
|
OtherRobots []OtherRobot `json:"robots"`
|
|
Projectiles []Projectile `json:"projectiles"`
|
|
Splosions []Splosion `json:"splosions"`
|
|
Obstacles []MiniObstacle `json:"objects"`
|
|
Reset bool `json:"reset"`
|
|
Type string `json:"type"`
|
|
Turn int `json:"turn"`
|
|
AllBots []BotHealth `json:"all_bots"`
|
|
Messages []string `json:"messages"`
|
|
}
|
|
|
|
type OtherRobot struct {
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Position govector.Point2d `json:"position"`
|
|
Heading govector.Vector2d `json:"heading"`
|
|
Health int `json:"health"`
|
|
}
|
|
|
|
type MiniObstacle [4]int
|
|
|
|
func (mo *MiniObstacle) id() string {
|
|
return fmt.Sprintf(
|
|
"%x%x%x%x",
|
|
mo[0],
|
|
mo[1],
|
|
mo[2],
|
|
mo[3],
|
|
)
|
|
}
|
|
|
|
func (mo MiniObstacle) String() string {
|
|
return mo.id()
|
|
}
|
|
|
|
func (mo *MiniObstacle) toObstacle() Obstacle {
|
|
return Obstacle{
|
|
Bounds: govector.AABB2d{
|
|
A: govector.Point2d{float32(mo[0]), float32(mo[1])},
|
|
B: govector.Point2d{float32(mo[2]), float32(mo[3])},
|
|
},
|
|
}
|
|
}
|
|
|
|
type Obstacle struct {
|
|
Bounds govector.AABB2d `json:"bounds"`
|
|
Hp int `json:"-"`
|
|
}
|
|
|
|
type BotHealth struct {
|
|
RobotId string `json:"robot_id"`
|
|
Health int `json:"health"`
|
|
}
|