diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-28 11:38:44 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:59 +0100 |
| commit | 2ee42003433b2faeda4ded1bc6557a6eaf3720ff (patch) | |
| tree | ec619361d443732c375fea62853c6a6cb4c4d058 | |
| parent | 00c718e7c7dd082da6aff619147c156c721861b7 (diff) | |
| download | muhqs-game-2ee42003433b2faeda4ded1bc6557a6eaf3720ff.tar.gz muhqs-game-2ee42003433b2faeda4ded1bc6557a6eaf3720ff.zip | |
improve code
* explicitly ignore errors where appropriate
* do not append in a loop
* specify format string in Errorf
| -rw-r--r-- | go/game/ai.go | 4 | ||||
| -rw-r--r-- | go/game/attack.go | 2 | ||||
| -rw-r--r-- | go/game/map.go | 2 | ||||
| -rw-r--r-- | go/game/trigger.go | 5 |
4 files changed, 5 insertions, 8 deletions
diff --git a/go/game/ai.go b/go/game/ai.go index 415f01e0..c55218e3 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -291,7 +291,7 @@ func moveAwayFromEnemies(ai *UnitAI) Action { } a := NewMoveAction(ai.u) - a.Target().AddSelection(farest) + _ = a.Target().AddSelection(farest) return a } @@ -316,7 +316,7 @@ func actionFromPaths(ai *UnitAI, graph *dijkstra.Graph, paths []*dijkstra.BestPa for _, id := range paths[nearest].Path[1:] { mapping, _ := graph.GetMapped(id) var x, y int - fmt.Sscanf(mapping, "(%d, %d)", &x, &y) + _, _ = fmt.Sscanf(mapping, "(%d, %d)", &x, &y) nextStep := m.TileAt(Position{X: x, Y: y}) if slices.Contains(ai.u.MoveRangeTiles(m), nextStep) { target = nextStep diff --git a/go/game/attack.go b/go/game/attack.go index 08bc9567..3896e142 100644 --- a/go/game/attack.go +++ b/go/game/attack.go @@ -12,7 +12,7 @@ type Attack struct { } func INVALID_ATTACK(a Attack) bool { - return a.attacks == nil || len(a.attacks) == 0 + return len(a.attacks) == 0 } func (a Attack) MaxRange() int { diff --git a/go/game/map.go b/go/game/map.go index e0c99911..fb67ebbb 100644 --- a/go/game/map.go +++ b/go/game/map.go @@ -226,7 +226,7 @@ func (m *Map) RandomTileFromSymbols(r *rand.Rand, symbols []string) (Position, e for _, symbol := range symbols { tileString, ok := m.symbols[symbol] if !ok { - return INVALID_POSITION(), fmt.Errorf(fmt.Sprintf("symbol %s not in the map symbols %v", symbol, m.symbols)) + return INVALID_POSITION(), fmt.Errorf("%s", fmt.Sprintf("symbol %s not in the map symbols %v", symbol, m.symbols)) } tileType, ok := TileNames[tileString] diff --git a/go/game/trigger.go b/go/game/trigger.go index eb0cc424..2619bdd8 100644 --- a/go/game/trigger.go +++ b/go/game/trigger.go @@ -75,9 +75,7 @@ func newEotEvent() Event { func newTargetEvent(source interface{}, targets *Targets) Event { affected := make([]interface{}, 0, len(targets.ts)) for _, t := range targets.ts { - for _, sel := range t.sel { - affected = append(affected, sel) - } + affected = append(affected, t.sel...) } return Event{eventType: target, sources: []interface{}{source}, affected: affected} } @@ -109,7 +107,6 @@ func (t *triggerBase) Card() *Card { log.Panicf("Unhandled source type %v", t) return nil } - return nil } func (t *triggerBase) trigger(s *LocalState, e Event) ([]*TriggeredAction, bool) { |
