From 797886b42b8b31a6429dd37c6bdeb92b4fa4d74a Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Wed, 5 Feb 2020 21:21:25 -0800 Subject: [PATCH] Extract ai.go --- game/ai.go | 29 +++++++++++++++++++++++++++++ game/game.go | 26 -------------------------- 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 game/ai.go diff --git a/game/ai.go b/game/ai.go new file mode 100644 index 0000000..7d80fb0 --- /dev/null +++ b/game/ai.go @@ -0,0 +1,29 @@ +package game + +import "log" + +func chooseCommand(t Team, s State) command { + h := t.Baton.Holder + if collide(h.Pos+1, h.Lane, s) { + return left + } + + var nextBot *Bot + for i, b := range t.Bots { + if b.id == h.id+1 { + nextBot = &t.Bots[i] + break + } + } + + if nextBot != nil { + if h.Lane != nextBot.Lane { + if abs(nextBot.Pos-h.Pos) < h.v { + log.Println("WHOOOOOOA") + return slowDown + } + } + } + + return speedUp +} diff --git a/game/game.go b/game/game.go index 02b04b4..6862cbf 100644 --- a/game/game.go +++ b/game/game.go @@ -101,32 +101,6 @@ func doCommand(cmd command, b *Bot) { } } -func chooseCommand(t Team, s State) command { - h := t.Baton.Holder - if collide(h.Pos+1, h.Lane, s) { - return left - } - - var nextBot *Bot - for i, b := range t.Bots { - if b.id == h.id+1 { - nextBot = &t.Bots[i] - break - } - } - - if nextBot != nil { - if h.Lane != nextBot.Lane { - if abs(nextBot.Pos-h.Pos) < h.v { - log.Println("WHOOOOOOA") - return slowDown - } - } - } - - return speedUp -} - type command int const (