unstopped failure conditions
This commit is contained in:
parent
2fb7ff7b20
commit
e1bed61a00
5
main.go
5
main.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
@ -61,10 +60,10 @@ func main() {
|
||||
WeaponDamage: *weaponDamage,
|
||||
WeaponSpeed: *weaponSpeed,
|
||||
},
|
||||
wg: &wg,
|
||||
}
|
||||
log.Printf("my robot: %+v", r)
|
||||
go r.play()
|
||||
wg.Add(1)
|
||||
go r.play()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
15
robot.go
15
robot.go
@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func connect(server string, port int) (*websocket.Conn, error) {
|
||||
@ -23,6 +24,10 @@ type robot struct {
|
||||
playerId string
|
||||
name string
|
||||
stats StatsRequest
|
||||
|
||||
// TODO: don't know if I like how this is done ... I would rather send
|
||||
// a signal over a chanel
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
func (r *robot) negociate() (err error) {
|
||||
@ -93,6 +98,7 @@ func (r *robot) negociate() (err error) {
|
||||
}
|
||||
|
||||
func (r *robot) play() {
|
||||
defer r.wg.Done()
|
||||
var err error
|
||||
err = r.negociate()
|
||||
if err != nil {
|
||||
@ -118,14 +124,15 @@ func (r *robot) play() {
|
||||
log.Printf("%s: Connection lost", r.name)
|
||||
return
|
||||
}
|
||||
for _, me := range boardstate.MyRobots {
|
||||
me = boardstate.MyRobots[0]
|
||||
if govector.Distance(me.Position, moveto) < 3.0 {
|
||||
log.Printf("old: %+v: %+v", me.Position, moveto)
|
||||
log.Printf("%s: old: %+v: %+v", r.name, me.Position, moveto)
|
||||
moveto = govector.Point2d{
|
||||
X: rand.Float32() * r.game.BoardSize.Width,
|
||||
Y: rand.Float32() * r.game.BoardSize.Height,
|
||||
}
|
||||
log.Printf("new: %+v: %+v", me.Position, moveto)
|
||||
log.Printf("%s: new: %+v: %+v", r.name, me.Position, moveto)
|
||||
}
|
||||
|
||||
// TODO: send instructions
|
||||
@ -137,7 +144,9 @@ func (r *robot) play() {
|
||||
}
|
||||
err = websocket.JSON.Send(r.ws, instruction)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user