Skip to content

Commit

Permalink
Merge branch 'master' of github.com:intelygenz/codeconz-lighthouses-e…
Browse files Browse the repository at this point in the history
…ngine
  • Loading branch information
onizucraft committed Nov 14, 2024
2 parents 4f8b6f5 + 7f20a2b commit b53af55
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion internal/engine/game/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/engine/game/initialstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions maps/mapjgm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! !
!
!AA
!

0 comments on commit b53af55

Please sign in to comment.