diff --git a/internal/engine/game/actions.go b/internal/engine/game/actions.go index f5212e5..9d65fe5 100644 --- a/internal/engine/game/actions.go +++ b/internal/engine/game/actions.go @@ -47,7 +47,8 @@ func (e *Game) moveToPosition(p *player.Player, action *player.Action) error { if err != nil { return err } - p.AddLighthouseKey(*l) + p.AddLighthouseKey(l) + fmt.Printf("Player %d got key for lighthouse %d in position %v\n", p.ID, l.ID, l.Position) } } diff --git a/internal/engine/game/initialstate.go b/internal/engine/game/initialstate.go index ad81997..bfd7ad7 100644 --- a/internal/engine/game/initialstate.go +++ b/internal/engine/game/initialstate.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" "github.com/jonasdacruz/lighthouses_aicontest/internal/engine/lighthouse" "github.com/jonasdacruz/lighthouses_aicontest/internal/engine/player" @@ -57,7 +58,8 @@ func (e *Game) SendInitialState() { panic(err) } - ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("turn_request_timeout")) + // Add 5 seconds timeout to the InitialState call + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() // sending initial state to player diff --git a/internal/engine/player/player.go b/internal/engine/player/player.go index 0cb5153..be479c8 100644 --- a/internal/engine/player/player.go +++ b/internal/engine/player/player.go @@ -68,13 +68,13 @@ func (p *Player) GetPosition() (x, y int) { return int(p.Position.X()), int(p.Position.Y()) } -func (p *Player) AddLighthouseKey(lighthouse lighthouse.Lighthouse) { +func (p *Player) AddLighthouseKey(lighthouse *lighthouse.Lighthouse) { if !p.LighthouseKeyExists(lighthouse) { - p.LighthouseKeys = append(p.LighthouseKeys, &lighthouse) + p.LighthouseKeys = append(p.LighthouseKeys, lighthouse) } } -func (p *Player) LighthouseKeyExists(lighthouse lighthouse.Lighthouse) bool { +func (p *Player) LighthouseKeyExists(lighthouse *lighthouse.Lighthouse) bool { for _, l := range p.LighthouseKeys { if l.Position.Equal(geom.XY, lighthouse.Position) { return true diff --git a/maps/mapjgm.txt b/maps/mapjgm.txt new file mode 100644 index 0000000..5c3938a --- /dev/null +++ b/maps/mapjgm.txt @@ -0,0 +1,4 @@ +! ! + ! +!AA + !