|
[Freecol-commits] freecol/src/net/sf/freecol/server/ai AIColony.java,1.5,1.6 AIPlayer.java,1.15,1.16
From: Stian Grenborgen <stiangre@us...> - 2005-10-16 09:51
|
Update of /cvsroot/freecol/freecol/src/net/sf/freecol/server/ai
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32441/src/net/sf/freecol/server/ai
Modified Files:
AIColony.java AIPlayer.java
Log Message:
Some bugfixes.
Index: AIPlayer.java
===================================================================
RCS file: /cvsroot/freecol/freecol/src/net/sf/freecol/server/ai/AIPlayer.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** AIPlayer.java 30 Sep 2005 16:07:08 -0000 1.15
--- AIPlayer.java 16 Oct 2005 09:50:57 -0000 1.16
***************
*** 224,240 ****
}
// Check if we can find a better site to work than a new colony:
! for (int i=0; i<unitWishes.length; i++) {
! wishList = unitWishes[i];
! for (int j=0; j<wishList.size(); j++) {
! WorkerWish ww = (WorkerWish) wishList.get(j);
! int turns = unit.getTurnsToReach(ww.getDestination().getTile());
! // TODO: Choose to build colony if the value of the wish is low.
! if (bestWish == null && turns < bestTurns || bestWish != null && (
! turns < bestTurns
! || turns == bestTurns && ww.getValue() > bestWish.getValue())) {
! bestWish = ww;
! bestTurns = turns;
! }
! }
}
if (bestWish != null) {
--- 224,242 ----
}
// Check if we can find a better site to work than a new colony:
! if (!hasFewColonies() || colonyTile == null || bestTurns > 10) {
! for (int i=0; i<unitWishes.length; i++) {
! wishList = unitWishes[i];
! for (int j=0; j<wishList.size(); j++) {
! WorkerWish ww = (WorkerWish) wishList.get(j);
! int turns = unit.getTurnsToReach(ww.getDestination().getTile());
! // TODO: Choose to build colony if the value of the wish is low.
! if (bestWish == null && turns < bestTurns
! || bestWish != null && (turns < bestTurns ||
! turns == bestTurns && ww.getValue() > bestWish.getValue())) {
! bestWish = ww;
! bestTurns = turns;
! }
! }
! }
}
if (bestWish != null) {
***************
*** 303,307 ****
--- 305,333 ----
}
+
+ /**
+ * This is a temporary method which are used for
+ * forcing the computer players into building more
+ * colonies. The method will be removed after the
+ * proper code for deciding wether a colony should
+ * be built or not has been implemented.
+ *
+ * @return <code>true</code> if the AI should build
+ * more colonies.
+ */
+ public boolean hasFewColonies() {
+ Iterator it = getPlayer().getColonyIterator();
+ int numberOfColonies = 0;
+ int numberOfWorkers = 0;
+ while (it.hasNext()) {
+ Colony c = (Colony) it.next();
+ numberOfColonies++;
+ numberOfWorkers += c.getUnitCount();
+ }
+ return numberOfColonies <= 2 || numberOfColonies >= 3
+ && numberOfWorkers / numberOfColonies > numberOfColonies - 2;
+ }
+
/**
* Maps <code>Transportable</code>s to carrier's using a
Index: AIColony.java
===================================================================
RCS file: /cvsroot/freecol/freecol/src/net/sf/freecol/server/ai/AIColony.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AIColony.java 30 Sep 2005 16:07:08 -0000 1.5
--- AIColony.java 16 Oct 2005 09:50:56 -0000 1.6
***************
*** 232,240 ****
}
}
! if (!wishFound) {
((AIUnit) ww.getTransportable()).setMission(null);
}
! }
! if (w instanceof GoodsWish) {
GoodsWish gw = (GoodsWish) w;
//TODO: check for a certain required amount?
--- 232,239 ----
}
}
! if (!wishFound && ww.getTransportable() != null) {
((AIUnit) ww.getTransportable()).setMission(null);
}
! } else if (w instanceof GoodsWish) {
GoodsWish gw = (GoodsWish) w;
//TODO: check for a certain required amount?
***************
*** 242,245 ****
--- 241,246 ----
newWishes.add(gw);
}
+ } else {
+ logger.warning("Unknown type of Wish.");
}
}
***************
*** 280,283 ****
--- 281,289 ----
continue;
}
+ if (goodsType == Goods.MUSKETS
+ && colony.getProductionOf(Goods.MUSKETS) > 0
+ && colony.getGoodsCount(Goods.MUSKETS) > colony.getWarehouseCapacity() - 50) {
+ continue;
+ }
if (colony.getGoodsCount(goodsType) > 0) {
List alreadyAdded = new ArrayList();
***************
*** 400,404 ****
if (unit.getExpertWorkType() == wlp.getGoodsType() && wlp.getWorkLocation().canAdd(unit)
&& (wlp.getGoodsType() != Goods.FOOD
! || !((ColonyTile) wl).getWorkTile().isLand() && unit.getType() == Unit.EXPERT_FISHERMAN
|| ((ColonyTile) wl).getWorkTile().isLand() && unit.getType() != Unit.EXPERT_FISHERMAN)) {
unit.setLocation(wlp.getWorkLocation());
--- 406,410 ----
if (unit.getExpertWorkType() == wlp.getGoodsType() && wlp.getWorkLocation().canAdd(unit)
&& (wlp.getGoodsType() != Goods.FOOD
! || !((ColonyTile) wl).getWorkTile().isLand() && unit.getType() == Unit.EXPERT_FISHERMAN && colony.getBuilding(Building.DOCK).isBuilt()
|| ((ColonyTile) wl).getWorkTile().isLand() && unit.getType() != Unit.EXPERT_FISHERMAN)) {
unit.setLocation(wlp.getWorkLocation());
|
| Thread | Author | Date |
|---|---|---|
| [Freecol-commits] freecol/src/net/sf/freecol/server/ai AIColony.java,1.5,1.6 AIPlayer.java,1.15,1.16 | Stian Grenborgen <stiangre@us...> |