2013-09-27 22:27:05 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
v "bitbucket.org/hackerbots/vector"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Robot struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
2013-10-19 17:29:40 -07:00
|
|
|
Stats Stats `json:"-"`
|
|
|
|
TargetSpeed float32 `json:"-"`
|
2013-10-19 00:00:45 -07:00
|
|
|
Speed float32 `json:"speed"`
|
2013-09-27 22:27:05 -07:00
|
|
|
Health int `json:"health"`
|
|
|
|
Position v.Point2d `json:"position"`
|
|
|
|
Heading v.Vector2d `json:"heading"`
|
2013-10-19 17:29:40 -07:00
|
|
|
MoveTo *v.Point2d `json:"-"`
|
|
|
|
FireAt *v.Point2d `json:"-"`
|
2013-09-27 22:27:05 -07:00
|
|
|
Scanners []Scanner `json:"scanners"`
|
2013-10-19 17:29:40 -07:00
|
|
|
LastFired int `json:"-"`
|
2013-10-25 22:30:15 -07:00
|
|
|
Collision bool `json:"collision"`
|
2013-09-27 22:27:05 -07:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:13:21 -07:00
|
|
|
// This is the subset of data we send to players about robots
|
|
|
|
// that are not theirs.
|
|
|
|
type OtherRobot struct {
|
2013-10-28 23:35:00 -07:00
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Position v.Point2d `json:"position"`
|
|
|
|
Heading v.Vector2d `json:"heading"`
|
|
|
|
Health int `json:"health"`
|
2013-10-24 20:13:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r Robot) GetTruncatedDetails() OtherRobot {
|
|
|
|
return OtherRobot{
|
|
|
|
Id: r.Id,
|
|
|
|
Name: r.Name,
|
|
|
|
Position: r.Position,
|
2013-10-28 23:35:00 -07:00
|
|
|
Heading: r.Heading,
|
2013-10-24 20:13:21 -07:00
|
|
|
Health: r.Health,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 22:27:05 -07:00
|
|
|
type RobotSorter struct {
|
2013-10-24 20:13:21 -07:00
|
|
|
Robots []OtherRobot
|
2013-09-27 22:27:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2013-10-19 17:29:40 -07:00
|
|
|
Hp int `json:"-"`
|
|
|
|
Speed float32 `json:"-"`
|
|
|
|
Acceleration float32 `json:"-"`
|
|
|
|
WeaponRadius int `json:"-"`
|
|
|
|
ScannerRadius int `json:"-"`
|
|
|
|
TurnSpeed int `json:"-"`
|
|
|
|
FireRate int `json:"-"`
|
2013-09-27 22:27:05 -07:00
|
|
|
}
|
|
|
|
|
2013-10-18 23:22:35 -07:00
|
|
|
// 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
|
2013-10-19 00:00:45 -07:00
|
|
|
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)
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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)
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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)
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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)
|
2013-10-18 23:22:35 -07:00
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
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)
|
2013-10-18 23:22:35 -07:00
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s StatsRequest) Valid() bool {
|
|
|
|
total := (s.Speed + s.Hp + s.WeaponRadius +
|
|
|
|
s.ScannerRadius + s.Acceleration + s.TurnSpeed + s.FireRate)
|
|
|
|
|
2013-10-19 00:00:45 -07:00
|
|
|
// allowing for 50 pts in every category
|
2013-10-20 21:15:23 -07:00
|
|
|
if total > 400 {
|
2013-09-27 22:27:05 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type Instruction struct {
|
|
|
|
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
|
|
|
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
|
|
|
Stats Stats `json:"stats"`
|
|
|
|
}
|