diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-20 12:00:32 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:44 +0100 |
| commit | 260e52050562281a90b970c44e8816afb5f4dbaf (patch) | |
| tree | fa760f4a2b4db32dda5ad8d4d40574b27e302dbd /go/game | |
| parent | cbed4f79f1f7f90f600ad9d1d711f82c6e09e8e5 (diff) | |
| download | muhqs-game-260e52050562281a90b970c44e8816afb5f4dbaf.tar.gz muhqs-game-260e52050562281a90b970c44e8816afb5f4dbaf.zip | |
intermediate commit
* Add static analysis and improve Makefile
* Implement hints from static code analysis
Diffstat (limited to 'go/game')
| -rw-r--r-- | go/game/ai.go | 6 | ||||
| -rw-r--r-- | go/game/card.go | 6 | ||||
| -rw-r--r-- | go/game/map.go | 2 | ||||
| -rw-r--r-- | go/game/map_test.go | 7 | ||||
| -rw-r--r-- | go/game/permanent.go | 2 | ||||
| -rw-r--r-- | go/game/state.go | 6 |
6 files changed, 16 insertions, 13 deletions
diff --git a/go/game/ai.go b/go/game/ai.go index b1921639..18e58957 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -66,9 +66,9 @@ out: } // 2. - if u.AvailMoveActions > 0 { - // TODO: implement path finding - } + // TODO: implement path finding + // if u.AvailMoveActions > 0 { + // } // 3. if u.AvailAttackActions > 0 { diff --git a/go/game/card.go b/go/game/card.go index 9d71cc9c..8576a29e 100644 --- a/go/game/card.go +++ b/go/game/card.go @@ -109,11 +109,11 @@ func (card *Card) parseDefinition(definition []byte) { } delete(data, "name") - switch name.(type) { + switch nameYml := name.(type) { case string: - card.Name = name.(string) + card.Name = nameYml case map[string]interface{}: - cardName := name.(map[string]interface{})["en"] + cardName := nameYml["en"] card.Name = cardName.(string) default: log.Fatalf("Unexpected type %T of yml card field 'Name'\n", name) diff --git a/go/game/map.go b/go/game/map.go index ebf59d25..c84dc519 100644 --- a/go/game/map.go +++ b/go/game/map.go @@ -214,7 +214,7 @@ func (m *Map) RandomTileFromSymbols(symbols []string) (Position, error) { for _, symbol := range symbols { tileString, ok := m.symbols[symbol] if !ok { - return INVALID_POSITION(), errors.New(fmt.Sprintf("symbol %s not in the map symbols %v", symbol, m.symbols)) + return INVALID_POSITION(), fmt.Errorf(fmt.Sprintf("symbol %s not in the map symbols %v", symbol, m.symbols)) } tileType, ok := TileNames[tileString] diff --git a/go/game/map_test.go b/go/game/map_test.go index 8212f648..c8933c69 100644 --- a/go/game/map_test.go +++ b/go/game/map_test.go @@ -52,10 +52,13 @@ kings: } } -func TestLoadingAllMaps(T *testing.T) { +func TestLoadingAllMaps(t *testing.T) { maps := []string{"the-tyrant", "2P-ring-street", "2P-river-king", "3P-ring-street", "4P-islands", "the-kraken"} for _, m := range maps { - LoadMap("../../maps/" + m + ".yml") + _, err := LoadMap("../../maps/" + m + ".yml") + if err != nil { + t.Fatalf("Loading map %s failed with %s", m, err) + } } } diff --git a/go/game/permanent.go b/go/game/permanent.go index e90bd833..ce1d3105 100644 --- a/go/game/permanent.go +++ b/go/game/permanent.go @@ -32,7 +32,7 @@ type PermanentBase struct { func NewPermanentBase(card *Card, tile *Tile, owner *Player) PermanentBase { if tile.Permanent != nil { - log.Fatal("Tile at %v already occupied by %v", tile.Position, tile.Permanent) + log.Fatalf("Tile at %v already occupied by %v", tile.Position, tile.Permanent) } return PermanentBase{card, tile, 0, []Permanent{}, owner, owner} } diff --git a/go/game/state.go b/go/game/state.go index 3d600093..5cab9458 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -58,11 +58,11 @@ func removePtr[P *Unit | *Artifact](collection []P, ptr P) []P { func (s *State) DestroyPermanent(p Permanent) { s.removePermanent(p) - switch p.(type) { + switch p := p.(type) { case *Unit: - s.Units = removePtr(s.Units, p.(*Unit)) + s.Units = removePtr(s.Units, p) case *Artifact: - s.Artifacts = removePtr(s.Artifacts, p.(*Artifact)) + s.Artifacts = removePtr(s.Artifacts, p) } } |
