Archived
1
0

-Implemented most of Steal

-Started Attack

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-06-04 22:35:53 -07:00
parent a0e3d07a90
commit b7c5991a7a
12 changed files with 220 additions and 19 deletions

Binary file not shown.

Binary file not shown.

View File

@ -37,4 +37,20 @@ public interface Drone extends GameObject {
*/ */
public EnumMove move(); public EnumMove move();
/**
* Asks for which drone should be stolen from. Will be called whenever the
* Move method returns Steal.
*
* @return <code>Neighbor</code>;
*/
public Neighbor steal();
/**
* Asks for which drone should be attacked. Will be called whenever the Move
* method returns Attack.
*
* @return <code>Neighbor</code>
*/
public Neighbor attack();
} }

View File

@ -36,10 +36,12 @@ public class DroneListItem {
private int lumaLocatorDistance; private int lumaLocatorDistance;
private int objectLocatorDistance; private int objectLocatorDistance;
private int reliability; 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 speed; // Reflected in movements per turn
private int cargoSpace; private int cargoSpace;
private int theft; private int theft; // Between 1 and 2 - reflects how well can steal
// Info about this robot // Info about this robot
@ -209,6 +211,10 @@ public class DroneListItem {
return team; return team;
} }
public boolean getInventoryIsFull() {
return inventory.size() >= cargoSpace;
}
/** /**
* Sets the next DroneListItem in the Linked List * Sets the next DroneListItem in the Linked List
* *
@ -335,11 +341,11 @@ public class DroneListItem {
return true; return true;
} }
case Attack: { case Attack: {
// TODO - Implement attack doAttack();
return true; return true;
} }
case Steal: { case Steal: {
// TODO - Implement steal doSteal();
return true; return true;
} }
default: { default: {
@ -351,6 +357,93 @@ public class DroneListItem {
// Movement // 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) { private void moveDrone(Direction direction) {
if (waiting != 0) { if (waiting != 0) {
waiting--; waiting--;

View File

@ -140,7 +140,7 @@ public class DroneTools {
if (objectHere instanceof Drone) { if (objectHere instanceof Drone) {
Drone droneHere = (Drone) objectHere; Drone droneHere = (Drone) objectHere;
DroneListItem listItemHere = Nomads.droneToListItem(droneHere); 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); neighbors.add(aWildNeighbor);
} }
} }

View File

@ -8,6 +8,7 @@ public class Neighbor implements GameObject {
private String name; private String name;
private int x; private int x;
private int y; private int y;
private String UID;
/** /**
* Class Constructor * Class Constructor
@ -19,10 +20,11 @@ public class Neighbor implements GameObject {
* @param name * @param name
* - Name of the Drone * - 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.x = x;
this.y = y; this.y = y;
this.name = name; this.name = name;
this.UID = UID;
} }
@Override @Override
@ -48,6 +50,15 @@ public class Neighbor implements GameObject {
return y; return y;
} }
/**
* Retrieve UID of this Neighbor
*
* @return <code>String</code> - UID
*/
public String getUID() {
return UID;
}
@Override @Override
public void setName(String newName) { public void setName(String newName) {
name = newName; name = newName;

View File

@ -172,10 +172,33 @@ public class Nomads {
} }
} }
/**
* Matches a Drone to a DroneListItem
*
* @param theDrone
* <code>Drone</code> to be found
* @return <code>DroneListItem</code>
*/
public static DroneListItem droneToListItem(Drone theDrone) { public static DroneListItem droneToListItem(Drone theDrone) {
for (DroneTeam team : allTeams) { for (DroneTeam team : allTeams) {
DroneListItem current = team.getFirst(); 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
* <code>String</code> UID that needs to be found
* @return <code>DroneListItem</code>
*/
public static DroneListItem UIDToListItem(String UID) {
for (DroneTeam team : allTeams) {
DroneListItem current = team.getFirst();
if (current.getCurrent().getUID().equals(UID))
return current; return current;
} }
return null; return null;

View File

@ -113,9 +113,57 @@ public class World {
* GameObject to be placed * GameObject to be placed
*/ */
public void setObjectAt(int x, int y, GameObject newItem) { public void setObjectAt(int x, int y, GameObject newItem) {
if (theWorld[x][y] == null) {
theWorld[x][y] = newItem; theWorld[x][y] = newItem;
// TODO - Make sure this spot is free. } else {
// If it is not, then move somewhere close by 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 <code>Point</code>
*/
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 * @param x
* - X Index * - X Index
@ -218,8 +267,17 @@ public class World {
* @return <code>ArrayList(building)</code> * @return <code>ArrayList(building)</code>
*/ */
public ArrayList<Building> buildingsInRange(int x, int y, int range) { public ArrayList<Building> buildingsInRange(int x, int y, int range) {
// TODO - Implement buildingsInRange ArrayList<Building> allBuildings = new ArrayList<Building>();
return null;
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;
} }
/** /**