Search in sources :

Example 1 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class RemoveAvailableTech method perform.

@Override
public void perform(final GameData data) {
    final TechnologyFrontier front = m_player.getTechnologyFrontierList().getTechnologyFrontier(m_frontier.getName());
    front.removeAdvance(m_tech);
}
Also used : TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 2 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class GameDataExporter method playertechs.

private static String playertechs(final GameData data) {
    final StringBuilder returnValue = new StringBuilder();
    for (final PlayerID player : data.getPlayerList()) {
        if (player.getTechnologyFrontierList().getFrontiers().size() > 0) {
            returnValue.append("        <playerTech player=\"").append(player.getName()).append("\">\n");
            for (final TechnologyFrontier frontier : player.getTechnologyFrontierList().getFrontiers()) {
                returnValue.append("            <category name=\"").append(frontier.getName()).append("\">\n");
                for (final TechAdvance tech : frontier.getTechs()) {
                    String name = tech.getName();
                    final String cat = tech.getProperty();
                    for (final String definedName : TechAdvance.ALL_PREDEFINED_TECHNOLOGY_NAMES) {
                        if (definedName.equals(name)) {
                            name = cat;
                        }
                    }
                    returnValue.append("                <tech name=\"").append(name).append("\"/>\n");
                }
                returnValue.append("            </category>\n");
            }
            returnValue.append("        </playerTech>\n");
        }
    }
    return returnValue.toString();
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 3 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class ProTechAi method tech.

static void tech(final ITechDelegate techDelegate, final GameData data, final PlayerID player) {
    if (!Properties.getWW2V3TechModel(data)) {
        return;
    }
    final Territory myCapitol = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(player, data);
    final float enemyStrength = getStrengthOfPotentialAttackers(myCapitol, data, player);
    float myStrength = (myCapitol == null || myCapitol.getUnits() == null) ? 0.0F : strength(myCapitol.getUnits().getUnits(), false, false, false);
    final List<Territory> areaStrength = getNeighboringLandTerritories(data, player, myCapitol);
    for (final Territory areaTerr : areaStrength) {
        myStrength += strength(areaTerr.getUnits().getUnits(), false, false, false) * 0.75F;
    }
    final boolean capDanger = myStrength < (enemyStrength * 1.25F + 3.0F);
    final Resource pus = data.getResourceList().getResource(Constants.PUS);
    final int pusRemaining = player.getResources().getQuantity(pus);
    final Resource techtokens = data.getResourceList().getResource(Constants.TECH_TOKENS);
    final int techTokensQuantity = player.getResources().getQuantity(techtokens);
    int tokensToBuy = 0;
    if (!capDanger && techTokensQuantity < 3 && pusRemaining > Math.random() * 160) {
        tokensToBuy = 1;
    }
    if (techTokensQuantity > 0 || tokensToBuy > 0) {
        final List<TechnologyFrontier> cats = TechAdvance.getPlayerTechCategories(player);
        // retaining 65% chance of choosing land advances using basic ww2v3 model.
        if (data.getTechnologyFrontier().isEmpty()) {
            if (Math.random() > 0.35) {
                techDelegate.rollTech(techTokensQuantity + tokensToBuy, cats.get(1), tokensToBuy, null);
            } else {
                techDelegate.rollTech(techTokensQuantity + tokensToBuy, cats.get(0), tokensToBuy, null);
            }
        } else {
            final int rand = (int) (Math.random() * cats.size());
            techDelegate.rollTech(techTokensQuantity + tokensToBuy, cats.get(rand), tokensToBuy, null);
        }
    }
}
Also used : Territory(games.strategy.engine.data.Territory) Resource(games.strategy.engine.data.Resource) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 4 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class WW2V3Year41Test method testTechTokens.

@Test
public void testTechTokens() {
    // Set up the test
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge delegateBridge = getDelegateBridge(germans);
    delegateBridge.setStepName("germanTech");
    final TechnologyDelegate techDelegate = techDelegate(gameData);
    techDelegate.setDelegateBridgeAndPlayer(delegateBridge);
    techDelegate.start();
    final TechnologyFrontier mech = new TechnologyFrontier("", gameData);
    mech.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_MECHANIZED_INFANTRY, gameData, null));
    // Add tech token
    gameData.performChange(ChangeFactory.changeResourcesChange(germans, gameData.getResourceList().getResource(Constants.TECH_TOKENS), 1));
    // Check to make sure it was successful
    final int initTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(1, initTokens);
    // Fail the roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3 }));
    final TechResults roll = techDelegate.rollTech(1, mech, 0, null);
    // Check to make sure it failed
    assertEquals(0, roll.getHits());
    final int midTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(1, midTokens);
    // Make a Successful roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll2 = techDelegate.rollTech(1, mech, 0, null);
    // Check to make sure it succeeded and all tokens were removed
    assertEquals(1, roll2.getHits());
    final int finalTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(0, finalTokens);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Example 5 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class TechAdvance method createDefaultTechAdvances.

/**
 * For the game parser only.
 */
public static void createDefaultTechAdvances(final GameData data) {
    final TechnologyFrontier tf = data.getTechnologyFrontier();
    final boolean ww2v2 = Properties.getWW2V2(data);
    final boolean ww2v3 = Properties.getWW2V3(data);
    if (ww2v2) {
        createWW2V2Advances(tf);
    } else if (ww2v3) {
        createWW2V3Advances(tf);
    } else {
        createWW2V1Advances(tf);
    }
    // now create player tech frontiers
    final List<TechnologyFrontier> frontiers = new ArrayList<>();
    if (ww2v3) {
        final TechnologyFrontier an = new TechnologyFrontier("Air and Naval Advances", data);
        final TechnologyFrontier lp = new TechnologyFrontier("Land and Production Advances", data);
        final Tuple<List<TechAdvance>, List<TechAdvance>> ww2v3advances = getWW2v3CategoriesWithTheirAdvances(data);
        an.addAdvance(ww2v3advances.getFirst());
        lp.addAdvance(ww2v3advances.getSecond());
        frontiers.add(an);
        frontiers.add(lp);
    } else {
        final TechnologyFrontier tas = new TechnologyFrontier("Technology Advances", data);
        tas.addAdvance(new ArrayList<>(tf.getTechs()));
        frontiers.add(tas);
    }
    // add the frontiers
    for (final PlayerID player : data.getPlayerList().getPlayers()) {
        for (final TechnologyFrontier frontier : frontiers) {
            player.getTechnologyFrontierList().addTechnologyFrontier(new TechnologyFrontier(frontier));
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Aggregations

TechnologyFrontier (games.strategy.engine.data.TechnologyFrontier)10 PlayerID (games.strategy.engine.data.PlayerID)5 TechAdvance (games.strategy.triplea.delegate.TechAdvance)3 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)2 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)2 TechAttachment (games.strategy.triplea.attachments.TechAttachment)2 TechResults (games.strategy.triplea.delegate.dataObjects.TechResults)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 Change (games.strategy.engine.data.Change)1 CompositeChange (games.strategy.engine.data.CompositeChange)1 Resource (games.strategy.engine.data.Resource)1 Territory (games.strategy.engine.data.Territory)1 List (java.util.List)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1