137 lines
3.6 KiB
Go
137 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
v "bitbucket.org/hackerbots/vector"
|
|
)
|
|
|
|
type Robot struct {
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Stats Stats `json:"-"`
|
|
TargetSpeed float32 `json:"-"`
|
|
Speed float32 `json:"speed"`
|
|
Health int `json:"health"`
|
|
Position v.Point2d `json:"position"`
|
|
Heading v.Vector2d `json:"heading"`
|
|
MoveTo *v.Point2d `json:"-"`
|
|
FireAt *v.Point2d `json:"-"`
|
|
Scanners []Scanner `json:"scanners"`
|
|
LastFired int `json:"-"`
|
|
}
|
|
|
|
type RobotSorter struct {
|
|
Robots []Robot
|
|
}
|
|
|
|
func (s RobotSorter) Len() int {
|
|
return len(s.Robots)
|
|
}
|
|
|
|
func (s RobotSorter) Swap(i, j int) {
|
|
s.Robots[i], s.Robots[j] = s.Robots[j], s.Robots[i]
|
|
}
|
|
|
|
func (s RobotSorter) Less(i, j int) bool {
|
|
return s.Robots[i].Id < s.Robots[j].Id
|
|
}
|
|
|
|
type Stats struct {
|
|
Hp int `json:"-"`
|
|
Speed float32 `json:"-"`
|
|
Acceleration float32 `json:"-"`
|
|
WeaponRadius int `json:"-"`
|
|
ScannerRadius int `json:"-"`
|
|
TurnSpeed int `json:"-"`
|
|
FireRate int `json:"-"`
|
|
}
|
|
|
|
// We request stats using an integer between 1 and 100, the
|
|
// integer values map to sensible min-max ranges
|
|
type StatsRequest struct {
|
|
Hp int `json:"hp"`
|
|
Speed int `json:"speed"`
|
|
Acceleration int `json:"acceleration"`
|
|
WeaponRadius int `json:"weapon_radius"`
|
|
ScannerRadius int `json:"scanner_radius"`
|
|
TurnSpeed int `json:"turn_speed"`
|
|
FireRate int `json:"fire_rate"`
|
|
}
|
|
|
|
func DeriveStats(request StatsRequest) Stats {
|
|
s := Stats{}
|
|
|
|
// Conversion Tables
|
|
var hp_min float32 = 20.0
|
|
var hp_max float32 = 200.0
|
|
s.Hp = int(((float32(request.Hp) / 100.0) * (hp_max - hp_min)) + hp_min)
|
|
|
|
var speed_min float32 = 40.0
|
|
var speed_max float32 = 200.0
|
|
s.Speed = ((float32(request.Speed) / 100.0) * (speed_max - speed_min)) + speed_min
|
|
|
|
var accel_min float32 = 20.0
|
|
var accel_max float32 = 200.0
|
|
s.Acceleration = ((float32(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min
|
|
|
|
var wep_rad_min float32 = 5.0
|
|
var wep_rad_max float32 = 60.0
|
|
s.WeaponRadius = int(((float32(request.WeaponRadius) / 100.0) * (wep_rad_max - wep_rad_min)) + wep_rad_min)
|
|
|
|
var scan_rad_min float32 = 100.0
|
|
var scan_rad_max float32 = 400.0
|
|
s.ScannerRadius = int(((float32(request.ScannerRadius) / 100.0) * (scan_rad_max - scan_rad_min)) + scan_rad_min)
|
|
|
|
var turn_spd_min float32 = 30.0
|
|
var turn_spd_max float32 = 300.0
|
|
s.TurnSpeed = int(((float32(request.TurnSpeed) / 100.0) * (turn_spd_max - turn_spd_min)) + turn_spd_min)
|
|
|
|
var fire_rate_min float32 = 10.0
|
|
var fire_rate_max float32 = 2000.0
|
|
s.FireRate = int(fire_rate_max+300.0) - int(((float32(request.FireRate)/100.0)*(fire_rate_max-fire_rate_min))+fire_rate_min)
|
|
|
|
return s
|
|
}
|
|
|
|
func (s StatsRequest) Valid() bool {
|
|
total := (s.Speed + s.Hp + s.WeaponRadius +
|
|
s.ScannerRadius + s.Acceleration + s.TurnSpeed + s.FireRate)
|
|
|
|
// allowing for 50 pts in every category
|
|
if total > 350 {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
type Projectile struct {
|
|
Id string `json:"id"`
|
|
Position v.Point2d `json:"position"`
|
|
MoveTo v.Point2d `json:"-"`
|
|
Radius int `json:"radius"`
|
|
Speed float32 `json:"-"`
|
|
Damage int `json:"-"`
|
|
}
|
|
|
|
type Splosion struct {
|
|
Id string `json:"id"`
|
|
Position v.Point2d `json:"position"`
|
|
Radius int `json:"radius"`
|
|
MaxDamage int `json:"-"`
|
|
MinDamage int `json:"-"`
|
|
Lifespan int `json:"-"`
|
|
}
|
|
|
|
func (s *Splosion) Tick() {
|
|
s.Lifespan--
|
|
}
|
|
|
|
func (s *Splosion) Alive() bool {
|
|
return s.Lifespan > 0
|
|
}
|
|
|
|
type Instruction struct {
|
|
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
|
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
|
Stats Stats `json:"stats"`
|
|
}
|