text:
package cz.jan.maly.service.implementation;

import cz.jan.maly.model.Decider;
import cz.jan.maly.model.agent.AbstractAgent;
import cz.jan.maly.model.bot.AgentTypes;
import cz.jan.maly.model.bot.DesireKeys;
import cz.jan.maly.model.features.FeatureContainerHeader;
import cz.jan.maly.model.game.wrappers.ABaseLocationWrapper;
import cz.jan.maly.model.game.wrappers.AUnit;
import cz.jan.maly.model.game.wrappers.UnitWrapperFactory;
import cz.jan.maly.model.metadata.AgentType;
import cz.jan.maly.model.metadata.DesireKey;
import cz.jan.maly.model.metadata.DesireKeyID;
import cz.jan.maly.model.metadata.agents.configuration.ConfigurationWithAbstractPlan;
import cz.jan.maly.model.metadata.agents.configuration.ConfigurationWithSharedDesire;
import cz.jan.maly.model.planing.CommitmentDeciderInitializer;
import cz.jan.maly.model.planing.ReactionOnChangeStrategy;
import cz.jan.maly.service.AbstractAgentsInitializer;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static cz.jan.maly.model.DesiresKeys.*;
import static cz.jan.maly.model.bot.AgentTypes.PLAYER;
import static cz.jan.maly.model.bot.FactConverters.*;
import static cz.jan.maly.model.bot.FactKeys.*;
import static cz.jan.maly.model.bot.FactKeys.IS_BASE;
import static cz.jan.maly.model.bot.FactKeys.IS_ENEMY_BASE;
import static cz.jan.maly.model.bot.FactKeys.IS_ISLAND;
import static cz.jan.maly.model.bot.FactKeys.IS_MINERAL_ONLY;
import static cz.jan.maly.model.bot.FeatureContainerHeaders.*;

/**
 * Implementation of AbstractAgentsInitializer
 * Created by Jan on 09-May-17.
 */
public class AbstractAgentsInitializerImpl implements AbstractAgentsInitializer {

    @Override
    public List<AbstractAgent> initializeAbstractAgents(BotFacade botFacade) {
        List<AbstractAgent> abstractAgents = new ArrayList<>();
        abstractAgents.add(new AbstractAgent(ECO_MANAGER, botFacade));
        abstractAgents.add(new AbstractAgent(BUILDING_ORDER_MANAGER, botFacade));
        abstractAgents.add(new AbstractAgent(UNIT_ORDER_MANAGER, botFacade));
        return abstractAgents;
    }

    private static final AgentType ECO_MANAGER = AgentType.builder()
            .agentTypeID(AgentTypes.ECO_MANAGER)
            .usingTypesForFacts(new HashSet<>(Arrays.asList(BASE_TO_MOVE, LAST_TIME_HATCHERY_BUILD, LAST_TIME_EXTRACTOR_BUILD)))
            .initializationStrategy(type -> {

                //train drone
                ConfigurationWithSharedDesire trainDrone = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_DRONE)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                                && (Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.BUILD_WORKER, dataForDecision, TRAINING_WORKER)
                                                //or we are idle and there is still room for drone
                                                || (!dataForDecision.madeDecisionToAny()
                                                && (dataForDecision.getFeatureValueGlobalBeliefSets(COUNT_OF_EXTRACTORS) * 3) + (dataForDecision.getFeatureValueGlobalBeliefSets(COUNT_OF_MINERALS_TO_MINE) * 2.5)
                                                > dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_WORKERS) && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MINERALS) >= 100))
                                )
                                .globalBeliefTypesByAgentType(Stream.concat(TRAINING_WORKER.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_MINERALS)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(Stream.concat(TRAINING_WORKER.getConvertersForFactSetsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_EXTRACTORS, COUNT_OF_MINERALS_TO_MINE)).collect(Collectors.toSet()))
                                .globalBeliefTypes(Stream.concat(TRAINING_WORKER.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(COUNT_OF_WORKERS, CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Arrays.asList(INCREASE_CAPACITY, EXPAND, BUILD_EXTRACTOR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.BUILD_WORKER, dataForDecision, TRAINING_WORKER))
                                .globalBeliefTypesByAgentType(TRAINING_WORKER.getConvertersForFactsForGlobalBeliefsByAgentType())
                                .globalBeliefSetTypesByAgentType(TRAINING_WORKER.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(TRAINING_WORKER.getConvertersForFactsForGlobalBeliefs())
                                .build())
                        .build();
                type.addConfiguration(BUILD_WORKER, trainDrone);

                //morph to overlord
                ConfigurationWithSharedDesire trainOverlord = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_OVERLORD)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MORPHING_OVERLORDS) == 0
                                                && (dataForDecision.getFeatureValueGlobalBeliefs(CURRENT_POPULATION) >= dataForDecision.getFeatureValueGlobalBeliefs(MAX_POPULATION)
                                                || Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.INCREASE_CAPACITY, dataForDecision, INCREASING_CAPACITY)))
                                .globalBeliefTypesByAgentType(Stream.concat(INCREASING_CAPACITY.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(CURRENT_POPULATION, MAX_POPULATION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(INCREASING_CAPACITY.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(INCREASING_CAPACITY.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(COUNT_OF_MORPHING_OVERLORDS, CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        !Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.INCREASE_CAPACITY, dataForDecision, INCREASING_CAPACITY)
                                                || dataForDecision.getFeatureValueGlobalBeliefs(CURRENT_POPULATION)
                                                < dataForDecision.getFeatureValueGlobalBeliefs(MAX_POPULATION))
                                .globalBeliefTypesByAgentType(Stream.concat(INCREASING_CAPACITY.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(CURRENT_POPULATION, MAX_POPULATION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(INCREASING_CAPACITY.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(INCREASING_CAPACITY.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(COUNT_OF_MORPHING_OVERLORDS, CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .build())
                        .build();
                type.addConfiguration(INCREASE_CAPACITY, trainOverlord);

                //expand to another base
                ConfigurationWithSharedDesire expand = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(EXPAND)
                        .counts(1)
                        .reactionOnChangeStrategy((memory, desireParameters) -> {

                            //find nearest free base closest to any of our bases
                            Set<ABaseLocationWrapper> ourBases = memory.getReadOnlyMemoriesForAgentType(AgentTypes.BASE_LOCATION)
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE).get())
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE_LOCATION).get())
                                    .collect(Collectors.toSet());

                            //places where base is currently build
                            Set<ABaseLocationWrapper> placesWhereBaseIsCurrentlyBuild = UnitWrapperFactory.getStreamOfAllAlivePlayersUnits()
                                    .filter(aUnitOfPlayer -> aUnitOfPlayer.getType().isWorker())
                                    .filter(aUnitOfPlayer -> !aUnitOfPlayer.getTrainingQueue().isEmpty())
                                    .filter(aUnitOfPlayer -> aUnitOfPlayer.getTrainingQueue().get(0).isBase())
                                    .map(AUnit::getNearestBaseLocation)
                                    .filter(Optional::isPresent)
                                    .map(Optional::get)
                                    .filter(aBaseLocationWrapper -> !ourBases.contains(aBaseLocationWrapper))
                                    .collect(Collectors.toSet());

                            Optional<ABaseLocationWrapper> basesToExpand = memory.getReadOnlyMemoriesForAgentType(AgentTypes.BASE_LOCATION)
                                    .filter(readOnlyMemory -> !readOnlyMemory.returnFactValueForGivenKey(IS_ENEMY_BASE).get()
                                            && !readOnlyMemory.returnFactValueForGivenKey(IS_ISLAND).get())
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE_LOCATION).get())
                                    .filter(aBaseLocationWrapper -> !ourBases.contains(aBaseLocationWrapper)
                                            && !placesWhereBaseIsCurrentlyBuild.contains(aBaseLocationWrapper))
                                    .min(Comparator.comparingDouble(value -> ourBases.stream()
                                            .mapToDouble(other -> other.distanceTo(value))
                                            .min().orElse(Integer.MAX_VALUE)));

                            if (basesToExpand.isPresent()) {
                                memory.updateFact(BASE_TO_MOVE, basesToExpand.get());
                            } else {
                                memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                            }

                        })
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> {
                            memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                            memory.updateFact(LAST_TIME_HATCHERY_BUILD,
                                    memory.getReadOnlyMemoriesForAgentType(PLAYER)
                                            .mapToInt(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(MADE_OBSERVATION_IN_FRAME).orElse(0))
                                            .max().orElse(0));
                        })
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES_IN_CONSTRUCTION) == 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES_BEING_CONSTRUCT) == 0
                                                && (memory.returnFactValueForGivenKey(LAST_TIME_HATCHERY_BUILD).orElse(0) + 100
                                                < memory.getReadOnlyMemoriesForAgentType(PLAYER)
                                                .mapToInt(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(MADE_OBSERVATION_IN_FRAME).orElse(0))
                                                .max().orElse(0))
                                                && (Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.EXPAND, dataForDecision, EXPANDING))
