private void VisColor_Click(object sender, EventArgs e) { ColorChoice.ShowDialog(); ColorVars = ColorChoice.Color; Control C = (sender as Control); C.BackColor = ColorVars; C.Text = ""; }
public void setColor(ColorChoice c) { Color color = new Color(1, 0, 1); // default switch (c) { case ColorChoice.red: color = new Color(1, 0, 0); break; case ColorChoice.green: color = new Color(0, 1, 0); break; case ColorChoice.blue: color = new Color(0, 0, 1); break; default: break; } creature.color = color; }
private void processEvent() { int turn = this.gameOperator.Round.Current.Turn; LilyAcolasia.CardGame game = this.gameOperator.Round.Current; LilyAcolasia.GameInput input = this.gameEnumerator.Current; this.frameCounter++; if (this.currentGameState == GameState.RoundEnd) { if (!GameEffect.IsRoundEnd) { if (this.gameOperator.Round.HasNextRound()) { StartRound(); } else { this.currentGameState = GameState.GameEnding; var round = this.gameOperator.Round; this.frameCounter = 0; if (round.Point1 > round.Point2) { if (level == 4) { achievements.WarfareLost(); } else if (level == 1) { achievements.MimicLost(); } else if (level == 0) { achievements.HumanLost(); } gameEndingState = 0; } else if (round.Point1 < round.Point2) { if (level == 4) { achievements.WarfareWin(); } else if (level == 1) { achievements.MimicWin(); } else if (level == 0) { achievements.HumanWin(); } bool isPerfect = true; foreach (LilyAcolasia.Field f in game.Fields) { if (f.Winner != USER_TURN) { isPerfect = false; break; } } if (isPerfect) { achievements.Perfect(); } gameEndingState = 1; } else { if (level == 4) { achievements.WarfareDraw(); } else if (level == 1) { achievements.MimicDraw(); } else if (level == 0) { achievements.HumanDraw(); } gameEndingState = 2; } } } } else if (this.currentGameState == GameState.GameEnding) { this.bgmSource.volume *= 0.95f; if (frameCounter > GAME_ENDING_WAIT) { if (gameEndingState == 0) { GameEffect.GameEnd(0); audioSource.clip = soundGameLost; audioSource.Play(); } else if (gameEndingState == 1) { GameEffect.GameEnd(1); audioSource.clip = soundGameWin; audioSource.Play(); } else if (gameEndingState == 2) { GameEffect.GameEnd(2); audioSource.clip = soundGameDraw; audioSource.Play(); } this.currentGameState = GameState.GameEnd; this.frameCounter = 0; } } else if (this.currentGameState == GameState.GameEnd) { if (!GameEffect.IsGameEnd) { if (Input.GetMouseButtonDown(0)) { CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0.5f, () => { if (this.netuser != null) { this.netuser.Close(); DestroyObject(this.netuser.gameObject); } SceneManager.LoadScene("Title"); }); } else if (demoAi != null) { demoAi = null; CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0.5f, () => { if (this.netuser != null) { this.netuser.Close(); DestroyObject(this.netuser.gameObject); } SceneManager.LoadScene("Game"); }); } } } else if (this.currentGameState == GameState.CutIn) { if (!GameEffect.IsCutIn) { int n = game.LastTrashed.Power; if (n == 5) { if (demoAi == null && game.Turn == USER_TURN) { this.currentGameState = GameState.ColorChoice; ColorChoice.Show((color) => { LilyAcolasia.GameInput ipt = this.gameEnumerator.Current; ipt.input(LilyAcolasia.Command.Special, color); this.gameEnumerator.MoveNext(); this.currentGameState = GameState.UserAction; audioSource.clip = soundSkillColor; audioSource.Play(); }); } else { this.currentGameState = GameState.AIAction; } } else if (n == 9) { this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction; } else { GameEffect.Special(n, game.Turn); this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction; } this.frameCounter = 0; } } else if (this.currentGameState == GameState.RoundStart) { if (this.frameCounter >= TURN_WAIT) { this.frameCounter = 0; this.currentGameState = GameState.TurnStart; } } else if (this.currentGameState == GameState.TurnStart) { if (this.frameCounter >= TURN_WAIT) { this.frameCounter = 0; this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction; } } else if (this.currentGameState == GameState.CmdWait) { if (this.frameCounter >= CMD_WAIT) { this.frameCounter = 0; if (game.Status == LilyAcolasia.GameStatus.Status.End) { input.input(LilyAcolasia.Command.Next); this.gameEnumerator.MoveNext(); if (game.Status == LilyAcolasia.GameStatus.Status.RoundEnd) { this.currentGameState = GameState.RoundEnd; GameEffect.RoundEnd(game.Winner); } else { this.currentGameState = GameState.TurnStart; } } else if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput) { GameEffect.Special(-1, game.Turn); input.input(LilyAcolasia.Command.Special); this.gameEnumerator.MoveNext(); } else { this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction; } } } else if (this.currentGameState == GameState.UserAction) { if (this.demoAi != null) { if (game.Status != LilyAcolasia.GameStatus.Status.WaitSpecialInput || this.frameCounter >= AI_WAIT) { this.frameCounter = 0; var next = demoAi.next(game); input.input(next.Item1, next.Item2, next.Item3.ToString()); this.gameEnumerator.MoveNext(); this.frameCounter = 0; this.currentGameState = GameState.CmdWait; GameEffect.Special(-1, game.Turn); if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput) { GameEffect.CutIn(game.LastTrashed.Power); audioSource.clip = soundCutIn; audioSource.Play(); this.currentGameState = GameState.CutIn; } } } else { if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput && !game.LastTrashed.HasSpecialInput) { this.currentGameState = GameState.CmdWait; this.frameCounter = 0; GameEffect.Special(game.LastTrashed.Power, game.Turn); } } this.frameCounter = 0; } else if (this.currentGameState == GameState.AIAction) { if (game.Status != LilyAcolasia.GameStatus.Status.WaitSpecialInput || this.frameCounter >= AI_WAIT) { this.frameCounter = 0; if (this.level == 0) { if (!netuser.IsConnected) { GameEffect.GameEnd(3); this.netuser.Close(); DestroyObject(this.netuser.gameObject); this.currentGameState = GameState.GameEnd; return; } string next = netuser.message(); if (next == null) { GameEffect.GameEnd(3); this.netuser.Close(); DestroyObject(this.netuser.gameObject); this.currentGameState = GameState.GameEnd; return; } else if (next == "") { return; } input.input(next); } else { var next = ai.next(game); input.input(next.Item1, next.Item2, next.Item3.ToString()); } this.gameEnumerator.MoveNext(); this.frameCounter = 0; this.currentGameState = GameState.CmdWait; GameEffect.Special(-1, game.Turn); if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput) { GameEffect.CutIn(game.LastTrashed.Power); audioSource.clip = soundCutIn; audioSource.Play(); this.currentGameState = GameState.CutIn; } } } }
/* * create creature, * create and save creature resource, * create creature network, * create network node, * add resource to node, * save creature to founder creatures dict and species dict */ public void addSpecies(string name, ColorChoice color, float mutationDeviation, string primaryConsume, string dependentOn, string produces, float mutationDeviationFraction, float lowestMutationDeviation, bool nonLinearPhenotypeNet, int phenotype, int turnTime) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, phenotype, turnTime, 1000, 700, 3, 10, mutationDeviation, color, true, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // user edits: List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); //Debug.Log("resource added to creature: " + ecosystemResources[0]); // add creature resource store for primary resource that creature needs ResourceEditor resourceCreator = cc.addResource(); EcoCreationHelper.addCreatureResource(resourceCreator, primaryConsume, 100, 90, 1, 90, 5, 20, 1); cc.saveResource(); // add creature resource store for resouce creature produces // Note: Creature 1 doesn't need this resource to survive (no health gain or drain) resourceCreator = cc.addResource(); EcoCreationHelper.addCreatureResource(resourceCreator, produces, 100, 90, 0, 90, 0, 20, 1); cc.saveResource(); // add creature resource store for resouce creature is dependent on resourceCreator = cc.addResource(); // high starting level, so that population doesn't die out immediately EcoCreationHelper.addCreatureResource(resourceCreator, dependentOn, 100, 90, 1, 50, 1, 5, 1); cc.saveResource(); // for reference later List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // generates movement actions with a resource cost cc.generateMovementActions(primaryConsume, 5); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eat" + primaryConsume, 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, primaryConsume); cc.saveAction(); // create action for consuming Resource that creature is dependent on ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eat" + dependentOn, 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, dependentOn); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { primaryConsume, 20 }, { dependentOn, 50 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // action for converting with a 1 to 2 ratio ae = cc.addAction(); ae.setCreator(ActionCreatorType.convertEditor); ConvertEditor convEdit = (ConvertEditor)ae.getActionCreator(); resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; EcoCreationHelper.setBasicActionParams(convEdit, "convert" + primaryConsume + "To" + produces, 1, 10, resourceCosts); Dictionary <string, float> startResources = new Dictionary <string, float>() { { primaryConsume, 1f } }; Dictionary <string, float> endResources = new Dictionary <string, float>() { { produces, 10f } }; EcoCreationHelper.setConvertActionParams(convEdit, 5, startResources, endResources); cc.saveAction(); // action for depositing B ae = cc.addAction(); ae.setCreator(ActionCreatorType.depositEditor); DepositEditor depEdit = (DepositEditor)ae.getActionCreator(); // no resource costs for depositing EcoCreationHelper.setBasicActionParams(depEdit, "deposit" + produces, 1, 10, null); EcoCreationHelper.setDepositActionParams(depEdit, 0, produces, 10); cc.saveAction(); // user opens networks creator for that creature /**** phenotype network template ****/ PhenotypeNetworkEditor phenoNetCreator = (PhenotypeNetworkEditor)cc.addNetwork(NetworkType.phenotype); List <string> phenoOutputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; if (nonLinearPhenotypeNet) { EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 4, 2, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); } else { EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 0, 0, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); } // Note: don't call saveNetwork(), call savePhenotypeNetwork() cc.savePhenotypeNetwork(); //Debug.Log("finished creating phenotype net"); // create network to sense external resource levels /**** net1 ****/ // user adds a network NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); List <string> resourcesToSense = creatureResources; // sense resources creature can store List <string> outputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "externalNet", resourcesToSense, outputActions, 1, 6, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally resourcesToSense = creatureResources; // use all output actions again outputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 1, 6, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetEat" + primaryConsume, "eat" + primaryConsume }, { "outNetEat" + dependentOn, "eat" + dependentOn }, { "outNetRepro", "reproduce" }, { "outNetDeposit" + produces, "deposit" + produces }, { "outNetConvert", "convert" + primaryConsume + "To" + produces } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); //cc.creature.printNetworks(); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
void Awake() { colorChoice = this; this.spriteRenderer = GetComponent <SpriteRenderer>(); }
public void addPlant(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 1, 100, 1000, 700, 3, 10, mutationDeviation, color, false, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "energy", 1000, 800, 1, 900, 10, 100, 1); cc.saveResource(); resourceCreator = cc.addResource(); ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 20, 0, 90, 0, 20, 0); cc.saveResource(); // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); List <string> predatorList = new List <string>() { "cow" }; cc.addDefenseAbilities(predatorList); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>(); // no resource cost // set parameters EcoCreationHelper.setBasicActionParams(cle, "photosynth", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "energy"); cc.saveAction(); ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { "energy", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "energy", 30 }, { "vitamin", 10 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // user opens networks creator for that creature // user adds a network /* * NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); * List<string> resourcesToSense = creatureResources; // sense resources creature can store * List<string> outputActions = new List<string>() * { * "reproduce", * "photosynth", * "eatVitamin", * }; * * EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "SensoryNet", resourcesToSense, outputActions, 0, 0, * ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); * * * // user clicks save on network creator * cc.saveNetwork(); */ // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally List <string> resourcesToSense = creatureResources; // use all output actions again List <string> outputActions = new List <string>() { "reproduce", "photosynth", "eatVitamin", }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetPhoto", "photosynth" }, { "outNetRepro", "reproduce" }, { "outNetEatVit", "eatVitamin" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
/* ************************************************************************************************************************** */ public void addCarnivore(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation, string prey) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 3, 100, 1000, 700, 3, 10, mutationDeviation, color, true, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "energy", 1000, 800, 1, 900, 5, 200, 1); cc.saveResource(); /* * resourceCreator = cc.addResource(); * ecosystemResources = new List<string>(ecosystem.resourceOptions.Keys); * EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 10, 0, 90, 0, 20, 0); * cc.saveResource(); */ // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // TODO create default actions for creature action pool, and example user made action // (should use add an action creator to creature creator) cc.generateMovementActions("energy", .5f); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); // if predator List <string> preyList = new List <string>() { "cow" }; cc.addAttackAbilities(preyList); cc.saveAbilities(); // create action for consuming primary resource /* * ae = cc.addAction(); * ae.setCreator(ActionCreatorType.consumeCreator); * cle = (ConsumeFromLandEditor)ae.getActionCreator(); * // define resource costs * resourceCosts = new Dictionary<string, float>() * { * {"energy", 1}, * }; * // set parameters * EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); * EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); * cc.saveAction(); */ //createAttackAction ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.attackEditor); AttackEditor attackEdit = (AttackEditor)ae.getActionCreator(); Dictionary <string, float> resourceCosts = new Dictionary <string, float> { { "energy", .2f } }; EcoCreationHelper.setBasicActionParams(attackEdit, "eatCow", 1, 10, resourceCosts); EcoCreationHelper.setAttackActionParams(attackEdit, "cow", 1, .9f); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "energy", 200 }, //{"vitamin", 10} }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally List <string> resourcesToSense = creatureResources; // use all output actions again List <string> outputActions = new List <string>() { "reproduce", "eatCow", //"eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight", }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); PhenotypeNetworkEditor phenoNetCreator = (PhenotypeNetworkEditor)cc.addNetwork(NetworkType.phenotype); List <string> phenoOutputActions = new List <string>() { "reproduce", "eatCow", //"eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight", }; EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 0, 0, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // Note: don't call saveNetwork(), call savePhenotypeNetwork() cc.savePhenotypeNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetRepro", "reproduce" }, //{"outNetEatVit", "eatVitamin" }, { "outNetEatCow", "eatCow" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
/* * create creature, * create and save creature resource, * create creature network, * create network node, * add resource to node, * save creature to founder creatures dict and species dict */ public void addSpecies(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation, bool loadPrev, int turnTime) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 3, turnTime, 1000, 700, 3, 10, mutationDeviation, color, false, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "grass", 100, 80, 1, 90, 10, 20, 1); cc.saveResource(); resourceCreator = cc.addResource(); ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 10, 0, 90, 0, 20, 0); cc.saveResource(); // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // TODO create default actions for creature action pool, and example user made action // (should use add an action creator to creature creator) cc.generateMovementActions("grass", 5); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>() { { "grass", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatGrass", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "grass"); cc.saveAction(); ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { "grass", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "grass", 40 }, { "vitamin", 10 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // user opens networks creator for that creature // user adds a network NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); List <string> resourcesToSense = creatureResources; // sense resources creature can store List <string> outputActions = new List <string>() { "reproduce", "eatGrass", "eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "SensoryNet", resourcesToSense, outputActions, 1, 9, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally resourcesToSense = creatureResources; // use all output actions again outputActions = new List <string>() { "reproduce", "eatGrass", "eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 1, 9, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetEat", "eatGrass" }, { "outNetRepro", "reproduce" }, { "outNetEatVit", "eatVitamin" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); if (loadPrev) { cc.loadWeightsFromFile(); } // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
/// <summary> /// Set basic parameters for a creature type. /// </summary> /// <param name="ce">Creature wrapper.</param> /// <param name="name">Name of creature.</param> /// <param name="phenotype">Phenotype of creature (potentially sensed by other creatures).</param> /// <param name="turnTime">The amount of time given for a creature's turn. It's recommended to use the same turn time for all creatures.</param> /// <param name="maxHealth">The maximum possible health a creature can achieve.</param> /// <param name="initialHealth">The initial health of the creature when a population is created. Note that a child inherits the health of it's parent, and doesn't use this value.</param> /// <param name="actionClearInterval">The action queue is cleared at intervals of this number of steps.</param> /// <param name="actionClearSize">The size that the action queue must reach before it is cleared.</param> /// <param name="mutationDeviation">The initial amount of mutation that occurs with reproduction.</param> /// <param name="color">The color of the creature.</param> /// <param name="usePhenoNet">Chose wether creature should sense the phenotypes of it's neighbors. If so, you must create a phenotype network template.</param> /// <param name="mutationDeviationFraction">The number that the mutation deviation is multiplied by each time a creature reproduces. This new deviation is passed on to the child. This can be used to slowy reduce the amount of variability in the population.</param> /// <param name="lowestMutationDeviation">The lowest value that the mutation deviation can reach, even with the mutationDeviationFraction.</param> /// <param name="mutationType">The type of mutation being used.</param> public static void setCreatureStats(CreatureEditor ce, string name, int phenotype, float turnTime, float maxHealth, float initialHealth, int actionClearInterval, int actionClearSize, float mutationDeviation, ColorChoice color, bool usePhenoNet, float mutationDeviationFraction, float lowestMutationDeviation, MutationDeviationCoefficientType mutationType) { ce.setSpecies(name); ce.setPhenotype(phenotype); ce.setTurnTime(turnTime); ce.setMaxHealth(maxHealth); ce.setInitialHealth(initialHealth); ce.setActionClearInterval(actionClearInterval); ce.setActionClearSize(actionClearSize); ce.setMutationStandardDeviation(mutationDeviation); ce.setColor(color); ce.setUsePhenotypeNet(usePhenoNet); ce.setAnnealMutationFraction(mutationDeviationFraction); ce.setBaseMutationDeviation(lowestMutationDeviation); ce.setMutationCoeffType(mutationType); }
public BlocksGeneration(int parentHeight, int parentWidth) { colorChoice = new ColorChoice(); _parentHeight = parentHeight; _parentWidth = parentWidth; }
public IActionResult SetColor([Bind("Color")] ColorChoice colorChoice) { HttpContext.Session.SetString("Color", colorChoice.Color); return(RedirectToAction(nameof(ShowAllProducts))); }
public Bitmap Construct(out Dictionary <string, RectangleF> Borders) { if (serviceObjectNew) { serviceObjectNew = false; } else { die("This object has been used. Dispose this, create and use a new Service object."); } var theCloudBitmap = new Bitmap(width, height); var gImage = Graphics.FromImage(theCloudBitmap); gImage.TextRenderingHint = TextRenderingHint.AntiAlias; Center = new PointF(theCloudBitmap.Width / 2f, theCloudBitmap.Height / 2f); if (Angle != 0) { gImage.Rotate(Center, Angle); } weightSpan = highestWeight - lowestWeight; if (MaximumFontSize < MinimumFontSize) { die("MaximumFontSize is less than MinimumFontSize"); } fontHeightSpan = MaximumFontSize - MinimumFontSize; gImage.Clear(ColorChoice.GetBackGroundColor()); foreach (var tag in tagsSorted) { var fontToApply = new Font(SelectedFont, CalculateFontSize(tag.Value)); var stringBounds = gImage.MeasureString(tag.Key, fontToApply); var format = DisplayChoice.GetFormat(); var isVertical = format.FormatFlags.HasFlag(StringFormatFlags.DirectionVertical); if (isVertical) { var stringWidth = stringBounds.Width; stringBounds.Width = stringBounds.Height; stringBounds.Height = stringWidth; } var topLeft = CalculateWhere(stringBounds); /* Strategy chosen display format, failed to be placed */ if (topLeft.Equals(spiralEndSentinel)) { WordsSkipped.Add(tag.Key, tag.Value); continue; } var textCenter = isVertical & VerticalTextRight ? new PointF(topLeft.X + (stringBounds.Width / 2f), topLeft.Y + (stringBounds.Height / 2f)) : topLeft; var currentBrush = new SolidBrush(ColorChoice.GetCurrentColor()); if (isVertical & VerticalTextRight) { gImage.Rotate(textCenter, -180); } gImage.DrawString(tag.Key, fontToApply, currentBrush, topLeft, format); if (isVertical & VerticalTextRight) { gImage.Rotate(textCenter, 180); } if (ShowWordBoundaries) { gImage.DrawRectangle(new Pen(currentBrush), topLeft.X, topLeft.Y, stringBounds.Width, stringBounds.Height); } Occupied.Add(new RectangleF(topLeft, stringBounds)); } gImage.Dispose(); Occupied.RemoveRange(0, 4); if (Crop) { theCloudBitmap = CropAndTranslate(theCloudBitmap); } Borders = Occupied .Zip(tagsSorted.Keys.Where(word => !WordsSkipped.ContainsKey(word)), (rect, tag) => new { rect, tag }) .ToDictionary(x => x.tag, x => x.rect); return(theCloudBitmap); }