From 98d005af41aa0aca4b8d5daa6feaea51bbad5d6e Mon Sep 17 00:00:00 2001 From: Terry Malone Date: Thu, 22 Dec 2022 17:00:06 +0000 Subject: [PATCH 1/2] Create Starter.go --- starterAIs/Starter.go | 125 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 starterAIs/Starter.go diff --git a/starterAIs/Starter.go b/starterAIs/Starter.go new file mode 100644 index 0000000..6875e9d --- /dev/null +++ b/starterAIs/Starter.go @@ -0,0 +1,125 @@ +package main + +import ( + "fmt" + "strings" +) + +/** + * Auto-generated code below aims at helping you parse + * the standard input according to the problem statement. + **/ +type Tile struct { + x int + y int + scrapAmount int + owner int + units int + recycler bool + canBuild bool + canSpawn bool + inRangeOfRecycler bool +} + +const me = 1 +const foe = 0 +const neutral = -1 + +func main() { + var width, height int + fmt.Scan(&width, &height) + + // game loop + for { + var tiles []Tile + var myTiles []Tile + var oppTiles []Tile + var neutralTiles []Tile + var myUnits []Tile + var oppUnits []Tile + var myRecyclers []Tile + var oppRecyclers []Tile + + var myMatter, oppMatter int + fmt.Scan(&myMatter, &oppMatter) + + for i := 0; i < height; i++ { + for j := 0; j < width; j++ { + // owner: 1 = me, 0 = foe, -1 = neutral + var scrapAmount, owner, units, recycler, canBuild, canSpawn, inRangeOfRecycler int + fmt.Scan(&scrapAmount, &owner, &units, &recycler, &canBuild, &canSpawn, &inRangeOfRecycler) + + tile := Tile{ + i, + j, + scrapAmount, + owner, + units, + recycler == 1, + canBuild == 1, + canSpawn == 1, + inRangeOfRecycler == 1, + } + + tiles = append(tiles, tile) + + if tile.owner == me { + myTiles = append(myTiles, tile) + + if tile.units > 0 { + myUnits = append(myUnits, tile) + } else if tile.recycler { + myRecyclers = append(myRecyclers, tile) + } + } else if tile.owner == foe { + oppTiles = append(oppTiles, tile) + + if tile.units > 0 { + oppUnits = append(oppUnits, tile) + } else if tile.recycler { + oppRecyclers = append(oppRecyclers, tile) + } else { + neutralTiles = append(neutralTiles, tile) + } + } + } + } + + // calculate actions + var actions []string + + for _, tile := range tiles { + + if tile.canSpawn { + amount := 1 // TODO: pick amount of robots to spawn here + if amount > 0 { + actions = append(actions, fmt.Sprintf("SPAWN %d %d %d", amount, tile.x, tile.y)) + } + } + + if tile.canBuild { + shouldBuild := true // TODO: pick whether to build recycler here + if shouldBuild { + actions = append(actions, fmt.Sprintf("BUILD %d %d", tile.x, tile.y)) + } + } + } + + for _, tile := range myUnits { + // TODO: pick a destination + targetX := -1 + targetY := -1 + if targetX != -1 && targetY != -1 { + amount := 0 // TODO: pick amount of units to move + actions = append(actions, fmt.Sprintf("MOVE %d %d %d %d %d", amount, tile.x, tile.y, targetX, targetY)) + } + } + + // fmt.Fprintln(os.Stderr, "Debug messages...") + if len(actions) <= 0 { + fmt.Println("WAIT") + } else { + fmt.Println(strings.Join(actions, ";")) + } + } +} From 52b27fe80db223ef7bfcd4947690f26ae4f0bb89 Mon Sep 17 00:00:00 2001 From: Terry Malone Date: Thu, 22 Dec 2022 21:09:11 +0000 Subject: [PATCH 2/2] Update Starter.go --- starterAIs/Starter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starterAIs/Starter.go b/starterAIs/Starter.go index 6875e9d..1492961 100644 --- a/starterAIs/Starter.go +++ b/starterAIs/Starter.go @@ -50,8 +50,8 @@ func main() { fmt.Scan(&scrapAmount, &owner, &units, &recycler, &canBuild, &canSpawn, &inRangeOfRecycler) tile := Tile{ - i, j, + i, scrapAmount, owner, units,