package main import ( v "bitbucket.org/hackerbots/vector" ) type Robot struct { Id string `json:"id"` Name string `json:"name"` Stats Stats `json:"stats"` TargetSpeed float64 `json:"speed"` Speed float64 `json:"speed"` Health int `json:"health"` Position v.Point2d `json:"position"` Heading v.Vector2d `json:"heading"` MoveTo *v.Point2d `json:"move_to,omitempty"` FireAt *v.Point2d `json:"fire_at,omitempty"` Scanners []Scanner `json:"scanners"` LastFired int `json:"last_fired"` } 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:"hp"` Speed float64 `json:"speed"` Acceleration float64 `json:"acceleration"` WeaponRadius int `json:"weapon_radius"` ScannerRadius int `json:"scanner_radius"` TurnSpeed int `json:"turn_speed"` FireRate int `json:"fire_rate"` } // 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 hp_min := 20.0 hp_max := 200.0 s.Hp = int(((float64(request.Hp) / 100.0) * (hp_max - hp_min)) + hp_min) speed_min := 40.0 speed_max := 200.0 s.Speed = ((float64(request.Speed) / 100.0) * (speed_max - speed_min)) + speed_min accel_min := 20.0 accel_max := 200.0 s.Acceleration = ((float64(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min wep_rad_min := 5.0 wep_rad_max := 60.0 s.WeaponRadius = int(((float64(request.WeaponRadius) / 100.0) * (wep_rad_max - wep_rad_min)) + wep_rad_min) scan_rad_min := 100.0 scan_rad_max := 400.0 s.ScannerRadius = int(((float64(request.ScannerRadius) / 100.0) * (scan_rad_max - scan_rad_min)) + scan_rad_min) turn_spd_min := 30.0 turn_spd_max := 300.0 s.TurnSpeed = int(((float64(request.TurnSpeed) / 100.0) * (turn_spd_max - turn_spd_min)) + turn_spd_min) fire_rate_min := 10.0 fire_rate_max := 2000.0 s.FireRate = int(fire_rate_max+300.0) - int(((float64(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) if total > 350 { return false } return true } type Projectile struct { Id string `json:"id"` Position v.Point2d `json:"position"` MoveTo v.Point2d `json:"move_to"` Radius int `json:"radius"` Speed float64 `json:"speed"` Damage int `json:"damage"` } type Splosion struct { Id string `json:"id"` Position v.Point2d `json:"position"` Radius int `json:"radius"` MaxDamage int `json:"damage"` MinDamage int `json:"damage"` Lifespan int `json:"lifespan"` } 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"` }