//                                        || (dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MINERALS) > 350
//                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES) == 2))
                                )
                                .globalBeliefTypes(Stream.concat(EXPANDING.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(COUNT_OF_HATCHERIES_IN_CONSTRUCTION, CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .globalBeliefTypesByAgentType(Stream.concat(EXPANDING.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_HATCHERIES_BEING_CONSTRUCT, COUNT_OF_HETCH, COUNT_OF_MINERALS, COUNT_OF_HATCHERIES)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(EXPANDING.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        !Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.EXPAND, dataForDecision, EXPANDING)
                                                || !memory.returnFactValueForGivenKey(BASE_TO_MOVE).isPresent()
                                                || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES_IN_CONSTRUCTION) > 0
                                                || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES_BEING_CONSTRUCT) > 0
                                                || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HATCHERIES_BEGINNING_CONSTRUCTION) > 0
                                )
                                .globalBeliefTypes(Stream.concat(EXPANDING.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(COUNT_OF_HATCHERIES_IN_CONSTRUCTION, CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .globalBeliefTypesByAgentType(Stream.concat(EXPANDING.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_HATCHERIES_BEING_CONSTRUCT, COUNT_OF_HETCH, COUNT_OF_MINERALS, COUNT_OF_HATCHERIES, COUNT_OF_HATCHERIES_BEGINNING_CONSTRUCTION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(EXPANDING.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .build())
                        .build();
                type.addConfiguration(EXPAND, expand);

                ConfigurationWithSharedDesire buildExtractor = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_EXTRACTOR)
                        .counts(1)
                        .reactionOnChangeStrategy((memory, desireParameters) -> {

                            //extractors bases
                            Set<ABaseLocationWrapper> extractorsBases = memory.getReadOnlyMemoriesForAgentType(AgentTypes.EXTRACTOR)
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(REPRESENTS_UNIT).get())
                                    .filter(aUnitWithCommands -> aUnitWithCommands.getNearestBaseLocation().isPresent())
                                    .map(aUnitWithCommands -> aUnitWithCommands.getNearestBaseLocation().get())
                                    .collect(Collectors.toSet());

                            //gas bases
                            Optional<ABaseLocationWrapper> ourBase = memory.getReadOnlyMemoriesForAgentType(AgentTypes.BASE_LOCATION)
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE).get())
                                    .filter(readOnlyMemory -> !readOnlyMemory.returnFactValueForGivenKey(IS_MINERAL_ONLY).get())
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactSetValueForGivenKey(HAS_BASE).isPresent())
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactSetValueForGivenKey(HAS_BASE).get()
                                            .anyMatch(aUnitOfPlayer -> !aUnitOfPlayer.isMorphing() && !aUnitOfPlayer.isBeingConstructed()))
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE_LOCATION).get())
                                    .filter(aBaseLocationWrapper -> !extractorsBases.contains(aBaseLocationWrapper))
                                    .findAny();

                            if (ourBase.isPresent()) {
                                memory.updateFact(BASE_TO_MOVE, ourBase.get());
                            } else {
                                memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                            }

                        })
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> {
                            memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                            memory.updateFact(LAST_TIME_EXTRACTOR_BUILD,
                                    memory.getReadOnlyMemoriesForAgentType(PLAYER)
                                            .mapToInt(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(MADE_OBSERVATION_IN_FRAME).orElse(0))
                                            .max().orElse(0));
                        })
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && !dataForDecision.madeDecisionToAny()
                                        && (memory.returnFactValueForGivenKey(LAST_TIME_EXTRACTOR_BUILD).orElse(0) + 100
                                        < memory.getReadOnlyMemoriesForAgentType(PLAYER)
                                        .mapToInt(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(MADE_OBSERVATION_IN_FRAME).orElse(0))
                                        .max().orElse(0))
                                        && Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.BUILD_EXTRACTOR, dataForDecision, BUILDING_EXTRACTOR))
                                .globalBeliefTypes(Stream.concat(BUILDING_EXTRACTOR.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .globalBeliefTypesByAgentType(BUILDING_EXTRACTOR.getConvertersForFactsForGlobalBeliefsByAgentType())
                                .globalBeliefSetTypesByAgentType(BUILDING_EXTRACTOR.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .desiresToConsider(new HashSet<>(Collections.singleton(BUILD_EXTRACTOR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !memory.returnFactValueForGivenKey(BASE_TO_MOVE).isPresent()
                                        || !Decider.getDecision(AgentTypes.ECO_MANAGER, DesireKeys.BUILD_EXTRACTOR, dataForDecision, BUILDING_EXTRACTOR))
                                .globalBeliefTypes(BUILDING_EXTRACTOR.getConvertersForFactsForGlobalBeliefs())
                                .globalBeliefTypesByAgentType(BUILDING_EXTRACTOR.getConvertersForFactsForGlobalBeliefsByAgentType())
                                .globalBeliefSetTypesByAgentType(BUILDING_EXTRACTOR.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .useFactsInMemory(true)
                                .build())
                        .build();
                type.addConfiguration(BUILD_EXTRACTOR, buildExtractor);

                //abstract plan from desire by another agent to build extractor (to meet requirements for building)
                ConfigurationWithAbstractPlan buildExtractorFromOtherAgent = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny())
                                .desiresToConsider(new HashSet<>(Collections.singleton(BUILD_EXTRACTOR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .desiresForOthers(new HashSet<>(Collections.singleton(BUILD_EXTRACTOR)))
                        .build();
                type.addConfiguration(BUILD_EXTRACTOR, buildExtractorFromOtherAgent, false);
                ConfigurationWithSharedDesire buildExtractorForAbstractPlan = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_EXTRACTOR)
                        .counts(1)
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> memory.eraseFactValueForGivenKey(BASE_TO_MOVE))
                        .reactionOnChangeStrategy((memory, desireParameters) -> {

                            //extractors bases
                            Set<ABaseLocationWrapper> extractorsBases = memory.getReadOnlyMemoriesForAgentType(AgentTypes.EXTRACTOR)
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(REPRESENTS_UNIT).get())
                                    .filter(aUnitWithCommands -> aUnitWithCommands.getNearestBaseLocation().isPresent())
                                    .map(aUnitWithCommands -> aUnitWithCommands.getNearestBaseLocation().get())
                                    .collect(Collectors.toSet());

                            //gas bases
                            Optional<ABaseLocationWrapper> ourBase = memory.getReadOnlyMemoriesForAgentType(AgentTypes.BASE_LOCATION)
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE).get())
                                    .filter(readOnlyMemory -> !readOnlyMemory.returnFactValueForGivenKey(IS_MINERAL_ONLY).get())
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactSetValueForGivenKey(HAS_BASE).isPresent())
                                    .filter(readOnlyMemory -> readOnlyMemory.returnFactSetValueForGivenKey(HAS_BASE).get()
                                            .anyMatch(aUnitOfPlayer -> !aUnitOfPlayer.isMorphing() && !aUnitOfPlayer.isBeingConstructed()))
                                    .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE_LOCATION).get())
                                    .filter(aBaseLocationWrapper -> !extractorsBases.contains(aBaseLocationWrapper))
                                    .findAny();

                            if (ourBase.isPresent()) {
                                memory.updateFact(BASE_TO_MOVE, ourBase.get());
                            } else {
                                memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                            }

                        })
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> memory.eraseFactValueForGivenKey(BASE_TO_MOVE))
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(BUILD_EXTRACTOR, BUILD_EXTRACTOR, buildExtractorForAbstractPlan);

            })
            .desiresForOthers(new HashSet<>(Arrays.asList(BUILD_WORKER, INCREASE_CAPACITY, EXPAND, BUILD_EXTRACTOR)))
            .build();

    private static final AgentType UNIT_ORDER_MANAGER = AgentType.builder()
            .agentTypeID(AgentTypes.UNIT_ORDER_MANAGER)
            .initializationStrategy(type -> {

                //build zerglings or infrastructure
                type.addConfiguration(BOOST_GROUND_MELEE, shareIntentionToTrainUnit(BOOST_GROUND_MELEE, DesireKeys.BOOST_GROUND_MELEE, BOOSTING_GROUND_MELEE));

                //build hydras or infrastructure
                type.addConfiguration(BOOST_GROUND_RANGED, shareIntentionToTrainUnit(BOOST_GROUND_RANGED, DesireKeys.BOOST_GROUND_RANGED, BOOSTING_GROUND_RANGED));

                //build mutalisks or infrastructure
                type.addConfiguration(BOOST_AIR, shareIntentionToTrainUnit(BOOST_AIR, DesireKeys.BOOST_AIR, BOOSTING_AIR));

                //abstract plan to build units based on position requests
                ConfigurationWithAbstractPlan groundPosition = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && (dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) > 0)
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MINERALS) >= 300
                                )
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_POOLS, COUNT_OF_HYDRALISK_DENS,
                                        COUNT_OF_MINERALS)))
                                .globalBeliefTypes(new HashSet<>(Collections.singletonList(CAN_TRANSIT_FROM_5_POOL)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) == 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_POOLS, COUNT_OF_HYDRALISK_DENS)))
                                .build())
                        .desiresForOthers(new HashSet<>(Arrays.asList(BOOST_GROUND_MELEE, BOOST_GROUND_RANGED)))
                        .build();
                type.addConfiguration(HOLD_GROUND, groundPosition, false);
                ConfigurationWithSharedDesire buildLings = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(BOOST_GROUND_MELEE)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) == 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Collections.singletonList(COUNT_OF_HYDRALISK_DENS)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(BOOST_GROUND_MELEE, HOLD_GROUND, buildLings);
                ConfigurationWithSharedDesire buildHydras = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(BOOST_GROUND_RANGED)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Collections.singletonList(COUNT_OF_HYDRALISK_DENS)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) == 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Collections.singletonList(COUNT_OF_HYDRALISK_DENS)))
                                .build())
                        .build();
                type.addConfiguration(BOOST_GROUND_RANGED, HOLD_GROUND, buildHydras);
