From 03e8308f71b8c0b206780df5320bd85595b7dc32 Mon Sep 17 00:00:00 2001 From: androidmage Date: Tue, 12 Jan 2016 18:50:53 -0500 Subject: [PATCH 1/7] Updated archon escape and guards Archons will always to try move anywhere but where it is if can be potentially attacked and guards no longer throw Game Action Exception. --- RobotPlayer.java | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 2bbc3b3..d3c2bd2 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -189,15 +189,17 @@ public void run() { Signal[] signals = rc.emptySignalQueue(); if(signals.length > 0){ //if == 0, no signals, so not ready for(Signal s: signals){ - if(moveCount < 1 && s.getTeam() == ourTeam && rc.senseRobot(s.getID()).type == RobotType.ARCHON){ + if(moveCount < 1 && s.getTeam() == ourTeam){ FancyMessage f = FancyMessage.getFromRecievedSignal(s); - MapLocation archonLocation = f.senderLocation; - Direction archonDirection = rc.getLocation().directionTo(archonLocation); - Direction oppositeDirection = archonDirection.opposite(); - if(rc.isCoreReady()){ - if(rc.canMove(oppositeDirection)){ - rc.move(oppositeDirection); - moveCount += 1; + if(f.type == 0){ + MapLocation archonCreatorLocation = f.senderLocation; + Direction archonDirection = rc.getLocation().directionTo(archonCreatorLocation); + Direction oppositeDirection = archonDirection.opposite(); + if(rc.isCoreReady()){ + if(rc.canMove(oppositeDirection)){ + rc.move(oppositeDirection); + moveCount += 1; + } } } } @@ -938,6 +940,12 @@ public static void escapeEnemy(){ return; } } + for(Direction possibleDirection: DIRECTIONS){ + if(rc.canMove(possibleDirection)){ + rc.move(possibleDirection); + return; + } + } } catch (Exception e) { System.out.println(e.getMessage()); @@ -960,6 +968,9 @@ public static ArrayList dangerousRobots(RobotInfo[] enemies, MapLocat dangerousEnemies.add(enemy); } } + if(dangerousEnemies.isEmpty()){ + return null; + } return dangerousEnemies; } From 43a044f9eb5b1294b38f97c53b724521b2463186 Mon Sep 17 00:00:00 2001 From: androidmage Date: Tue, 12 Jan 2016 21:22:24 -0500 Subject: [PATCH 2/7] Archon produce scout if all but one spot full --- RobotPlayer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index d3c2bd2..5f42261 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -753,6 +753,9 @@ public static RobotType chooseRobotType() { if(Math.random()*3>1) { return RobotType.SCOUT; } + if(almostSurrounded()){ + return RobotType.SCOUT; + } if(numberOfRobotsInRadiusAndThoseRobots(RobotType.GUARD,3,ourTeam).first == 7){ return RobotType.SCOUT; } @@ -765,7 +768,18 @@ public static RobotType chooseRobotType() { } return RobotType.GUARD; } - + /** + * boolean almostSurrounded + * @return a boolean on whether or not robot is almost surrounded + * + */ + public static boolean almostSurrounded(){ + RobotInfo[] robots = rc.senseNearbyRobots(3); + if(robots != null && robots.length == 7){ + return true; + } + return false; + } /** * Returns the number of robots within a given radius squared * @param type the type of robot to look for From 52a5aeb93cf408b20ed53346323f91e1862787c9 Mon Sep 17 00:00:00 2001 From: androidmage Date: Tue, 12 Jan 2016 23:11:36 -0500 Subject: [PATCH 3/7] Added viper class but not implemented --- RobotPlayer.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/RobotPlayer.java b/RobotPlayer.java index 5f42261..1f0f175 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -59,8 +59,60 @@ else if(selftype == RobotType.SOLDIER) { Soldier s = new RobotPlayer().new Soldier(); s.run(); } + else if(selftype == RobotType.VIPER){ + Viper s = new RobotPlayer().new Viper(); + s.run(); + } } + /** + * + * Class Viper + * + * The class outlining our viper bots + * + */ + private class Viper{ + public MapLocation enemyArchonLocation; + public boolean goOffense; + + public Viper() { + goOffense = false; + } + + public void run() { + while(true) { + try { + // Use Guard AI (move out) until there are enough soldiers ammassed around, then go towards enemy archon and attack + Signal[] signals = rc.emptySignalQueue(); + if (signals.length > 0) { + for (Signal s : signals) { + // receive a message containing enemy archon ID + if (s.getTeam() == ourTeam) { + FancyMessage f = FancyMessage.getFromRecievedSignal(s); + if(f.type == 2){ + int xPos = f.ints.first; + int yPos = f.ints.second; + enemyArchonLocation = new MapLocation(xPos, yPos); + goOffense = true; + } + } + } + } + if(rc.isCoreReady() && goOffense){ + RESOURCE_FUNCTIONS.BUG(enemyArchonLocation); + } + if(rc.isWeaponReady()){ + RESOURCE_FUNCTIONS.attackWeakestEnemy(); + } + Clock.yield(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + } /** * * Class Turret From 6d455f967ffb41da7e1e5c618e7eab23ae66a028 Mon Sep 17 00:00:00 2001 From: katiekang1998 Date: Wed, 13 Jan 2016 18:15:04 -0500 Subject: [PATCH 4/7] new turrent and ttm class the ttm will go towards the enemy archons until it is within attack range, and then turn into a turret that attacks the weakest enemy. --- RobotPlayer.java | 78 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 1f0f175..c50c736 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -63,6 +63,14 @@ else if(selftype == RobotType.VIPER){ Viper s = new RobotPlayer().new Viper(); s.run(); } + else if(selftype == RobotType.TURRET){ + Turret s = new RobotPlayer().new Turret(); + s.run(); + } + else if(selftype == RobotType.TTM){ + TTM s = new RobotPlayer().new TTM(); + s.run(); + } } /** @@ -113,7 +121,7 @@ public void run() { } } - /** +/** * * Class Turret * @@ -122,22 +130,77 @@ public void run() { */ private class Turret{ - MapLocation enemyLocation; + //MapLocation enemyLocation; + public MapLocation enemyArchonLocation; + public Turret(){ } + public void run(){ + while(true){ + try{Signal[] signals = rc.emptySignalQueue(); + if (signals.length > 0) { + for (Signal s : signals) { + // receive a message containing enemy archon ID + if (s.getTeam() == ourTeam) { + FancyMessage f = FancyMessage.getFromRecievedSignal(s); + if(f.type == 2){ + int xPos = f.ints.first; + int yPos = f.ints.second; + enemyArchonLocation = new MapLocation(xPos, yPos); + } + } + } + } + if(enemyArchonLocation.distanceSquaredTo(rc.getLocation())>40){ + rc.pack(); + } + else if(rc.isWeaponReady()){ + RESOURCE_FUNCTIONS.attackWeakestEnemy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + private class TTM{ + + //MapLocation enemyLocation; + public MapLocation enemyArchonLocation; + //public boolean goOffense; + + public TTM(){ + + } + public void run(){ while(true){ try{ - - if(rc.isWeaponReady()){ - enemyLocation = RESOURCE_FUNCTIONS.locateStrongestEnemy(); - if(rc.canAttackLocation(enemyLocation)){ - rc.attackLocation(enemyLocation); + Signal[] signals = rc.emptySignalQueue(); + if (signals.length > 0) { + for (Signal s : signals) { + // receive a message containing enemy archon ID + if (s.getTeam() == ourTeam) { + FancyMessage f = FancyMessage.getFromRecievedSignal(s); + if(f.type == 2){ + int xPos = f.ints.first; + int yPos = f.ints.second; + enemyArchonLocation = new MapLocation(xPos, yPos); + } + } } } + if(enemyArchonLocation.distanceSquaredTo(rc.getLocation())<40){ + rc.unpack(); + } + + if(rc.isCoreReady()){ + RESOURCE_FUNCTIONS.BUG(enemyArchonLocation); + } } catch (Exception e) { e.printStackTrace(); @@ -145,6 +208,7 @@ public void run(){ } } } + /** * Class Soldier * From 6824fe6d20f3a12fd05a97bae08769f21ebc92b2 Mon Sep 17 00:00:00 2001 From: androidmage Date: Thu, 14 Jan 2016 13:59:34 -0500 Subject: [PATCH 5/7] Implemented vipers but doesn't work very well --- RobotPlayer.java | 77 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index c50c736..6db2994 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -111,7 +111,10 @@ public void run() { RESOURCE_FUNCTIONS.BUG(enemyArchonLocation); } if(rc.isWeaponReady()){ - RESOURCE_FUNCTIONS.attackWeakestEnemy(); + MapLocation target = RESOURCE_FUNCTIONS.viperAttackTarget(); + if(rc.canAttackLocation(target)){ + rc.attackLocation(target); + } } Clock.yield(); } catch (Exception e) { @@ -387,6 +390,9 @@ public void run() { * */ private class Archon{ + + public boolean ViperProduction; + public boolean production; /** * Constructor @@ -394,6 +400,8 @@ private class Archon{ */ public Archon(){ zombieRounds = rc.getZombieSpawnSchedule().getRounds(); + ViperProduction = false; + production = true; } /** @@ -410,10 +418,19 @@ public void run(){ for(int i = 0; i < signals.length; i++){ if(signals[i].getTeam() == ourTeam){ FancyMessage x = FancyMessage.getFromRecievedSignal(signals[i]); + System.out.println("type is " + x.type); if(x.isMessage){ if(x.type == 2){ mostRecentEnemyArchonLocations.add(new Triple(0,new MapLocation(x.ints.first - 16000,x.ints.second - 16000),rc.getRoundNum())); } + if(x.type == 3){ + production = false; + ViperProduction = false; + } + if(x.type == 4){ + production = true; + ViperProduction = false; + } } } } @@ -424,7 +441,19 @@ public void run(){ FancyMessage.sendMessage(1, 1, 1, 3); } RobotType type = RESOURCE_FUNCTIONS.chooseRobotType(); - if(rc.isCoreReady() && RESOURCE_FUNCTIONS.tryBuild(type)){ //See function in RESOURCE_FUNCTIONS to know what it does + if(!ViperProduction && production && type == RobotType.VIPER){ + production = false; + ViperProduction = true; + FancyMessage.sendMessage(3, 0, 0, 1000); + } + if(!production && ViperProduction && RESOURCE_FUNCTIONS.tryBuild(RobotType.VIPER)){ + ViperProduction = false; + System.out.println("success"); + production = true; + FancyMessage.sendMessage(4, 0, 0, 1000); + type = RESOURCE_FUNCTIONS.chooseRobotType(); + } + if(rc.isCoreReady() && production && RESOURCE_FUNCTIONS.tryBuild(type)){ //See function in RESOURCE_FUNCTIONS to know what it does //After building scout, waits a turn, then signals it the location, so it has a good idea of where base is //Also signals the scout which type to become Clock.yield(); @@ -866,22 +895,25 @@ public static RobotType chooseRobotType() { return RobotType.SCOUT; } } - if(Math.random()*3>1) { - return RobotType.SCOUT; - } if(almostSurrounded()){ return RobotType.SCOUT; } if(numberOfRobotsInRadiusAndThoseRobots(RobotType.GUARD,3,ourTeam).first == 7){ return RobotType.SCOUT; } - int fate = randall.nextInt(3); - if(fate == 0){ + int fate = randall.nextInt(10); + if(fate < 3){ return RobotType.SOLDIER; } - if(fate == 1){ + if(fate > 6){ return RobotType.SCOUT; } + if(fate == 4){ + int more_fate = randall.nextInt(2); + if(!RESOURCE_FUNCTIONS.zombiesNearby() && more_fate == 0){ + return RobotType.VIPER; + } + } return RobotType.GUARD; } /** @@ -1157,6 +1189,35 @@ public static MapLocation locateStrongestEnemy(){ } return null; } + public static boolean zombiesNearby(){ + RobotInfo[] enemies = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, Team.ZOMBIE); + if(enemies != null && enemies.length > 1){ + return true; + } + return false; + } + public static MapLocation viperAttackTarget(){ + RobotInfo[] sensedRobots = rc.senseNearbyRobots(RobotType.VIPER.attackRadiusSquared, opponentTeam); + RobotInfo target = null; + if(sensedRobots != null){ + for(RobotInfo robot: sensedRobots){ + if(target == null || robot.health Date: Sun, 17 Jan 2016 13:09:04 -0500 Subject: [PATCH 6/7] Archon production and rubble clearing update --- RobotPlayer.java | 109 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 35 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 6db2994..9350747 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -85,7 +85,8 @@ private class Viper{ public boolean goOffense; public Viper() { - goOffense = false; + enemyArchonLocation = rc.getInitialArchonLocations(opponentTeam)[0]; + goOffense = true; } public void run() { @@ -112,9 +113,15 @@ public void run() { } if(rc.isWeaponReady()){ MapLocation target = RESOURCE_FUNCTIONS.viperAttackTarget(); - if(rc.canAttackLocation(target)){ + if(target != null && rc.canAttackLocation(target)){ rc.attackLocation(target); } + else{ + Direction rubbleDirection = RESOURCE_FUNCTIONS.clearRubbleForPath(enemyArchonLocation); + if(rubbleDirection != null){ + rc.clearRubble(rubbleDirection); + } + } } Clock.yield(); } catch (Exception e) { @@ -225,7 +232,9 @@ private class Soldier { public int moveCount; public Soldier() { + enemyArchonLocation = rc.getInitialArchonLocations(opponentTeam)[0]; moveCount = 0; + goOffense = true; } public void run() { @@ -272,6 +281,12 @@ public void run() { } }*/ RESOURCE_FUNCTIONS.attackWeakestEnemy(); + if(rc.isWeaponReady()){ + Direction rubbleDirection = RESOURCE_FUNCTIONS.clearRubbleForPath(enemyArchonLocation); + if(rubbleDirection != null){ + rc.clearRubble(rubbleDirection); + } + } } // If there are enough scouts around, move out towards enemy Archon /* (mostRecentEnemyArchonLocations.size() > 0 && RESOURCE_FUNCTIONS.numberOfRobotsInRadiusAndThoseRobots(RobotType.SOLDIER, RobotType.SOLDIER.sensorRadiusSquared, rc.getTeam()).first > 5) { @@ -374,6 +389,12 @@ public void run() { RESOURCE_FUNCTIONS.BUG(target); } } + if(rc.isWeaponReady()){ + Direction rubbleDirection = RESOURCE_FUNCTIONS.nearestRubble(); + if(rubbleDirection != null){ + rc.clearRubble(rubbleDirection); + } + } } Clock.yield(); }catch(Exception e){ @@ -391,8 +412,8 @@ public void run() { */ private class Archon{ - public boolean ViperProduction; public boolean production; + public RobotType decision; /** * Constructor @@ -400,7 +421,7 @@ private class Archon{ */ public Archon(){ zombieRounds = rc.getZombieSpawnSchedule().getRounds(); - ViperProduction = false; + decision = null; production = true; } @@ -425,45 +446,40 @@ public void run(){ } if(x.type == 3){ production = false; - ViperProduction = false; } if(x.type == 4){ production = true; - ViperProduction = false; } } } } //If it can, always tries to build Scouts. if(rc.isCoreReady()){ - RESOURCE_FUNCTIONS.escapeEnemy(); if(rc.getRoundNum() % 100 == 0){ FancyMessage.sendMessage(1, 1, 1, 3); } - RobotType type = RESOURCE_FUNCTIONS.chooseRobotType(); - if(!ViperProduction && production && type == RobotType.VIPER){ - production = false; - ViperProduction = true; - FancyMessage.sendMessage(3, 0, 0, 1000); - } - if(!production && ViperProduction && RESOURCE_FUNCTIONS.tryBuild(RobotType.VIPER)){ - ViperProduction = false; - System.out.println("success"); - production = true; - FancyMessage.sendMessage(4, 0, 0, 1000); - type = RESOURCE_FUNCTIONS.chooseRobotType(); + if(decision == null){ + decision = RESOURCE_FUNCTIONS.chooseRobotType(); } - if(rc.isCoreReady() && production && RESOURCE_FUNCTIONS.tryBuild(type)){ //See function in RESOURCE_FUNCTIONS to know what it does - //After building scout, waits a turn, then signals it the location, so it has a good idea of where base is - //Also signals the scout which type to become - Clock.yield(); - Triple scoutType = getScoutInitType(); - //Check if near zombie round - if (mostRecentEnemyArchonLocations.size() != 0 && RESOURCE_FUNCTIONS.isCloseToZombieSpawnRound()) { - scoutType = getScoutHerdingType(); + if(rc.isCoreReady() && production){ + if(RESOURCE_FUNCTIONS.tryBuild(decision)){ //See function in RESOURCE_FUNCTIONS to know what it does + //After building scout, waits a turn, then signals it the location, so it has a good idea of where base is + //Also signals the scout which type to become + FancyMessage.sendMessage(4, 0, 0, 6400); + Clock.yield(); + decision = null; + Triple scoutType = getScoutInitType(); + //Check if near zombie round + if (mostRecentEnemyArchonLocations.size() != 0 && RESOURCE_FUNCTIONS.isCloseToZombieSpawnRound()) { + scoutType = getScoutHerdingType(); + } + FancyMessage.sendMessage(0,scoutType.first | scoutType.second,scoutType.third,3); + } + else{ + FancyMessage.sendMessage(3, 0, 0, 6400); } - FancyMessage.sendMessage(0,scoutType.first | scoutType.second,scoutType.third,3); } + RESOURCE_FUNCTIONS.escapeEnemy(); } Clock.yield(); }catch(Exception e){ @@ -902,15 +918,14 @@ public static RobotType chooseRobotType() { return RobotType.SCOUT; } int fate = randall.nextInt(10); - if(fate < 3){ + if(fate < 4){ return RobotType.SOLDIER; } - if(fate > 6){ + if(fate == 9){ return RobotType.SCOUT; } - if(fate == 4){ - int more_fate = randall.nextInt(2); - if(!RESOURCE_FUNCTIONS.zombiesNearby() && more_fate == 0){ + if(fate == 8){ + if(!RESOURCE_FUNCTIONS.zombiesNearby()){ return RobotType.VIPER; } } @@ -1205,7 +1220,9 @@ public static MapLocation viperAttackTarget(){ target=robot; } } - return target.location; + if(target != null){ + return target.location; + } } sensedRobots = rc.senseNearbyRobots(RobotType.VIPER.attackRadiusSquared, Team.ZOMBIE); if(sensedRobots != null){ @@ -1214,7 +1231,29 @@ public static MapLocation viperAttackTarget(){ target=robot; } } - return target.location; + if(target != null){ + return target.location; + } + } + return null; + } + public static Direction clearRubbleForPath(MapLocation enemyArchonLocation){ + Direction enemyArchonDirection = rc.getLocation().directionTo(enemyArchonLocation); + if(enemyArchonDirection != null && rc.senseRubble(rc.getLocation().add(enemyArchonDirection)) > 0){ + return enemyArchonDirection; + } + return null; + } + public static Direction nearestRubble(){ + for(Direction direction: DIRECTIONS){ + if(rc.senseRubble(rc.getLocation().add(direction)) > 100){ + return direction; + } + } + for(Direction direction: DIRECTIONS){ + if(rc.senseRubble(rc.getLocation().add(direction)) > 50){ + return direction; + } } return null; } From b9bd23bc927fd9f018c0eb73bf7ecad1c41a6c9e Mon Sep 17 00:00:00 2001 From: androidmage Date: Sun, 17 Jan 2016 23:34:31 -0500 Subject: [PATCH 7/7] Archons activate neutral robots and find parts --- RobotPlayer.java | 62 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 9350747..f6f0efd 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -455,6 +455,10 @@ public void run(){ } //If it can, always tries to build Scouts. if(rc.isCoreReady()){ + MapLocation neutral = RESOURCE_FUNCTIONS.findAdjacentNeutralRobot(); + if(neutral != null){ + rc.activate(neutral); + } if(rc.getRoundNum() % 100 == 0){ FancyMessage.sendMessage(1, 1, 1, 3); } @@ -479,7 +483,7 @@ public void run(){ FancyMessage.sendMessage(3, 0, 0, 6400); } } - RESOURCE_FUNCTIONS.escapeEnemy(); + movement(); } Clock.yield(); }catch(Exception e){ @@ -499,6 +503,29 @@ public Triple getScoutHerdingType(){ int yPosition = (enemyArchonLocation.y + 16000); return new Triple(1,xPosition,yPosition); } + + public void movement(){ + try{ + if(rc.senseHostileRobots(rc.getLocation(), RobotType.ARCHON.sensorRadiusSquared) != null){ + RESOURCE_FUNCTIONS.escapeEnemy(); + } + if(rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, Team.NEUTRAL) != null){ + RobotInfo neutral = RESOURCE_FUNCTIONS.seekNeutralRobots(); + if(neutral != null){ + RESOURCE_FUNCTIONS.BUG(neutral.location); + } + } + if(rc.sensePartLocations(RobotType.ARCHON.sensorRadiusSquared) != null){ + MapLocation part = RESOURCE_FUNCTIONS.seekNearestPart(); + if(part != null){ + RESOURCE_FUNCTIONS.BUG(part); + } + } + } + catch(Exception e){ + e.printStackTrace(); + } + } } /** @@ -1257,6 +1284,39 @@ public static Direction nearestRubble(){ } return null; } + public static RobotInfo seekNeutralRobots(){ + RobotInfo[] neutrals = rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, Team.NEUTRAL); + RobotInfo closest = null; + int smallestDistance = 100; + for(RobotInfo neutral: neutrals){ + if(closest == null || rc.getLocation().distanceSquaredTo(neutral.location) < smallestDistance){ + closest = neutral; + smallestDistance = rc.getLocation().distanceSquaredTo(neutral.location); + } + } + return closest; + } + public static MapLocation findAdjacentNeutralRobot(){ + RobotInfo[] neutrals = rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, Team.NEUTRAL); + for(RobotInfo neutral: neutrals){ + if(neutral != null && rc.getLocation().isAdjacentTo(neutral.location)){ + return neutral.location; + } + } + return null; + } + public static MapLocation seekNearestPart(){ + MapLocation[] parts = rc.sensePartLocations(RobotType.ARCHON.sensorRadiusSquared); + MapLocation closest = null; + int smallestDistance = 100; + for(MapLocation part: parts){ + if(closest == null || rc.getLocation().distanceSquaredTo(part) < smallestDistance){ + closest = part; + smallestDistance = rc.getLocation().distanceSquaredTo(part); + } + } + return closest; + } }