float32 -> float64

This commit is contained in:
sm
2014-04-26 15:36:04 -07:00
parent db28bfea11
commit 8f7ef5aa1a
8 changed files with 83 additions and 82 deletions
+50 -50
View File
@@ -15,11 +15,11 @@ type Robot struct {
Name string `json:"name"`
Message string `json:"-"`
Stats Stats `json:"-"`
TargetSpeed float32 `json:"-"`
Speed float32 `json:"speed"`
TargetSpeed float64 `json:"-"`
Speed float64 `json:"speed"`
Health int `json:"health"`
RepairCounter float32 `json:"repair"`
ScanCounter float32 `json:"scan_bonus"`
RepairCounter float64 `json:"repair"`
ScanCounter float64 `json:"scan_bonus"`
ActiveScan bool `json:"-"`
Position v.Point2d `json:"position"`
Heading v.Vector2d `json:"heading"`
@@ -33,7 +33,7 @@ type Robot struct {
Probe *v.Point2d `json:"probe"`
ProbeResult *Collision `json:"probe_result"`
gameStats *BotStats `json:"-"`
Delta float32 `json:"-"`
Delta float64 `json:"-"`
idg *IdGenerator
}
@@ -101,14 +101,14 @@ func (s AllRobotSorter) Less(i, j int) bool {
// Stats is the point allocation for a Robot.
type Stats struct {
Hp int `json:"hp"`
Speed float32 `json:"speed"`
Acceleration float32 `json:"acceleration"`
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"`
WeaponDamage int `json:"weapon_damage"`
WeaponSpeed float32 `json:"weapon_speed"`
WeaponSpeed float64 `json:"weapon_speed"`
}
// StatsRequest is the struct used in comunication with the player. We request
@@ -131,41 +131,41 @@ 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)
hp_min := 20.0
hp_max := 200.0
s.Hp = int((float64(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
speed_min := 40.0
speed_max := 200.0
s.Speed = float64(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
accel_min := 20.0
accel_max := 200.0
s.Acceleration = ((float64(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)
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)
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)
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)
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)
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)
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)
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)
var weapon_damage_min float32 = 0.0
var weapon_damage_max float32 = 20.0
s.WeaponDamage = int(((float32(request.WeaponDamage) / 100.0) * (weapon_damage_max - weapon_damage_min)) + weapon_damage_min)
weapon_damage_min := 0.0
weapon_damage_max := 20.0
s.WeaponDamage = int(((float64(request.WeaponDamage) / 100.0) * (weapon_damage_max - weapon_damage_min)) + weapon_damage_min)
var weapon_speed_min float32 = 80.0
var weapon_speed_max float32 = 600.0
s.WeaponSpeed = float32(((float32(request.WeaponSpeed) / 100.0) * (weapon_speed_max - weapon_speed_min)) + weapon_speed_min)
weapon_speed_min := 80.0
weapon_speed_max := 600.0
s.WeaponSpeed = float64(((float64(request.WeaponSpeed) / 100.0) * (weapon_speed_max - weapon_speed_min)) + weapon_speed_min)
return s
}
@@ -177,7 +177,7 @@ type Instruction struct {
Heading *v.Vector2d `json:"heading,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Probe *v.Point2d `json:"probe,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"`
TargetSpeed *float64 `json:"target_speed,omitempty"`
Repair *bool `json:"repair,omitempty"`
Scan *bool `json:"scan,omitempty"`
}
@@ -187,12 +187,12 @@ type Instruction struct {
func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *Robot) {
finalCollision := false
collision := false
closest := float32(math.Inf(1))
closest := math.Inf(1)
var intersection *v.Point2d
var finalRobot *Robot
// TODO: this needs moved to the conf?
botSize := float32(5.0)
botSize := 5.0
botPolygon := v.OrientedSquare(r.Position, r.Heading, botSize)
// Check Walls
@@ -314,12 +314,12 @@ func (r *Robot) Tick(g *Game) {
}
// Max turn radius in this case is in degrees per second
if float32(math.Abs(float64(angle))) > (float32(r.Stats.TurnSpeed) * r.Delta) {
if math.Abs(angle) > float64(r.Stats.TurnSpeed)*r.Delta {
// New heading should be a little less, take current heading and
// rotate by the max turn radius per frame.
rot := (float32(r.Stats.TurnSpeed) * r.Delta) * v.Deg2rad
rot := (float64(r.Stats.TurnSpeed) * r.Delta) * v.Deg2rad
new_heading = current_heading.Rotate(rot * float32(dir))
new_heading = current_heading.Rotate(rot * dir)
}
move_vector := new_heading.Scale(r.Speed * r.Delta)
@@ -386,9 +386,9 @@ func (r *Robot) Tick(g *Game) {
// We are only allowed to scan when we're stopped
if math.Abs(float64(r.Speed)) < v.Epsilon && r.ActiveScan {
r.ScanCounter += r.Delta * float32(r.Stats.ScannerRadius) * 0.1
r.ScanCounter += r.Delta * float64(r.Stats.ScannerRadius) * 0.1
} else if r.ScanCounter > 0 {
r.ScanCounter -= r.Delta * float32(r.Stats.ScannerRadius) * 0.05
r.ScanCounter -= r.Delta * float64(r.Stats.ScannerRadius) * 0.05
if r.ScanCounter <= 0 {
r.ScanCounter = 0
}
@@ -425,7 +425,7 @@ func (r *Robot) scan(g *Game) {
continue
}
dist := v.Distance(bot.Position, r.Position)
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
s := Scanner{
Id: bot.Id,
Type: "robot",
@@ -441,7 +441,7 @@ func (r *Robot) scan(g *Game) {
}
dist := v.Distance(proj.Position, r.Position)
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
s := Scanner{
Id: proj.Id,
Type: "projectile",
@@ -452,7 +452,7 @@ func (r *Robot) scan(g *Game) {
for splo := range g.splosions {
dist := v.Distance(splo.Position, r.Position)
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
s := Scanner{
Id: splo.Id,
Type: "explosion",
@@ -466,8 +466,8 @@ func (r *Robot) scan(g *Game) {
// fire is called according to player instruction. XXX: There is a race here...
func (r *Robot) fire(g *Game) *Projectile {
// Throttle the fire rate
time_since_fired := (float32(g.turn) * (r.Delta * 1000)) - (float32(r.LastFired) * (r.Delta * 1000))
if time_since_fired < float32(r.Stats.FireRate) {
time_since_fired := (float64(g.turn) * (r.Delta * 1000)) - (float64(r.LastFired) * (r.Delta * 1000))
if time_since_fired < float64(r.Stats.FireRate) {
return nil
}
@@ -490,8 +490,8 @@ func (r *Robot) fire(g *Game) *Projectile {
func (r *Robot) reset(g *Game) {
for {
start_pos := v.Point2d{
X: rand.Float32() * float32(g.width),
Y: rand.Float32() * float32(g.height),
X: rand.Float64() * float64(g.width),
Y: rand.Float64() * float64(g.height),
}
r.MoveTo = &start_pos
r.Position = start_pos