//
                //abstract plan to build units based on position requests
                ConfigurationWithAbstractPlan airPosition = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) > 0
                                )
                                .globalBeliefTypesByAgentType(new HashSet<>(Collections.singletonList(COUNT_OF_SPIRES)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) == 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Collections.singletonList(COUNT_OF_SPIRES)))
                                .build())
                        .desiresForOthers(new HashSet<>(Collections.singletonList(BOOST_AIR)))
                        .build();
                type.addConfiguration(HOLD_AIR, airPosition, false);
                ConfigurationWithSharedDesire buildMutas = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(BOOST_AIR)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(BOOST_AIR, HOLD_AIR, buildMutas);

            })
            .desiresForOthers(new HashSet<>(Arrays.asList(BOOST_GROUND_MELEE, BOOST_GROUND_RANGED, BOOST_AIR)))
            .build();

    private static ConfigurationWithSharedDesire shareIntentionToTrainUnit(DesireKey boostingTypeDesire, DesireKeyID boostingTypeDesireID,
                                                                           FeatureContainerHeader featureContainerHeader) {
        return ConfigurationWithSharedDesire.builder()
                .sharedDesireKey(boostingTypeDesire)
                .counts(1)
                .decisionInDesire(CommitmentDeciderInitializer.builder()
                        .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                && Decider.getDecision(AgentTypes.UNIT_ORDER_MANAGER, boostingTypeDesireID, dataForDecision, featureContainerHeader)
                                || (dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MINERALS) >= 350 && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_GAS) >= 100)
                        )
                        .globalBeliefTypesByAgentType(Stream.concat(featureContainerHeader.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                Stream.of(COUNT_OF_MINERALS, COUNT_OF_GAS)).collect(Collectors.toSet()))
                        .globalBeliefSetTypesByAgentType(featureContainerHeader.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                        .globalBeliefTypes(new HashSet<>(Collections.singletonList(CAN_TRANSIT_FROM_5_POOL)))
                        .build())
                .decisionInIntention(CommitmentDeciderInitializer.builder()
                        .decisionStrategy((dataForDecision, memory) -> !Decider.getDecision(AgentTypes.UNIT_ORDER_MANAGER, boostingTypeDesireID, dataForDecision, featureContainerHeader))
                        .globalBeliefTypesByAgentType(featureContainerHeader.getConvertersForFactsForGlobalBeliefsByAgentType())
                        .globalBeliefSetTypesByAgentType(featureContainerHeader.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                        .build())
                .build();
    }

    public static final ReactionOnChangeStrategy FIND_MAIN_BASE = (memory, desireParameters) -> {
        Optional<ABaseLocationWrapper> ourBase = memory.getReadOnlyMemoriesForAgentType(AgentTypes.BASE_LOCATION)
                .filter(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE).get())
                .filter(readOnlyMemory -> readOnlyMemory.returnFactSetValueForGivenKey(HAS_BASE).get()
                        .anyMatch(aUnitOfPlayer -> !aUnitOfPlayer.isMorphing() && !aUnitOfPlayer.isBeingConstructed()))
                .map(readOnlyMemory -> readOnlyMemory.returnFactValueForGivenKey(IS_BASE_LOCATION).get())
                .filter(ABaseLocationWrapper::isStartLocation)
                .findAny();
        if (ourBase.isPresent()) {
            memory.updateFact(BASE_TO_MOVE, ourBase.get());
        } else {
            memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
        }
    };

    private static final AgentType BUILDING_ORDER_MANAGER = AgentType.builder()
            .agentTypeID(AgentTypes.BUILDING_ORDER_MANAGER)
            .usingTypesForFacts(new HashSet<>(Collections.singletonList(BASE_TO_MOVE)))
            .initializationStrategy(type -> {

                ConfigurationWithSharedDesire buildPool = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_POOL)
                        .counts(1)
                        .reactionOnChangeStrategy(FIND_MAIN_BASE)
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> memory.eraseFactValueForGivenKey(BASE_TO_MOVE))
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) == 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) == 0
                                                && Decider.getDecision(AgentTypes.BUILDING_ORDER_MANAGER, DesireKeys.ENABLE_GROUND_MELEE, dataForDecision, BUILDING_POOL)
