diff --git a/docs/algorithms.md b/docs/en/algorithms.md similarity index 100% rename from docs/algorithms.md rename to docs/en/algorithms.md diff --git a/docs/principles.md b/docs/en/genome.md similarity index 62% rename from docs/principles.md rename to docs/en/genome.md index 4ed9bd1..06b19bb 100644 --- a/docs/principles.md +++ b/docs/en/genome.md @@ -1,4 +1,4 @@ -# Principles +# Genome This document describes principles I have came up with. I don't think I'd be angry if you use them in your projects. This document is mostly for me to remember things. @@ -28,25 +28,35 @@ Type of gene is enum that provides different functions. Here is (Very WIP) list Dummy - gene without behaviour. -Transfer - gene that defines rules of flow. -- `distribute_between_children(,flow: mut ) -> ` +Transport - gene that defines rules of flow. +- `distribute_between_children() -> ChildDistribution` -Pure Generator - gene that only creates flow. -- `create_flow(,current_flow: mut ) -> ` - won't be called if flow isn't empty. +Pure Producer - gene that only creates flow. +- `create_flow(,current_flow: mut Flow) -> Flow` - won't be called if flow isn't empty. -Modifier - gene that modifies or creates flow. -- `modify_flow(,current_flow: mut ) -> ` +Producer - gene that creates or modifies flow. +- `create_flow() -> Flow` - called if ProduceDecision::CreateFlow +- `modify_single() -> Flow` - called if ProduceDecision::ModifySingle +- `modify_all() -> Flow` - called if ProduceDecision::ModifyAll + +Modifier - gene that only modifies flow. +- `modify_flow() -> Flow` Consumer - gene that consumes flow. - `consume()` Trigger - gene that interacts with context to conditionally progress flow. - `check_trigger() -> bool` +- `distribute_between_children() -> ChildDistribution` - same as Transport Observer - gene that observes flow. -- `observe(,current_flow: mut )` +- `observe()` +- `distribute_between_children() -> ChildDistribution` - same as Transport ### Flow Flow is data that circulates across genome. If not consumed, goes to the void. -Currently it is something like Vec +Currently it is struct containing Vec + +### Context + consists of current Flow struct and Godot context. Godot context should at least be Plant node. diff --git a/docs/en/genome_and_player.md b/docs/en/genome_and_player.md new file mode 100644 index 0000000..c5a5886 --- /dev/null +++ b/docs/en/genome_and_player.md @@ -0,0 +1,85 @@ +# Genome and player + +This document describes principles I have came up with. I don't think I'd be angry if you use them in your projects. +This document is mostly for me to remember things. + +## Used terms +MC - Modification Currency. Currency that player spends on modifications + +## The core principles are: +- Every plant that is represented as graph can be drawn. +- Player should have all necessary instruments to create anything he likes by the end of his playthrough. +- Player's tools should progress through game + +## Progression +- Player should start small + - Player starts with somewhat of a currency to spend on modifications each level + - Player starts with allelic crossingover and "combine" tools +- Progressing through the levels, player gains the most important instruments +- Optional instruments and template plants are bought through shop + +## Levels +- Before level, player may adjust his plants collection through experimentation. + +## Planned tools +Early game: +- Allelic crossingover + - Player picks two plants, and they exchange genes that are on the same places. + - As an output, player gets two plants. + - Upgrades to "Swap places" tool + - Costs 1 MC +- Categoric crossingover + - Player picks two plants, and they exchange genes that hold the same label. + - As an output, player gets two plants. + - Upgrades to "Swap" tool + - Costs 1 MC +- Combine tool + - Player picks donor and recipient plant. Then, algorithm decides whether to replace one node or to add as a child. Then, algorithm picks subgraph from donor, and applies it to recipient. + - As an output, player gets two plants - recipient and donor. + - Upgrades to "Add" tool + - Costs 1 MC +- Random deletion tool + - Player picks one plant, and algorithm randomly deletes genes from it. + - As an output, player gets one plant. + - Upgrades to "Remove" tool + - Costs 1 MC +- Random mutation tool + - Player picks one plant. Then, algorithm mutates it randomly and uncontrollably. + - As an output, player gets one plant. + - Upgrades to "Batch mutation" tool. + - Costs 1 MC +Midgame +- Remove tool + - Player picks one plant. They might pick one or more nodes to delete. Then, selected genes are deleted. + - As an output, player gets one plant. + - Costs 1.5 MC +- Add tool + - Player picks donor and recipient plant. Then, player selects one or more genes. Then, player selects to replace or position subgraph. + - As an output, player gets two plants - recipient and donor. + - Costs 2 MC + - Upgrades to "Create" tool +- Swap tool + - Player picks two plants. They must pick first and second genes. + - As an output, player gets two plants with swapped genes. + - Costs 0.25 MC + - The cost is low because it was meant to be applied multiple times +- Swap places tool + - Player picks two plants. Then, player selects one or more genes that will be swapped. + - As an output, Player gets two plants with swapped genes. + - Costs 1.5 MC +- Batch mutation tool + - Player picks one plant. Then, player selects amount of mutations. + - As an output, Player gets one plant. + - Upgrades to "Batch controlled mutation" tool + - Costs 3 MC +- Batch controlled mutation tool + - Player picks one plant. Then, Player selects genes to mutate. + - As an output, player gets one plant. + - Costs 5 MC + +Endgame +- Create tool + - Player has genes dock. Player constructs tree from them, and then attaches it to selected plant, or creates new. + - As an output, player gets one plant. + - Costs 10 MC + diff --git a/rust-pvz-genetics/src/genetics/gene.rs b/rust-pvz-genetics/src/genetics/gene.rs index 7de6272..e52089e 100644 --- a/rust-pvz-genetics/src/genetics/gene.rs +++ b/rust-pvz-genetics/src/genetics/gene.rs @@ -39,7 +39,7 @@ pub enum GeneType { }, /// Modifies flow Modifier { - modify_flow: fn(GeneContext) -> Option + modify_flow: fn(GeneContext) -> Flow }, /// Conditionally passes through flow. Acts like transport. Trigger { @@ -101,7 +101,7 @@ impl GeneType { Self::Consumer { consume: consumer_function } } /// Creates modifier with modifier function. - pub fn modifier(modifier_function: fn(GeneContext) -> Option) -> Self { + pub fn modifier(modifier_function: fn(GeneContext) -> Flow) -> Self { Self::Modifier { modify_flow: modifier_function } } /// Creates trigger with distribution between all children.