Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.codestrikes.adapter;
- import net.codestrikes.sdk.Area;
- import net.codestrikes.sdk.BotBase;
- import net.codestrikes.sdk.Move;
- import net.codestrikes.sdk.MoveCollection;
- import net.codestrikes.sdk.ReadonlyMoveCollection;
- import net.codestrikes.sdk.RoundContext;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- public class PlayerBot extends BotBase {
- private static Map<Area, Integer> attackBlockedByEnemyCount;
- static {
- attackBlockedByEnemyCount = new HashMap<>();
- attackBlockedByEnemyCount.put(Area.HookKick, 0);
- attackBlockedByEnemyCount.put(Area.UppercutPunch, 0);
- attackBlockedByEnemyCount.put(Area.LowKick, 0);
- attackBlockedByEnemyCount.put(Area.HookPunch, 0);
- }
- private static Map<Area, Integer> attacksReceivedCount;
- static {
- attacksReceivedCount = new HashMap<>();
- attacksReceivedCount.put(Area.HookKick, 0);
- attacksReceivedCount.put(Area.UppercutPunch, 0);
- attacksReceivedCount.put(Area.LowKick, 0);
- attacksReceivedCount.put(Area.HookPunch, 0);
- }
- private static int enemyHp = 200;
- private static int playerHp = 200;
- private static int turnCount = 1;
- private static boolean aggressiveStance = true;
- private static MoveCollection myLastMoves;
- public MoveCollection nextMove(RoundContext context) {
- if (turnCount == 1 || (context.getLastOpponentMoves() == null && playerHp != 200)) {
- if (context.getLastOpponentMoves() == null && playerHp != 200) {
- enemyHp = 0;
- playerHp = 0;
- context.setMoves(chooseNextMoves());
- updateStatistics(context);
- checkStats(context);
- } else {
- context.setMoves(chooseNextMoves());
- updateStatistics(context);
- checkStats(context);
- }
- } else {
- updateStatistics(context);
- checkStats(context);
- context.setMoves(chooseNextMoves());
- }
- if (playerHp < 50) aggressiveStance = false;
- turnCount++;
- myLastMoves = context.getMyMoves();
- return context.getMyMoves();
- }
- private Area generateRandomArea() {
- if (aggressiveStance) {
- int random = new Random().nextInt(3);
- Area[] areas = {Area.HookPunch, Area.UppercutPunch, Area.HookKick};
- return areas[random];
- }
- else{
- int random = new Random().nextInt(2);
- Area[] areas = {Area.HookPunch, Area.UppercutPunch};
- return areas[random];
- }
- }
- private MoveCollection chooseNextMoves() {
- MoveCollection moves;
- if (!aggressiveStance) {
- if (turnCount % 2 == 1) {
- moves = getAttacksCombo(generateRandomArea())
- .addDefence(generateRandomArea())
- .addDefence(Area.HookKick);
- } else {
- moves = calculateNextAttacks()
- .addDefence(calculateNextDefence())
- .addDefence(Area.HookKick);
- }
- } else {
- if (turnCount % 2 == 1) {
- moves = getDoubleAttacksCombo(generateRandomArea())
- .addDefence(calculateNextDefence());
- } else {
- moves = calculateNextAttacks()
- .addDefence(calculateNextDefence());
- }
- }
- return moves;
- }
- private void updateStatistics(RoundContext context) {
- if (context.getLastOpponentMoves() != null && myLastMoves != null) {
- for (Move move : myLastMoves.getAttacks()) {
- if (Arrays.stream(context.getLastOpponentMoves().getDefences()).anyMatch(x -> x.getArea().equals(move.getArea()))) {
- Integer lastValue = attackBlockedByEnemyCount.get(move.getArea());
- attackBlockedByEnemyCount.replace(move.getArea(), lastValue, lastValue + 1);
- }
- }
- for (Move move : context.getLastOpponentMoves().getAttacks()) {
- if (Arrays.stream(myLastMoves.getDefences()).noneMatch(x -> x.getArea().equals(move.getArea()))) {
- Integer lastValue = attacksReceivedCount.get(move.getArea());
- attacksReceivedCount.replace(move.getArea(), lastValue, lastValue + 1);
- }
- }
- }
- }
- private void checkStats(RoundContext context) {
- enemyHp = enemyHp - context.getMyDamage();
- playerHp = playerHp - context.getOpponentDamage();
- if (enemyHp <= 0 || playerHp <= 0) {
- for (Map.Entry<Area, Integer> entry : attackBlockedByEnemyCount.entrySet()) {
- entry.setValue(0);
- }
- for (Map.Entry<Area, Integer> entry : attacksReceivedCount.entrySet()) {
- entry.setValue(0);
- }
- aggressiveStance = true;
- enemyHp = 200;
- playerHp = 200;
- turnCount = 1;
- }
- }
- private MoveCollection getAttacksCombo(Area nextArea) {
- MoveCollection moveCollection = new MoveCollection();
- switch (nextArea) {
- case HookPunch:
- return moveCollection.addAttack(Area.HookPunch).addAttack(Area.LowKick);
- case UppercutPunch:
- return moveCollection.addAttack(Area.UppercutPunch).addAttack(Area.UppercutPunch);
- default:
- return moveCollection.addAttack(Area.HookKick);
- }
- }
- private MoveCollection getDoubleAttacksCombo(Area nextArea) {
- MoveCollection moveCollection = new MoveCollection();
- switch (nextArea) {
- case LowKick:
- return moveCollection.addAttack(Area.HookKick).addAttack(Area.LowKick).addAttack(Area.HookPunch);
- case HookPunch:
- return moveCollection.addAttack(Area.HookPunch).addAttack(Area.LowKick).addAttack(Area.HookPunch).addAttack(Area.LowKick);
- case UppercutPunch:
- return moveCollection.addAttack(Area.UppercutPunch).addAttack(Area.UppercutPunch).addAttack(Area.UppercutPunch).addAttack(Area.UppercutPunch);
- default:
- return moveCollection.addAttack(Area.HookKick).addAttack(Area.HookKick);
- }
- }
- private MoveCollection calculateNextAttacks() {
- int min = 200;
- Area nextArea = Area.HookKick;
- for (Map.Entry<Area, Integer> entry : attackBlockedByEnemyCount.entrySet()) {
- if (entry.getValue() < min) {
- min = entry.getValue();
- nextArea = entry.getKey();
- }
- }
- if (!aggressiveStance) return getAttacksCombo(nextArea);
- return getDoubleAttacksCombo(nextArea);
- }
- private Area calculateNextDefence() {
- int max = attacksReceivedCount.get(Area.HookKick);
- Area nextArea = Area.HookKick;
- for (Map.Entry<Area, Integer> entry : attacksReceivedCount.entrySet()) {
- if (entry.getValue() > max) {
- max = entry.getValue();
- nextArea = entry.getKey();
- }
- }
- if (nextArea != Area.LowKick) return nextArea;
- return Area.HookKick;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement