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 (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -61,10 +60,10 @@ func main() {
|
|||||||
WeaponDamage: *weaponDamage,
|
WeaponDamage: *weaponDamage,
|
||||||
WeaponSpeed: *weaponSpeed,
|
WeaponSpeed: *weaponSpeed,
|
||||||
},
|
},
|
||||||
|
wg: &wg,
|
||||||
}
|
}
|
||||||
log.Printf("my robot: %+v", r)
|
|
||||||
go r.play()
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
go r.play()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
15
robot.go
15
robot.go
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func connect(server string, port int) (*websocket.Conn, error) {
|
func connect(server string, port int) (*websocket.Conn, error) {
|
||||||
@ -23,6 +24,10 @@ type robot struct {
|
|||||||
playerId string
|
playerId string
|
||||||
name string
|
name string
|
||||||
stats StatsRequest
|
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) {
|
func (r *robot) negociate() (err error) {
|
||||||
@ -93,6 +98,7 @@ func (r *robot) negociate() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *robot) play() {
|
func (r *robot) play() {
|
||||||
|
defer r.wg.Done()
|
||||||
var err error
|
var err error
|
||||||
err = r.negociate()
|
err = r.negociate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -118,14 +124,15 @@ func (r *robot) play() {
|
|||||||
log.Printf("%s: Connection lost", r.name)
|
log.Printf("%s: Connection lost", r.name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for _, me := range boardstate.MyRobots {
|
||||||
me = boardstate.MyRobots[0]
|
me = boardstate.MyRobots[0]
|
||||||
if govector.Distance(me.Position, moveto) < 3.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{
|
moveto = govector.Point2d{
|
||||||
X: rand.Float32() * r.game.BoardSize.Width,
|
X: rand.Float32() * r.game.BoardSize.Width,
|
||||||
Y: rand.Float32() * r.game.BoardSize.Height,
|
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
|
// TODO: send instructions
|
||||||
@ -137,7 +144,9 @@ func (r *robot) play() {
|
|||||||
}
|
}
|
||||||
err = websocket.JSON.Send(r.ws, instruction)
|
err = websocket.JSON.Send(r.ws, instruction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user