package game func moveToRandomTile(s *State, u *Unit) { moveTargets := u.MoveRangeTiles(s.Map) if len(moveTargets) > 0 { moveTarget := moveTargets[s.Rand.Intn(len(moveTargets))-1] s.MoveUnit(u, moveTarget) } } func attackAttackableEnemyPerm(s *State, u *Unit) { attackablePerms := u.AttackablePermanents(s.Map) if len(attackablePerms) > 0 { attackablePerm := attackablePerms[s.Rand.Intn(len(attackablePerms))-1] s.Fight(u, attackablePerm) } } // 1. If enemy Unit in attack Range then // attack enemy Unit in Range // 2. While move action available do // 3a. If enemy unit exists // move towards nearest enemy unit until it is in attack range // if attack action avail then proceed at 1. // 3b. Otherwise // move to random tile in movement range func AggressiveAi(s *State, u *Unit) { // 1. attackAttackableEnemyPerm(s, u) // 2. if u.AvailMoveActions > 0 { enemyUnits := s.EnemyUnits(u.GetController()) if len(enemyUnits) > 0 { // 3a. // TODO: implement path finding if u.AvailAttackActions > 0 { AggressiveAi(s, u) } } else { // 3b. moveToRandomTile(s, u) } } } // 2.2 Shy // 1. If not in the attack Range of an enemy Unit then // activate full action if available // 2. If move action available then // move to most distant point from all enemy units // 3. If enemy Unit in attack Range then // attack enemy Unit in Range func ShyAi(s *State, u *Unit) { // 1. inEnemyAttackRange := false out: for _, enemyUnit := range s.EnemyUnits(u.GetController()) { for _, p := range enemyUnit.AttackablePermanents(s.Map) { if p == u { inEnemyAttackRange = true break out } } } if !inEnemyAttackRange && u.HasFullAction() { u.FullAction() } // 2. // TODO: implement path finding // if u.AvailMoveActions > 0 { // } // 3. if u.AvailAttackActions > 0 { attackAttackableEnemyPerm(s, u) } } // 2.3 Wandering X // 1. If enemy unit in Range X then // execute aggressive AI // 2. If move action available then // move to random tile in movement Range // proceed at 1. func WanderingAi(s *State, u *Unit, x int) { // 1. for _, enemyUnit := range s.EnemyUnits(u.GetController()) { if IsPositionInRange(u.GetTile().Position, enemyUnit.GetTile().Position, x) { AggressiveAi(s, u) break } } // 2. if u.AvailMoveActions > 0 { moveToRandomTile(s, u) WanderingAi(s, u, x) } } // 2.4 Target-oriented TARGET // 1. Use full action if possible // 2a. If a TARGET exists and is reachable // // Move onto or towards nearest TARGET // 3a. If enemy Unit in attack Range // attack enemy Unit in Range // // 2b. Otherwise // // execute wandering 3 AI func TargetOrientedAi(s *State, u *Unit, t *Position) { // 1. if u.HasFullAction() { u.FullAction() } if t != nil { // TODO: path finding again attackAttackableEnemyPerm(s, u) } else { WanderingAi(s, u, 3) } }