• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java AIGoods类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中net.sf.freecol.server.ai.AIGoods的典型用法代码示例。如果您正苦于以下问题:Java AIGoods类的具体用法?Java AIGoods怎么用?Java AIGoods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

AIGoods类属于net.sf.freecol.server.ai包,在下文中一共展示了AIGoods类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testGetNextStopAlreadyAtDestination

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopAlreadyAtDestination() {
    Game game = ServerTestHelper.startServerGame(getCoastTestMap(plainsType));
    Map map = game.getMap();
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");
    dutch.exploreMap(true);
    
    // create a ship carrying a colonist
    Tile colonyTile = map.getTile(9, 9);
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    Unit galleon = new ServerUnit(game, colonyTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    TransportableAIObject goods = new AIGoods(aiMain, galleon, 
                                              horsesType, 50, colonyTile);
    mission.queueTransportable(goods, false, lb);

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertTrue("Unit should be already at the destination",
        Map.isSameLocation(dest, galleon.getLocation()));
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:33,
代码来源:TransportMissionTest.java

示例2: testGetNextStopIsEurope

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopIsEurope() {
    Game game = ServerTestHelper.startServerGame(getCoastTestMap(plainsType));
    Map map = game.getMap();
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer)game.getPlayerByNationId("model.nation.dutch");
    dutch.exploreMap(true);
    Europe europe = dutch.getEurope();
    assertNotNull("Setup error, europe is null", europe);

    // create a ship carrying a colonist in a colony
    Tile colonyTile = map.getTile(9, 9);
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    Unit galleon = new ServerUnit(game, colonyTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    TransportableAIObject goods = new AIGoods(aiMain, galleon,
                                              horsesType, 50, europe);
    assertTrue("Goods should queue",
               mission.queueTransportable(goods, false, lb));
    mission.doMission(lb);

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertEquals("Destination should be Europe", europe, dest);
    assertTrue("Unit should have a path", 
        galleon.getTurnsToReach(dest) < Unit.MANY_TURNS);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:38,
代码来源:TransportMissionTest.java

示例3: testGetNextStopIsColony

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopIsColony() {
    Game game = ServerTestHelper.startServerGame(getCoastTestMap(plainsType));
    Map map = game.getMap();
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer)game.getPlayerByNationId("model.nation.dutch");
    Europe europe = dutch.getEurope();
    assertNotNull("Setup error, europe is null", europe);

    Tile colonyTile = map.getTile(9, 9);
    assertTrue(colonyTile.isLand());
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    // create a ship
    Tile galleonTile = map.getTile(10, 9);
    assertFalse(galleonTile.isLand());
    Unit galleon = new ServerUnit(game, galleonTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    TransportableAIObject goods = new AIGoods(aiMain, galleon,
                                              horsesType, 50, colonyTile);
    goods.setTransportDestination(europe);
    mission.queueTransportable(goods, false, lb);
    mission.doMission(lb);

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertEquals("Destination should be the colony",
                 colonyTile.getColony(), dest);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:39,
代码来源:TransportMissionTest.java

示例4: testWagonTrain

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testWagonTrain() {
    Game game = ServerTestHelper.startServerGame(getTestMap());
    Colony one = getStandardColony(3, 3, 3);
    one.setName("one");
    Colony two = getStandardColony(3, 8, 8);
    two.setName("two");
    assertEquals(one.getOwner(), two.getOwner());

    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    Unit wagonTrain = new ServerUnit(game, one.getTile(),
        (ServerPlayer) one.getOwner(), wagonType);
    AIUnit wagon = aiMain.getAIUnit(wagonTrain);
    assertNotNull(wagon);

    wagon.setMission(null);
    assertNull("Transport mission should be valid.",
               TransportMission.invalidReason(wagon));
    TransportMission mission = new TransportMission(aiMain, wagon);

    Location dest = mission.getTarget();
    assertEquals("Destination should be colony one.", one, dest);

    wagonTrain.setLocation(one.getTile().getNeighbourOrNull(Direction.NE));
    dest = mission.getTarget();
    assertEquals("Destination should still be colony one.", one, dest);

    Goods goods = new Goods(game, two, horsesType, 20);
    two.addGoods(goods);
    AIGoods aiGoods = new AIGoods(aiMain, two, 
                                  goods.getType(), goods.getAmount(), one);
    mission.queueTransportable(aiGoods, false, lb);
    mission.doMission(lb);

    dest = mission.getTarget();
    assertEquals("Destination should now be colony two", two.getId(), dest.getId());
    assertEquals("Destination should now be colony two.", two, dest);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:40,
代码来源:TransportMissionTest.java

示例5: displayColonyPlan

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
/**
 * Debug action to display an AI colony plan.
 *
 * Called from tile popup menu.
 *
 * @param freeColClient The <code>FreeColClient</code> in effect.
 * @param colony The <code>Colony</code> to summarize.
 */
public static void displayColonyPlan(final FreeColClient freeColClient,
                                     final Colony colony) {
    final FreeColServer server = freeColClient.getFreeColServer();
    final AIMain aiMain = server.getAIMain();
    final AIColony aiColony = aiMain.getAIColony(colony);

    StringBuilder sb = new StringBuilder();
    if (aiColony == null) {
        sb.append(colony.getName() + "is not an AI colony.");
    } else {
        sb.append(aiColony.getColonyPlan().toString());
        sb.append("\n\nTILE IMPROVEMENTS:\n");
        for (TileImprovementPlan tip : aiColony.getTileImprovementPlans()) {
            sb.append(tip.toString());
            sb.append("\n");
        }
        sb.append("\n\nWISHES:\n");
        for (Wish w : aiColony.getWishes()) {
            sb.append(w.toString());
            sb.append("\n");
        }
        sb.append("\n\nEXPORT GOODS:\n");
        for (AIGoods aig : aiColony.getAIGoods()) {
            sb.append(aig.toString());
            sb.append("\n");
        }
    }

    freeColClient.getGUI().showInformationMessage(sb.toString());
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:39,
代码来源:DebugUtils.java

示例6: testGetNextStopAlreadyAtDestination

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopAlreadyAtDestination(){
    Map map = getCoastTestMap(plainsType);
    Game game = ServerTestHelper.startServerGame(map);
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer) game.getPlayer("model.nation.dutch");

    // create a ship carrying a colonist
    Tile colonyTile = map.getTile(9, 9);
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    Unit galleon = new ServerUnit(game, colonyTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    aiUnit.setMission(mission);
    Transportable goods = new AIGoods(aiMain,galleon, horsesType,50, colonyTile);
    mission.queueTransportable(goods, false);

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertTrue("Unit should be already at the destination",
        Map.isSameLocation(dest, galleon.getLocation()));
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:32,
代码来源:TransportMissionTest.java

示例7: testGetNextStopIsEurope

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopIsEurope() {
    Map map = getCoastTestMap(plainsType);
    Game game = ServerTestHelper.startServerGame(map);
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer)game.getPlayer("model.nation.dutch");
    Europe europe = dutch.getEurope();
    assertNotNull("Setup error, europe is null", europe);

    // create a ship carrying a colonist in a colony
    Tile colonyTile = map.getTile(9, 9);
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    Unit galleon = new ServerUnit(game, colonyTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    aiUnit.setMission(mission);
    Transportable goods = new AIGoods(aiMain, galleon, horsesType, 50,
                                      europe);
    mission.queueTransportable(goods, false);
    mission.doMission();

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertEquals("Destination should be Europe", europe, dest);
    assertFalse("Unit should have a path", 
                galleon.getTurnsToReach(dest) == FreeColObject.INFINITY);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:37,
代码来源:TransportMissionTest.java

示例8: testGetNextStopIsColony

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testGetNextStopIsColony() {
    Map map = getCoastTestMap(plainsType);
    Game game = ServerTestHelper.startServerGame(map);
    InGameController igc = ServerTestHelper.getInGameController();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    ServerPlayer dutch = (ServerPlayer)game.getPlayer("model.nation.dutch");
    Europe europe = dutch.getEurope();
    assertNotNull("Setup error, europe is null", europe);

    // create a ship carrying a colonist
    Tile colonyTile = map.getTile(9, 9);
    Tile galleonTile = map.getTile(9, 10);
    getStandardColony(1, colonyTile.getX(), colonyTile.getY());

    Unit galleon = new ServerUnit(game, galleonTile, dutch, galleonType);
    AIUnit aiUnit = aiMain.getAIUnit(galleon);
    assertNotNull(aiUnit);

    // assign transport mission to the ship
    TransportMission mission = new TransportMission(aiMain, aiUnit);
    aiUnit.setMission(mission);
    Transportable goods = new AIGoods(aiMain, galleon, horsesType, 50,
                                      colonyTile);
    mission.queueTransportable(goods, false);
    mission.doMission();

    // Exercise
    Location dest = mission.getTarget();

    // Test
    assertNotNull("Unit should have a destination", dest);
    assertEquals("Destination should be the colony",
                 colonyTile.getColony(), dest);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:37,
代码来源:TransportMissionTest.java

示例9: testWagonTrain

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
public void testWagonTrain() {
    Map map = getTestMap();
    Game game = ServerTestHelper.startServerGame(map);
    Colony one = getStandardColony(3, 3, 3);
    Colony two = getStandardColony(3, 8, 8);
    assertEquals(one.getOwner(), two.getOwner());

    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    assertNotNull(aiMain);

    Unit wagonTrain = new ServerUnit(game, one.getTile(),
        (ServerPlayer) one.getOwner(), wagonType);
    AIUnit wagon = aiMain.getAIUnit(wagonTrain);
    assertNotNull(wagon);

    wagon.abortMission("test");
    assertNull("Transport mission should be valid",
               TransportMission.invalidReason(wagon));
    TransportMission mission = new TransportMission(aiMain, wagon);

    Location dest = mission.getTarget();
    assertEquals("Destination should be colony one.", one, dest);

    wagonTrain.setLocation(one.getTile().getAdjacentTile(Map.Direction.NE));
    dest = mission.getTarget();
    assertEquals("Destination should still be colony one.", one, dest);

    AIGoods goods = new AIGoods(aiMain, two, horsesType, 20, one);
    mission.queueTransportable(goods, false);
    mission.doMission();

    dest = mission.getTarget();
    assertEquals("Destination should now be colony two.", two, dest);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:35,
代码来源:TransportMissionTest.java

示例10: dumpTransportable

点赞 2

import net.sf.freecol.server.ai.AIGoods; //导入依赖的package包/类
/**
 * Gets rid of a transportable, possibly dumping it.
 *
 * @param t The <code>Transportable</code> to dump.
 * @param force If true, disband units or dump goods at sea.
 * @return True if the transportable was dumped.
 */
private boolean dumpTransportable(Transportable t, boolean force) {
    final Unit carrier = getUnit();
    final AIUnit aiCarrier = getAIUnit();
    final Location here = carrier.getLocation();
    Locatable l = t.getTransportLocatable();
    boolean canLeave = carrier.isInEurope()
        || carrier.getLocation().getSettlement() != null;

    if (t instanceof AIUnit) {
        AIUnit aiu = (AIUnit)t;
        Direction direction = null;
        if (!canLeave) {
            for (Tile tile : carrier.getTile().getSurroundingTiles(1)) {
                if (tile.isLand()
                    && aiu.getUnit().getMoveType(tile).isProgress()) {
                    direction = carrier.getTile().getDirection(tile);
                    canLeave = true;
                    break;
                }
            }
        }
        if (canLeave && aiu.leaveTransport(direction)) {
            logger.finest(tag + " dumped " + aiu
                + " at " + here + ": " + toFullString());
        } else {
            if (!force) {
                logger.warning(tag + " failed to dump " + aiu
                    + " at " + here + ": " + toFullString());
                return false;
            }
            logger.warning(tag + " forcing dump(disband) " + aiu
                + " at " + here + ": " + toFullString());
            return AIMessage.askDisband(aiu);
        }
            
    } else if (t instanceof AIGoods) {
        AIGoods aig = (AIGoods)t;
        if (canLeave && aig.leaveTransport(null)) {
            logger.finest(tag + " dumped " + aig
                + " at " + here + ": " + toFullString());
        } else {
            if (!force) {
                logger.warning(tag + " failed to dump " + aig
                    + " at " + here + ": " + toFullString());
                return false;
            }
            logger.warning(tag + " forcing dump(goods) " + aig
                + " at " + here + ": " + toFullString());
            return AIMessage.askUnloadCargo(aiCarrier, aig.getGoods());
        }

    } else throw new IllegalStateException("Bogus transportable: " + t);

    return true;
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:63,
代码来源:TransportMission.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)