//                                                || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_MINERALS) > 200)
                                )
                                .globalBeliefTypesByAgentType(Stream.concat(BUILDING_POOL.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS, COUNT_OF_MINERALS)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(BUILDING_POOL.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(BUILDING_POOL.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS)))
                                .build())
                        .build();
                type.addConfiguration(ENABLE_GROUND_MELEE, buildPool);

                //common plans
                //build pool if not present
                ConfigurationWithSharedDesire buildPoolCommon = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_POOL)
                        .reactionOnChangeStrategy(FIND_MAIN_BASE)
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> memory.eraseFactValueForGivenKey(BASE_TO_MOVE))
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) == 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS).collect(Collectors.toSet()))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS)))
                                .build())
                        .build();
                //tell system to build extractor if it is missing
                ConfigurationWithSharedDesire buildExtractorCommon = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(BUILD_EXTRACTOR)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny() &&
                                        dataForDecision.getFeatureValueGlobalBeliefSets(COUNT_OF_EXTRACTORS) == 0)
                                .globalBeliefSetTypesByAgentType(Collections.singleton(COUNT_OF_EXTRACTORS))
                                .desiresToConsider(new HashSet<>(Collections.singleton(BUILD_EXTRACTOR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        dataForDecision.getFeatureValueGlobalBeliefSets(COUNT_OF_EXTRACTORS) > 0)
                                .globalBeliefSetTypesByAgentType(Collections.singleton(COUNT_OF_EXTRACTORS))
                                .build())
                        .build();
                //common abstract plan to upgrade to spire
                ConfigurationWithAbstractPlan upgradeToLairAbstractCommon = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny()
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_LAIRS, COUNT_OF_LAIRS_IN_CONSTRUCTION).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(UPGRADE_TO_LAIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_LAIRS_IN_CONSTRUCTION, COUNT_OF_LAIRS)))
                                .build())
                        .desiresForOthers(new HashSet<>(Arrays.asList(ENABLE_GROUND_MELEE, UPGRADE_TO_LAIR,
                                BUILD_EXTRACTOR)))
                        .build();
                type.addConfiguration(UPGRADE_TO_LAIR, upgradeToLairAbstractCommon, false);
                //tell system to build pool if needed
                type.addConfiguration(ENABLE_GROUND_MELEE, UPGRADE_TO_LAIR, buildPoolCommon);
                //tell system to build extractor if it is missing
                type.addConfiguration(BUILD_EXTRACTOR, UPGRADE_TO_LAIR, buildExtractorCommon);
                //tell system to upgrade hatchery to lair
                ConfigurationWithSharedDesire upgradeToLair = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(UPGRADE_TO_LAIR)
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(UPGRADE_TO_LAIR, UPGRADE_TO_LAIR, upgradeToLair);

                //hydralisk den. as abstract plan, meet dependencies - pool and at least one extractor
                ConfigurationWithAbstractPlan buildHydraliskDen = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && !dataForDecision.madeDecisionToAny()
                                        && Decider.getDecision(AgentTypes.BUILDING_ORDER_MANAGER, DesireKeys.ENABLE_GROUND_RANGED, dataForDecision, BUILDING_HYDRALISK_DEN)
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION) == 0
                                )
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_GROUND_RANGED)))
                                .globalBeliefTypesByAgentType(Stream.concat(BUILDING_HYDRALISK_DEN.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_HYDRALISK_DENS, COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(BUILDING_HYDRALISK_DEN.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(BUILDING_HYDRALISK_DEN.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_HYDRALISK_DENS, COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION)))
                                .build())
                        .desiresForOthers(new HashSet<>(Arrays.asList(ENABLE_GROUND_RANGED, BUILD_EXTRACTOR,
                                ENABLE_GROUND_MELEE)))
                        .build();
                type.addConfiguration(ENABLE_GROUND_RANGED, buildHydraliskDen, true);
                ConfigurationWithSharedDesire bdDen = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_HYDRALISK_DEN)
                        .reactionOnChangeStrategy(FIND_MAIN_BASE)
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> {
                            memory.eraseFactValueForGivenKey(BASE_TO_MOVE);
                        })
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(ENABLE_GROUND_RANGED, ENABLE_GROUND_RANGED, bdDen);
                type.addConfiguration(BUILD_EXTRACTOR, ENABLE_GROUND_RANGED, buildExtractorCommon);
                type.addConfiguration(ENABLE_GROUND_MELEE, ENABLE_GROUND_RANGED, buildPoolCommon);
                //hydralisk den

                //upgrade to lair. as abstract plan, meet dependencies - pool and at least one extractor
                ConfigurationWithAbstractPlan upgradeToLairAbstract = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && !dataForDecision.madeDecisionToAny()
                                        && Decider.getDecision(AgentTypes.BUILDING_ORDER_MANAGER, DesireKeys.UPGRADE_TO_LAIR, dataForDecision, UPGRADING_TO_LAIR)
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.concat(UPGRADING_TO_LAIR.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_LAIRS, COUNT_OF_LAIRS_IN_CONSTRUCTION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(UPGRADING_TO_LAIR.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(UPGRADING_TO_LAIR.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(UPGRADE_TO_LAIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_LAIRS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_LAIRS, COUNT_OF_LAIRS_IN_CONSTRUCTION)))
                                .build())
                        .desiresForOthers(new HashSet<>(Arrays.asList(ENABLE_GROUND_MELEE, UPGRADE_TO_LAIR,
                                BUILD_EXTRACTOR)))
                        .build();
                type.addConfiguration(UPGRADE_TO_LAIR, upgradeToLairAbstract, true);
                //upgrade to lair

                //build spire. as abstract plan, meet dependencies - upgrade to lair
                ConfigurationWithAbstractPlan buildSpire = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && !dataForDecision.madeDecisionToAny()
                                        && Decider.getDecision(AgentTypes.BUILDING_ORDER_MANAGER, DesireKeys.ENABLE_AIR, dataForDecision, BUILDING_SPIRE)
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.concat(BUILDING_SPIRE.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_SPIRES, COUNT_OF_SPIRES_IN_CONSTRUCTION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(BUILDING_SPIRE.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(BUILDING_SPIRE.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_AIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_SPIRES, COUNT_OF_SPIRES_IN_CONSTRUCTION).collect(Collectors.toSet()))
                                .build())
                        .desiresForOthers(new HashSet<>(Collections.singletonList(ENABLE_AIR)))
                        .desiresWithAbstractIntention(new HashSet<>(Collections.singleton(UPGRADE_TO_LAIR)))
                        .build();
                type.addConfiguration(ENABLE_AIR, buildSpire, true);
                ConfigurationWithSharedDesire bdSpire = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_SPIRE)
                        .reactionOnChangeStrategy(FIND_MAIN_BASE)
                        .reactionOnChangeStrategyInIntention((memory, desireParameters) -> memory.eraseFactValueForGivenKey(BASE_TO_MOVE))
                        .counts(1)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(ENABLE_AIR, ENABLE_AIR, bdSpire);
                type.addConfiguration(UPGRADE_TO_LAIR, ENABLE_AIR, upgradeToLairAbstractCommon);
                //build spire

                //build evolution chamber
                ConfigurationWithSharedDesire buildEvolutionChamber = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_EVOLUTION_CHAMBER)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(CAN_TRANSIT_FROM_5_POOL) != 0
                                        && !dataForDecision.madeDecisionToAny() &&
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION) == 0
                                        && Decider.getDecision(AgentTypes.BUILDING_ORDER_MANAGER, DesireKeys.ENABLE_STATIC_ANTI_AIR, dataForDecision, BUILDING_EVOLUTION_CHAMBER)
                                )
                                .globalBeliefTypesByAgentType(Stream.concat(BUILDING_EVOLUTION_CHAMBER.getConvertersForFactsForGlobalBeliefsByAgentType().stream(),
                                        Stream.of(COUNT_OF_EVOLUTION_CHAMBERS, COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION)).collect(Collectors.toSet()))
                                .globalBeliefSetTypesByAgentType(BUILDING_EVOLUTION_CHAMBER.getConvertersForFactSetsForGlobalBeliefsByAgentType())
                                .globalBeliefTypes(Stream.concat(BUILDING_EVOLUTION_CHAMBER.getConvertersForFactsForGlobalBeliefs().stream(),
                                        Stream.of(CAN_TRANSIT_FROM_5_POOL)).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_STATIC_ANTI_AIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_EVOLUTION_CHAMBERS, COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION)))
                                .build())
                        .build();
                type.addConfiguration(ENABLE_STATIC_ANTI_AIR, buildEvolutionChamber);

                //other managers requirements

                //abstract plan to build pool if it is not present
                ConfigurationWithAbstractPlan buildPoolIfMissing = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny() &&
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_GROUND_MELEE)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_POOLS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_POOLS_IN_CONSTRUCTION, COUNT_OF_POOLS)))
                                .build())
                        .build();

                //for melee
                type.addConfiguration(BOOST_GROUND_MELEE, buildPoolIfMissing, false);
                type.addConfiguration(ENABLE_GROUND_MELEE, BOOST_GROUND_MELEE, buildPoolCommon);

                //for sunken
                type.addConfiguration(MORPH_TO_SUNKEN_COLONY, buildPoolIfMissing, false);
                type.addConfiguration(ENABLE_GROUND_MELEE, MORPH_TO_SUNKEN_COLONY, buildPoolCommon);

                //abstract plan to build hydralisk den if it is not present
                ConfigurationWithAbstractPlan buildHydraliskDenIfMissing = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny() &&
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION) == 0
                                )
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_GROUND_RANGED)))
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_HYDRALISK_DENS, COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION)
                                        .collect(Collectors.toSet()))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_HYDRALISK_DENS, COUNT_OF_HYDRALISK_DENS_IN_CONSTRUCTION)))
                                .build())
                        .desiresForOthers(new HashSet<>(Arrays.asList(ENABLE_GROUND_RANGED, BUILD_EXTRACTOR,
                                ENABLE_GROUND_MELEE)))
                        .build();
                type.addConfiguration(BOOST_GROUND_RANGED, buildHydraliskDenIfMissing, false);
                type.addConfiguration(ENABLE_GROUND_RANGED, BOOST_GROUND_RANGED, bdDen);
                type.addConfiguration(BUILD_EXTRACTOR, BOOST_GROUND_RANGED, buildExtractorCommon);
                type.addConfiguration(ENABLE_GROUND_MELEE, BOOST_GROUND_RANGED, buildPoolCommon);

                //abstract plan to build spire if it is not present
                ConfigurationWithAbstractPlan buildSpireIfMissing = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> !dataForDecision.madeDecisionToAny() &&
                                        dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) == 0
                                        && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_SPIRES, COUNT_OF_SPIRES_IN_CONSTRUCTION).collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_AIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_SPIRES_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_SPIRES, COUNT_OF_SPIRES_IN_CONSTRUCTION).collect(Collectors.toSet()))
                                .build())
                        .desiresForOthers(new HashSet<>(Collections.singletonList(ENABLE_AIR)))
                        .desiresWithAbstractIntention(new HashSet<>(Collections.singleton(UPGRADE_TO_LAIR)))
                        .build();
                type.addConfiguration(BOOST_AIR, buildSpireIfMissing, false);
                type.addConfiguration(ENABLE_AIR, BOOST_AIR, bdSpire);
                type.addConfiguration(UPGRADE_TO_LAIR, BOOST_AIR, upgradeToLairAbstractCommon);

                //abstract plan to build evolution chamber if it is not present
                ConfigurationWithAbstractPlan buildECIfMissing = ConfigurationWithAbstractPlan.builder()
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) ->
                                        !dataForDecision.madeDecisionToAny() &&
                                                dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS) == 0
                                                && dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION) == 0)
                                .globalBeliefTypesByAgentType(Stream.of(COUNT_OF_EVOLUTION_CHAMBERS, COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION)
                                        .collect(Collectors.toSet()))
                                .desiresToConsider(new HashSet<>(Collections.singleton(ENABLE_STATIC_ANTI_AIR)))
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS) > 0
                                        || dataForDecision.getFeatureValueGlobalBeliefs(COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION) > 0)
                                .globalBeliefTypesByAgentType(new HashSet<>(Arrays.asList(COUNT_OF_EVOLUTION_CHAMBERS, COUNT_OF_EVOLUTION_CHAMBERS_IN_CONSTRUCTION)))
                                .build())
                        .desiresForOthers(new HashSet<>(Collections.singletonList(ENABLE_STATIC_ANTI_AIR)))
                        .build();
                ConfigurationWithSharedDesire buildEC = ConfigurationWithSharedDesire.builder()
                        .sharedDesireKey(MORPH_TO_EVOLUTION_CHAMBER)
                        .decisionInDesire(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> true)
                                .build())
                        .decisionInIntention(CommitmentDeciderInitializer.builder()
                                .decisionStrategy((dataForDecision, memory) -> false)
                                .build())
                        .build();
                type.addConfiguration(MORPH_TO_SPORE_COLONY, buildECIfMissing, false);
                type.addConfiguration(ENABLE_STATIC_ANTI_AIR, MORPH_TO_SPORE_COLONY, buildEC);

            })
            .desiresForOthers(new HashSet<>(Arrays.asList(ENABLE_GROUND_MELEE, ENABLE_STATIC_ANTI_AIR)))
            .desiresWithAbstractIntention(new HashSet<>(Arrays.asList(UPGRADE_TO_LAIR, ENABLE_GROUND_RANGED,
                    ENABLE_AIR)))
            .build();

}


