Skip to content

Commit

Permalink
Merge pull request #21 from SladeThe/master
Browse files Browse the repository at this point in the history
Fix bugs and some style issues in Go strategy
  • Loading branch information
kuviman authored Dec 2, 2019
2 parents b7ddc8a + 5c9ec24 commit 260efa9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
4 changes: 3 additions & 1 deletion clients/go/go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module aicup2019
module aicup2019

go 1.13
56 changes: 30 additions & 26 deletions clients/go/my_strategy.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
package main

import . "aicup2019/model"
import "fmt"
import (
"fmt"

type MyStrategy struct {}
. "aicup2019/model"
)

type MyStrategy struct{}

func NewMyStrategy() MyStrategy {
return MyStrategy {}
return MyStrategy{}
}

func distanceSqr(a Vec2Float64, b Vec2Float64) float64 {
return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y)
return (a.X-b.X)*(a.X-b.X) + (a.Y-b.Y)*(a.Y-b.Y)
}

func (strategy MyStrategy) getAction(unit Unit, game Game, debug Debug) UnitAction {
var nearestEnemy *Unit
for _, other := range game.Units {
for i, other := range game.Units {
if other.PlayerId != unit.PlayerId {
if nearestEnemy == nil || distanceSqr(unit.Position, other.Position) < distanceSqr(unit.Position, nearestEnemy.Position) {
nearestEnemy = &other
nearestEnemy = &game.Units[i]
}
}
}
var nearestWeapon *LootBox
for _, lootBox := range game.LootBoxes {
for i, lootBox := range game.LootBoxes {
switch lootBox.Item.(type) {
case *ItemWeapon:
case ItemWeapon:
if nearestWeapon == nil || distanceSqr(unit.Position, lootBox.Position) < distanceSqr(unit.Position, nearestWeapon.Position) {
nearestWeapon = &lootBox
nearestWeapon = &game.LootBoxes[i]
}
}
}
targetPos := unit.Position;
targetPos := unit.Position
if unit.Weapon == nil && nearestWeapon != nil {
targetPos = nearestWeapon.Position
} else if nearestEnemy != nil {
targetPos = nearestEnemy.Position
}
debug.Draw(CustomDataLog {
debug.Draw(CustomDataLog{
Text: fmt.Sprintf("Target pos: %v", targetPos),
});
aim := Vec2Float64 {
})
aim := Vec2Float64{
X: 0,
Y: 0,
}
if nearestEnemy != nil {
aim = Vec2Float64 {
aim = Vec2Float64{
X: nearestEnemy.Position.X - unit.Position.X,
Y: nearestEnemy.Position.Y - unit.Position.Y,
}
}
jump := targetPos.Y > unit.Position.Y
if targetPos.X > unit.Position.X && game.Level.Tiles[int(unit.Position.X + 1)][int(unit.Position.Y)] == TileWall {
jump = true;
if targetPos.X > unit.Position.X && game.Level.Tiles[int(unit.Position.X+1)][int(unit.Position.Y)] == TileWall {
jump = true
}
if targetPos.X < unit.Position.X && game.Level.Tiles[int(unit.Position.X - 1)][int(unit.Position.Y)] == TileWall {
jump = true;
if targetPos.X < unit.Position.X && game.Level.Tiles[int(unit.Position.X-1)][int(unit.Position.Y)] == TileWall {
jump = true
}
return UnitAction {
Velocity: targetPos.X - unit.Position.X,
Jump: jump,
JumpDown: !jump,
Aim: aim,
return UnitAction{
Velocity: targetPos.X - unit.Position.X,
Jump: jump,
JumpDown: !jump,
Aim: aim,
SwapWeapon: false,
PlantMine: false,
PlantMine: false,
Shoot: true,
}
}
}

0 comments on commit 260efa9

Please sign in to comment.