diff --git a/bin/net/grosinger/nomads/Drone.class b/bin/net/grosinger/nomads/Drone.class index 7221005..f344d59 100644 Binary files a/bin/net/grosinger/nomads/Drone.class and b/bin/net/grosinger/nomads/Drone.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem.class b/bin/net/grosinger/nomads/DroneListItem.class index 47e8905..3ad8935 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem.class and b/bin/net/grosinger/nomads/DroneListItem.class differ diff --git a/bin/net/grosinger/nomads/DroneTools.class b/bin/net/grosinger/nomads/DroneTools.class index 0df9340..d871885 100644 Binary files a/bin/net/grosinger/nomads/DroneTools.class and b/bin/net/grosinger/nomads/DroneTools.class differ diff --git a/bin/net/grosinger/nomads/Neighbor.class b/bin/net/grosinger/nomads/Neighbor.class index 4f03424..93fb961 100644 Binary files a/bin/net/grosinger/nomads/Neighbor.class and b/bin/net/grosinger/nomads/Neighbor.class differ diff --git a/bin/net/grosinger/nomads/Nomads.class b/bin/net/grosinger/nomads/Nomads.class index a99c266..200d79b 100644 Binary files a/bin/net/grosinger/nomads/Nomads.class and b/bin/net/grosinger/nomads/Nomads.class differ diff --git a/bin/net/grosinger/nomads/World.class b/bin/net/grosinger/nomads/World.class index 19bfcfc..79239a4 100644 Binary files a/bin/net/grosinger/nomads/World.class and b/bin/net/grosinger/nomads/World.class differ diff --git a/src/net/grosinger/nomads/Drone.java b/src/net/grosinger/nomads/Drone.java index 354b846..0cb2716 100644 --- a/src/net/grosinger/nomads/Drone.java +++ b/src/net/grosinger/nomads/Drone.java @@ -13,14 +13,14 @@ public interface Drone extends GameObject { * basic info your drone needs. */ public void setDroneTools(DroneTools yourTools); - + /** * A Unique Identifier * * @param UID */ public void setUID(String UID); - + /** * Retrieve UID * @@ -37,4 +37,20 @@ public interface Drone extends GameObject { */ public EnumMove move(); + /** + * Asks for which drone should be stolen from. Will be called whenever the + * Move method returns Steal. + * + * @return Neighbor; + */ + public Neighbor steal(); + + /** + * Asks for which drone should be attacked. Will be called whenever the Move + * method returns Attack. + * + * @return Neighbor + */ + public Neighbor attack(); + } diff --git a/src/net/grosinger/nomads/DroneListItem.java b/src/net/grosinger/nomads/DroneListItem.java index 48a83c9..376bca2 100644 --- a/src/net/grosinger/nomads/DroneListItem.java +++ b/src/net/grosinger/nomads/DroneListItem.java @@ -36,10 +36,12 @@ public class DroneListItem { private int lumaLocatorDistance; private int objectLocatorDistance; private int reliability; - private int defenses; + private int attack; // Between 1 and 2 - reflects how well can attack + private int defenses; // Between 1 and 2 - reflects ability to block + // steal private int speed; // Reflected in movements per turn private int cargoSpace; - private int theft; + private int theft; // Between 1 and 2 - reflects how well can steal // Info about this robot @@ -209,6 +211,10 @@ public class DroneListItem { return team; } + public boolean getInventoryIsFull() { + return inventory.size() >= cargoSpace; + } + /** * Sets the next DroneListItem in the Linked List * @@ -335,11 +341,11 @@ public class DroneListItem { return true; } case Attack: { - // TODO - Implement attack + doAttack(); return true; } case Steal: { - // TODO - Implement steal + doSteal(); return true; } default: { @@ -351,6 +357,93 @@ public class DroneListItem { // Movement + /** + * Finds who the drone wants to attack and attempts to perform attack. + */ + private void doAttack() { + Neighbor victimNeighbor = current.attack(); + + if (victimNeighbor == null) { + // Seems they did something wrong. Turn wasted. + return; + } + + DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID()); + + int victimDefence = victimList.getDefenses(); + + // Find a random number between 0-100 to determine success. + // Min + (int)(Math.random() * ((Max - Min) + 1)) + int rand = 0 + (int) (Math.random() * ((100 - 0) + 1)); + + // Find modified random number based on stats + int newRand = rand * (victimDefence - attack) * -1; + newRand += rand; + + // If number is <= 35, drone becomes wanted + // If number is <= 70, steal fails + // If number is > 70, steal + // Depending on how much higher than 70, more items will be stolen + + // TODO - Continue implementing attack + } + + /** + * Finds who the drone wants to steal from and attempts to perform steal. + */ + private void doSteal() { + Neighbor victimNeighbor = current.steal(); + + if (victimNeighbor == null) { + // Seems they did something wrong. Turn wasted. + return; + } + + DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID()); + + int victimDefence = victimList.getDefenses(); + + // Find a random number between 0-100 to determine success. + // Min + (int)(Math.random() * ((Max - Min) + 1)) + int rand = 0 + (int) (Math.random() * ((100 - 0) + 1)); + + // Find modified random number based on stats + int newRand = rand * (victimDefence - theft) * -1; + newRand += rand; + + // If number is <= 35, drone becomes wanted + // If number is <= 70, steal fails + // If number is > 70, steal + // Depending on how much higher than 70, more items will be stolen + + int itemsInVictimInventory = victimList.inventory.size(); + Double percentToTake = .00; + + if (newRand <= 35) { + // TODO - Implement wanted + } else if (newRand <= 70) { + percentToTake = .00; + } else if (newRand > 70 && newRand <= 80) { + percentToTake = .2; + } else if (newRand > 80 && newRand >= 90) { + percentToTake = .4; + } else if (newRand >= 100 && newRand <= 98) { + percentToTake = .7; + } else if (newRand > 98) { + percentToTake = 1.0; + } else { + // Not sure what happened here + } + + int itemsToTake = (int) Math.ceil(itemsInVictimInventory * percentToTake); + while (itemsToTake < 0 && !getInventoryIsFull() && victimList.inventory.size() > 0) { + // Min + (int)(Math.random() * ((Max - Min) + 1)) + int randIndex = 0 + (int) (Math.random() * (((victimList.inventory.size() - 1) - 0) + 1)); + inventory.add(victimList.inventory.get(randIndex)); + victimList.inventory.remove(randIndex); + } + } + private void moveDrone(Direction direction) { if (waiting != 0) { waiting--; diff --git a/src/net/grosinger/nomads/DroneTools.java b/src/net/grosinger/nomads/DroneTools.java index dc23b7e..cf4d761 100644 --- a/src/net/grosinger/nomads/DroneTools.java +++ b/src/net/grosinger/nomads/DroneTools.java @@ -140,7 +140,7 @@ public class DroneTools { if (objectHere instanceof Drone) { Drone droneHere = (Drone) objectHere; DroneListItem listItemHere = Nomads.droneToListItem(droneHere); - Neighbor aWildNeighbor = new Neighbor(listItemHere.getX(), listItemHere.getY(), droneHere.getName()); + Neighbor aWildNeighbor = new Neighbor(listItemHere.getX(), listItemHere.getY(), droneHere.getName(), droneHere.getUID()); neighbors.add(aWildNeighbor); } } diff --git a/src/net/grosinger/nomads/Neighbor.java b/src/net/grosinger/nomads/Neighbor.java index 6c5f303..cfbf37d 100644 --- a/src/net/grosinger/nomads/Neighbor.java +++ b/src/net/grosinger/nomads/Neighbor.java @@ -8,6 +8,7 @@ public class Neighbor implements GameObject { private String name; private int x; private int y; + private String UID; /** * Class Constructor @@ -19,10 +20,11 @@ public class Neighbor implements GameObject { * @param name * - Name of the Drone */ - public Neighbor(int x, int y, String name) { + public Neighbor(int x, int y, String name, String UID) { this.x = x; this.y = y; this.name = name; + this.UID = UID; } @Override @@ -48,6 +50,15 @@ public class Neighbor implements GameObject { return y; } + /** + * Retrieve UID of this Neighbor + * + * @return String - UID + */ + public String getUID() { + return UID; + } + @Override public void setName(String newName) { name = newName; diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java index 9419e19..8359eeb 100644 --- a/src/net/grosinger/nomads/Nomads.java +++ b/src/net/grosinger/nomads/Nomads.java @@ -172,10 +172,33 @@ public class Nomads { } } + /** + * Matches a Drone to a DroneListItem + * + * @param theDrone + * Drone to be found + * @return DroneListItem + */ public static DroneListItem droneToListItem(Drone theDrone) { for (DroneTeam team : allTeams) { DroneListItem current = team.getFirst(); - if (current.getCurrent().getUID() == theDrone.getUID()) + if (current.getCurrent().getUID().equals(theDrone.getUID())) + return current; + } + return null; + } + + /** + * Matches a UID to a Drone + * + * @param UID + * String UID that needs to be found + * @return DroneListItem + */ + public static DroneListItem UIDToListItem(String UID) { + for (DroneTeam team : allTeams) { + DroneListItem current = team.getFirst(); + if (current.getCurrent().getUID().equals(UID)) return current; } return null; diff --git a/src/net/grosinger/nomads/World.java b/src/net/grosinger/nomads/World.java index c88e347..92db099 100644 --- a/src/net/grosinger/nomads/World.java +++ b/src/net/grosinger/nomads/World.java @@ -113,9 +113,57 @@ public class World { * GameObject to be placed */ public void setObjectAt(int x, int y, GameObject newItem) { - theWorld[x][y] = newItem; - // TODO - Make sure this spot is free. - // If it is not, then move somewhere close by + if (theWorld[x][y] == null) { + theWorld[x][y] = newItem; + } else { + Point here = findEmptyPoint(new Point(x, y)); + theWorld[here.getX()][here.getY()] = newItem; + } + } + + /** + * Find "closest" point that is available to the point provided + * + * @param currentPoint + * - Location of drone + * @return Point + */ + private Point findEmptyPoint(Point currentPoint) { + // Current point is where the drone is + boolean validSpace = theWorld[currentPoint.getX()][currentPoint.getY()] == null; + Point tryThis = new Point(currentPoint.getX(), currentPoint.getY()); + int outX = 1; + int outY = 0; + int multiplier = 1; + + while (!validSpace) { + tryThis.setX(currentPoint.getX() + (outX * multiplier)); + tryThis.setY(currentPoint.getY() + (outY * multiplier)); + if (theWorld[tryThis.getX()][tryThis.getY()] == null) + validSpace = true; + else { + if (outX == 1 && outY == 0) { + outY = 1; + } else if (outX == 1 && outY == 1) + outX = 0; + else if (outX == 0 && outY == 1) + outX = -1; + else if (outX == -1 && outY == 1) + outY = 0; + else if (outX == -1 && outY == 0) + outY = -1; + else if (outX == -1 && outY == -1) + outX = 0; + else if (outX == 0 && outY == -1) + outX = 1; + else if (outX == 1 && outY == -1) { + outY = 0; + outX = 1; + multiplier++; + } + } + } + return tryThis; } /** @@ -207,7 +255,8 @@ public class World { } /** - * Searches for any buildings within range spaces of x,y + * Searches for any buildings within range spaces of x,y. This returns a + * building and should not be given to a Drone * * @param x * - X Index @@ -218,8 +267,17 @@ public class World { * @return ArrayList(building) */ public ArrayList buildingsInRange(int x, int y, int range) { - // TODO - Implement buildingsInRange - return null; + ArrayList allBuildings = new ArrayList(); + + for (int i = -range; i <= range; i++) { + for (int j = -range; j <= range; j++) { + GameObject objectHere = theWorld[x + i][y + j]; + if (objectHere != null && objectHere instanceof Building) { + allBuildings.add((Building) objectHere); + } + } + } + return allBuildings; } /** @@ -250,10 +308,10 @@ public class World { Objective newObjective = new Objective(bounty, UID); setObjectAt(randX, randY, newObjective); - - //Create a point to return that is somewhere nearby the actual location - Point pointCloseBy = new Point(randX+varX, randY+varY); - + + // Create a point to return that is somewhere nearby the actual location + Point pointCloseBy = new Point(randX + varX, randY + varY); + return pointCloseBy; }