text:
filename: /packages/material-ui/src/FormControl/FormControl.js
---

# FormControl API

The API documentation of the FormControl React component. Learn more about the properties and the CSS customization points.

```js
import FormControl from '@material-ui/core/FormControl';
```

Provides context such as filled/focused/error/required for form inputs.
Relying on the context provides high flexibility and ensures that the state always stays
consistent across the children of the `FormControl`.
This context is used by the following components:
 - FormLabel
 - FormHelperText
 - Input
 - InputLabel

⚠ Only one input can be used within a FormControl.

## Props

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| children | node |   | The contents of the form control. |
| classes | object |   | Override or extend the styles applied to the component. See [CSS API](#css-api) below for more details. |
| component | componentPropType | 'div' | The component used for the root node. Either a string to use a DOM element or a component. |
| disabled | bool | false | If `true`, the label, input and helper text should be displayed in a disabled state. |
| error | bool | false | If `true`, the label should be displayed in an error state. |
| fullWidth | bool | false | If `true`, the component will take up the full width of its container. |
| margin | enum: 'none' |
 'dense' |
 'normal'
 | 'none' | If `dense` or `normal`, will adjust vertical spacing of this and contained components. |
| required | bool | false | If `true`, the label will indicate that the input is required. |
| variant | enum: 'standard' |
 'outlined' |
 'filled'
 | 'standard' | The variant to use. |

Any other properties supplied will be spread to the root element (native element).

## CSS

You can override all the class names injected by Material-UI thanks to the `classes` property.
This property accepts the following keys:

| Name | Description |
|:-----|:------------|
| root | Styles applied to the root element.
| marginNormal | Styles applied to the root element if `margin="normal"`.
| marginDense | Styles applied to the root element if `margin="dense"`.
| fullWidth | Styles applied to the root element if `fullWidth={true}`.

Have a look at [overriding with classes](/customization/overrides/#overriding-with-classes) section
and the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/FormControl/FormControl.js)
for more detail.

If using the `overrides` [key of the theme](/customization/themes/#css),
you need to use the following style sheet name: `MuiFormControl`.

## Demos

- [Selection Controls](/demos/selection-controls/)
- [Text Fields](/demos/text-fields/)

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/base64.html">
<link rel="import"
      href="/tracing/ui/extras/about_tracing/tracing_controller_client.html">

<script>
'use strict';

tr.exportTo('tr.ui.e.about_tracing', function() {
  function beginXhr(method, path, data) {
    if (data === undefined)
      data = null;
    return new Promise(function(resolve, reject) {
      var req = new XMLHttpRequest();
      if (method != 'POST' && data !== null)
        throw new Error('Non-POST should have data==null');
      req.open(method, path, true);
      req.onreadystatechange = function(e) {
        if (req.readyState == 4) {
          window.setTimeout(function() {
            if (req.status == 200 && req.responseText != '##ERROR##') {
              resolve(req.responseText);
            } else {
              reject(new Error('Error occured at ' + path));
            }
          }, 0);
        }
      };
      req.send(data);
    });
  }

  /**
   * @constructor
   */
  function XhrBasedTracingControllerClient() { }

  XhrBasedTracingControllerClient.prototype = {
    __proto__: tr.ui.e.about_tracing.TracingControllerClient.prototype,

    beginMonitoring: function(monitoringOptions) {
      var monitoringOptionsB64 = btoa(JSON.stringify(monitoringOptions));
      return beginXhr('GET', '/json/begin_monitoring?' + monitoringOptionsB64);
    },

    endMonitoring: function() {
      return beginXhr('GET', '/json/end_monitoring');
    },

    captureMonitoring: function() {
      return beginXhr('GET', '/json/capture_monitoring_compressed').then(
        function(data) {
          var decoded_size = tr.b.Base64.getDecodedBufferLength(data);
          var buffer = new ArrayBuffer(decoded_size);
          tr.b.Base64.DecodeToTypedArray(data, new DataView(buffer));
          return buffer;
        }
      );
    },

    getMonitoringStatus: function() {
      return beginXhr('GET', '/json/get_monitoring_status').then(
          function(monitoringOptionsB64) {
            return JSON.parse(atob(monitoringOptionsB64));
          });
    },

    getCategories: function() {
      return beginXhr('GET', '/json/categories').then(
          function(json) {
            return JSON.parse(json);
          });
    },

    beginRecording: function(recordingOptions) {
      var recordingOptionsB64 = btoa(JSON.stringify(recordingOptions));
      return beginXhr('GET', '/json/begin_recording?' +
                      recordingOptionsB64);
    },

    beginGetBufferPercentFull: function() {
      return beginXhr('GET', '/json/get_buffer_percent_full');
    },

    endRecording: function() {
      return beginXhr('GET', '/json/end_recording_compressed').then(
        function(data) {
          var decoded_size = tr.b.Base64.getDecodedBufferLength(data);
          var buffer = new ArrayBuffer(decoded_size);
          tr.b.Base64.DecodeToTypedArray(data, new DataView(buffer));
          return buffer;
        }
      );
    },

    defaultTraceName: function() {
      return 'trace.json.gz';
    }
  };

  return {
    XhrBasedTracingControllerClient: XhrBasedTracingControllerClient
  };
});
</script>


text:
<?php global $redux_builder_amp;  ?>
<!doctype html>
<html amp <?php echo AMP_HTML_Utils::build_attributes_string( $this->get( 'html_tag_attributes' ) ); ?>>

	<meta charset="utf-8">
  <link rel="dns-prefetch" href="https://cdn.ampproject.org">
	<?php $paged = get_query_var( 'paged' );
		$current_search_url =trailingslashit(get_home_url())."?s=".get_search_query();
		$amp_url = untrailingslashit($current_search_url);
		if ($paged > 1 ) {
			global $wp;
			$current_archive_url 	= home_url( $wp->request );
			$amp_url 				= trailingslashit($current_archive_url);
			$remove 				= '/'. AMPFORWP_AMP_QUERY_VAR;
			$amp_url				= str_replace($remove, '', $amp_url) ;
			$amp_url 				= $amp_url ."?s=".get_search_query();
		} ?>
	<?php do_action( 'amp_post_template_head', $this ); ?>

<body <?php ampforwp_body_class('amp_home_body design_2_wrapper');?> >
<?php do_action('ampforwp_body_beginning', $this); ?>
<?php $this->load_parts( array( 'header-bar' ) ); ?>
<?php do_action( 'ampforwp_after_header', $this ); ?>

	<?php do_action('ampforwp_post_before_loop') ?>
	<?php
		if ( get_query_var( 'paged' ) ) {
	        $paged = get_query_var('paged');
	    } elseif ( get_query_var( 'page' ) ) {
	        $paged = get_query_var('page');
	    } else {
	        $paged = 1;
	    }

	    $exclude_ids = get_option('ampforwp_exclude_post');

		$q = new WP_Query( array(
			's' 				  => get_search_query() ,
			'ignore_sticky_posts' => 1,
			'paged'               => esc_attr($paged),
			'post__not_in' 		  => $exclude_ids,
			'has_password' 		  => false,
			'post_status'		  => 'publish'
		) ); ?>

<?php echo ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:' ) . '  ' . get_search_query();?>

		<?php if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
			$ampforwp_amp_post_url = trailingslashit( trailingslashit( get_permalink() ) . AMPFORWP_AMP_QUERY_VAR ); ?>

			<?php if ( has_post_thumbnail() || ( ampforwp_is_custom_field_featured_image() && ampforwp_cf_featured_image_src() ) ) {
				if ( has_post_thumbnail()) {
					$thumb_id = get_post_thumbnail_id();
					$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
					$thumb_url = $thumb_url_array[0];
					}
				else{
					$thumb_url = ampforwp_cf_featured_image_src();
				}
				?>

<a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"><amp-img src=<?php echo $thumb_url ?> width=100 height=75></amp-img>

			<?php } ?>

 <a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"> <?php the_title(); ?>

				<?php if(has_excerpt()){
						$content = get_the_excerpt();
					}else{
						$content = get_the_content();
					} ?>

<?php echo wp_trim_words( strip_shortcodes(  $content ) , '15' ); ?>

		<?php endwhile; ?>

<?php next_posts_link( ampforwp_translation($redux_builder_amp['amp-translator-next-text'] . ' »' ,'Next' ), 0 ) ?>

<?php previous_posts_link( '« '. ampforwp_translation($redux_builder_amp['amp-translator-previous-text'], 'Previous') ); ?>

	<?php else: ?>

				<?php echo ampforwp_translation($redux_builder_amp['amp-translator-search-no-found'],
				'It seems we can\'t find what you\'re looking for. '); ?>

	<?php endif; ?>
	 <?php wp_reset_postdata(); ?>
	<?php do_action('ampforwp_post_after_loop') ?>

<?php do_action( 'amp_post_template_above_footer', $this ); ?>
<?php $this->load_parts( array( 'footer' ) ); ?>
<?php do_action( 'amp_post_template_footer', $this ); ?>


text:
"use strict";

import Reflux from "reflux";

import { CauseActions } from "../actions";
import { CauseResource } from "../resources";

export default Reflux.createStore(
  { listenables: CauseActions
  , init: function() {
      this.causes = [];
    }
  , getCauses: function() { return this.causes; }
  , setCauses: function(causes) { this.causes = causes; }
  , triggerChange: function() {
      this.trigger(this.getCauses());
    }
  /* listCauses */
  , onListCauses: function() {
      CauseResource.listCauses(
        (err, res, body) => {
          this.setCauses(JSON.parse(body));
          CauseActions.listCauses.completed();
        }
      , (err, res, body) => {
          CauseActions.listCauses.failed(err);
        }
      );
    }
  , onListCausesCompleted: function() { this.triggerChange(); }
  , onListCausesFailed: function(err) { console.log(err); }
  }
);


text:
package org.hisp.dhis.validation.notification;

import org.hisp.dhis.message.MessageService;
import org.hisp.dhis.scheduling.TaskId;
import org.hisp.dhis.security.NoSecurityContextRunnable;
import org.hisp.dhis.system.notification.NotificationLevel;
import org.hisp.dhis.system.notification.Notifier;
import org.hisp.dhis.system.util.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Stian Sandvold
 */
public class ValidationResultNotificationTask
    extends NoSecurityContextRunnable
{

    @Autowired
    private ValidationNotificationService notificationService;

    @Autowired
    private MessageService messageService;

    @Autowired
    private Notifier notifier;

    public static final String KEY_TASK = "validationResultNotificationTask";

    private TaskId taskId;

    public void setTaskId( TaskId taskId )
    {
        this.taskId = taskId;
    }

    // -------------------------------------------------------------------------
    // Runnable implementation
    // -------------------------------------------------------------------------

    @Override
    public void call()
    {
        final Clock clock = new Clock().startClock();

        notifier.notify( taskId, "Sending new validation result notifications" );

        try
        {
            runInternal();

            notifier.notify( taskId, NotificationLevel.INFO,
                "Sent validation result notifications: " + clock.time(), true );
        }
        catch ( RuntimeException ex )
        {
            notifier.notify( taskId, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true );

            messageService
                .sendSystemErrorNotification( "Sending validation result notifications failed", ex );

            throw ex;
        }
    }

    @Transactional
    private void runInternal()
    {

        notificationService.sendUnsentNotifications();

    }
}


text:
package org.nmrg.common.config.druid;

import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

import com.alibaba.druid.support.http.WebStatFilter;

/**
 **
 ** @ClassName: DruidStatFilter
 ** @Description: TODO
 ** @author CC
 ** @date 2017年7月25日 - 下午3:26:13
 */
@WebFilter(filterName="druidWebStatFilter"
	,urlPatterns="/*",
    initParams={
        @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
	}
)
public class DruidStatFilter extends WebStatFilter {

}


text:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace IppDotNetSdkQuickBooksApiV3SampleWebFormsApp {

    public partial class SiteMaster {

        /// <summary>
        /// HeadContent control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.ContentPlaceHolder HeadContent;

        /// <summary>
        /// blueDotMenu control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.HtmlControls.HtmlGenericControl blueDotMenu;

        /// <summary>
        /// FeaturedContent control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.ContentPlaceHolder FeaturedContent;

        /// <summary>
        /// MainContent control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.ContentPlaceHolder MainContent;

        /// <summary>
        /// FooterContent control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.ContentPlaceHolder FooterContent;
    }
}


text:
class TreeNode:
    def __init__(self, **kwargs):
        self.children = dict()

    def get(self, key):
        return self.children.get(key, None)

    def get_children(self, sort=False):
        if sort:
            return sorted(self.children.values())
        return self.children.values()

    def add(self, key, node=None, **kwargs):
        if key not in self.children:
            if node is None:
                node = self.__class__(**kwargs)
            self.children[key] = node
        return self.children[key]

    def set(self, key, val, **kwargs):
        self.children[key] = val
        return self.children[key]

class OrderedTreeNode:
    def __init__(self, **kwargs):
        self.children = list()

    def get(self, index):
        return self.children[index]

    def get_children(self, sort=False):
        if sort:
            return sorted(self.children)
        return self.children

    def add(self, node=None, **kwargs):
        if node is None:
            node = self.__class__(**kwargs)
        self.children.append(node)
        return self.children[-1]

    def set(self, index, val, **kwargs):
        self.children[index] = val
        return self.children[index]

class Tree:
    def __init__(self, root=None, node_class=TreeNode, **kwargs):
        if root is None:
            root = node_class(**kwargs)
        self.root = root
        self.node_class = node_class

    def get_children(self, node, sort=False):
        return node.get_children(sort=sort)

    def dfs(self, action=None, pre_action=None, post_action=None, sort=False):
        assert(action is None or (pre_action is None and post_action is None))
        if action is not None and pre_action is None and post_action is None:
            pre_action = post_action = action

        def visit(node, depth=0, parent=None):
            if pre_action:
                if pre_action(node, depth, parent):
                    return
            for n in self.get_children(node, sort=sort):
                visit(n, depth+1, node)
                if post_action:
                    if post_action(node, depth, parent):
                        return

        visit(self.root)