I need help for a project in which I don’t know how to proceed, I’ll show you what I’m trying to do and the problem as well as the code.
Game board:
The game board is a matrix, of NxM positions.
Individuals and resources occupy a position in the matrix.
A position in the matrix can have 3 resources and a maximum of 3 individuals at a time. If at any time there are more than 3 individuals in a cell, those with the lowest number of life turns left will die until there are 3 individuals left.
Individuals:
The individuals in the game occupy a single square, and have as parameters:
• Individual Identification: A unique number that identifies the individual.
• Generation of the individual: Obtained according to the turn in which it was created.
• Turns of life left: Number of turns where you can continue developing.
• Probability of reproduction: If 2 individuals occupy the same position in the matrix, they either reproduce, generating another individual, or both die.
• Probability of cloning. At each step, an individual can clone themselves, and the clone will appear at the same position on the map.
• Probability of death = (1-Probability of reproduction).
The initial values of the “type individual” must be parameterizable for the game.
We will have 3 types of individuals:
- Basic type: moves randomly.
- Normal type: moves in a straight line towards a resource in the environment (selected
randomly from those available). - Advanced type: is able to make routes to the position of resources and select the resource they want to go to (the closest one that is not in the individual’s current position).
About individuals and reproduction:
• The reproduction of two individuals of the same type gives rise to another individual of that type.
• Reproduction of individuals of different types gives rise to another individual of the highest type at X percentage of game population improvement.
On each turn, the individual will be modified as follows:
Life goes down 1 turn.
The probability of reproduction drops by 10% of what the individual has at that moment.
The probability of mutation drops by 10% of what the individual has at that moment.
In a turn an individual MUST move.
Environment/resources
The environment models how the resources in it allow an individual to alter the values of its parameters. The environment is associated with static positions on the game board.
We will have 6 types of environment elements (at least). - Water, 2. Food, 3. Mountain, 4. Treasure, 5. Library, 6. Well
To simulate an evolving environment, each element of the environment has a spawn time when it will be active and visible on the map. Each position on the map can have a maximum of 3 resources at a given time: If a position has less than 3 resources, a new one can appear each turn with probability Z, parameterizable for each resource with probability V, adjustable in each game.
(Example: on turn 3 the position (4,5) has a Water resource, with an appearance time of 3. On that turn it is evaluated if a new resource can appear, to choose from the 6 possible. The calculation will use the probability Z to know if a new resource should appear or not, and if the result is positive, then the probabilities V of each type of resource will be used to choose the one that will finally appear.)
These elements of the environment will act as modifiers to the individual’s parameters: For example, Water will add 2 turns of life to the individual, Food 10 turns of life, and Mountain will decrease 2 turns of life, Treasure will increase the reproduction probability of the individual. individual by X%, while the Library will increase the cloning chance by Y% and increase the individual’s type, with the Well being instant death.
All values must be parameterizable for the game.
Control loop:
The control loop will perform the game operations in order:
- For each individual, their lifespan is updated, and if applicable it is eliminated if they have died.
- For each resource, it will evaluate whether it is still active or should be deleted (due to its appearance time).
- The movement of each individual will be executed (always mandatory).
- For each individual, the improvements obtained by the different resources found in their new position will be evaluated.
- For each position, it will evaluate whether there is reproduction or not.
- For each individual, it will evaluate whether cloning exists or not.
- For each position on the board in which there are several individuals, it will be evaluated whether some should disappear.
- For each position on the board, it will be evaluated whether new resources should appear.
Termination condition:
Only one individual remains alive or the user decides to end the simulation.
After the game:
The breeding tree of the winning item(s) (if such items exist) should be displayed, showing their family tree.
I have several problems: I can’t configure it so that only 3 resources appear in a cell, and no more than 1 of the same type.
Only individuals of type 1 make the correct movement, but not those of type 2 and type 3.
Pepito Ruiz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1