public void sanction(Soldiers s) { // punish all the soldiers form this capo instead of a single soldier // s.AcceptSanctionForExtortedShopOfOtherCapo(); for (int i = 0; i < soldiers.size(); i++) { Soldiers so = (Soldiers) soldiers.get(i); so.AcceptSanctionForExtortedShopOfOtherCapo(); } }
public void giveExtorsionMoney(double amount, Soldiers soldier, Shop shop, Color territory) { // store money // distribute money // 50 persent for capos, then rest for solidiers System.out.println( "capo #" + this.getIndex() + "cummulatedIncome = " + cummulatedIncome + "extorsionCount = " + extorsionCount); extorsionCount++; cummulatedIncome += amount * 0.5; soldier.setMoney(soldier.getMoney() + amount * 0.5); System.out.println("capo #" + index + " has now: $" + cummulatedIncome); // draw edges between Capo and by own soldiers extorted shops Context<Object> context = ContextUtils.getContext(this); Network<Object> net = (Network<Object>) context.getProjection("network"); net.addEdge(this, shop); // sanction if money from shop from other territory if (!territory.equals(familyColor)) { // decision process --> preliminary! --- TODO: could be implemented // with EMIL-S notPermittedExtorsionCount++; double rnd = RandomHelper.nextDoubleFromTo(0.0, 1.0); if (rnd <= sanctionProbability) { soldier.sanction(shop, territory); sanctionCount++; } } // notify the mandamento if (this != mandamento.getCapo()) { mandamento.onExtortMoney(index, cummulatedIncome); } }
/** Initialisation of Capo agent */ public void linkin() { System.out.println("Objects assigned to Capo #" + index + ", " + this.toString() + ": "); GridPoint pt = grid.getLocation(this); // finde Farbe des Territoriums auf dem der Capo sich befindet und setze // eigene Familienfarbe entsprechend for (Object obj : grid.getObjectsAt(pt.getX(), pt.getY())) { if (obj instanceof TerritoryMarker) { familyColor = ((TerritoryMarker) obj).getTerritoryColor(); break; } } // Ordne alle Soldaten und Shops auf dem Territorium dem Capo zu Iterable allObjects = grid.getObjects(); for (Object object : allObjects) { // finde Farbe des Territoriums auf dem sich das aktuelle Objekt // befindet Color c = Color.BLACK; GridPoint objLocation = grid.getLocation(object); for (Object obj : grid.getObjectsAt(objLocation.getX(), objLocation.getY())) { if (obj instanceof TerritoryMarker) { c = ((TerritoryMarker) obj).getTerritoryColor(); break; } } // Wenn Object auf Territorium der Familie (entspr. gleiche Farbe), // dann... if (familyColor.equals(c)) { // System.out.print(" Soldiers: "); // Soldat zuordnen if (object instanceof Soldiers) { Soldiers soldier = (Soldiers) object; soldiers.add(soldier); soldier.setMycapo(this); System.out.print(soldier.toString() + " "); } // System.out.print("\n Shops: "); // Shop zuordnen if (object instanceof Shop) { Shop shop = (Shop) object; shop.setCapo(this); shops.add(shop); System.out.print(shop.toString() + " "); } } } // for (int x=pt.getX(); x<pt.getX()+25; x++) // for(int y=pt.getY(); y<pt.getY()+25;y++){ // Object obj=grid.getObjectsAt(x,y); // // System.out.print(obj.toString()+" "); // if (obj instanceof UnremoveableIterator){ // UnremoveableIterator iter = (UnremoveableIterator)obj; // while (iter.hasNext()){ // Object element =iter.next(); // if (element instanceof Soldiers) { // Soldiers s = (Soldiers) element; // soldiers.add(s); // s.setMycapo(this); // } // System.out.print(element.toString()+" "); // } // // // // System.out.print(obj.toString()+" "); // } // } System.out.println(); // for (Object obj:grid.getObjectsAt(pt.getX(), pt.getY())){ // if (obj instanceof Soldiers){ // soldiers.add(obj); // } // } // if (soldiers.size()>0){ // int index = RandomHelper.nextIntFromTo(0, 5); // Object obj = soldiers.get(index); // ArrayList<Soldiers> soldiers1 ; // NdPoint spacePt = space.getLocation(obj); // Context<Object> context = ContextUtils.getContext(obj); // space.moveTo(soldiers, spacePt.getX(), spacePt.getY()); // grid.moveTo(soldiers, pt.getX(), pt.getY()); // // // // Network<Object> net // =(Network<Object>)context.getProjection("network"); // net.addEdge(this, soldiers); // // } }