Search Unity

Game idea, where do I start?

Discussion in 'Getting Started' started by Chiran, Dec 3, 2021.

  1. Chiran

    Chiran

    Joined:
    Nov 30, 2021
    Posts:
    1
    Hello, I'm interested in making a breeding game that has realistic genetics.

    When I search though, I notice that all guides point to a genetic algorithm being the way to go.
    But the genetic algorithm seems to be...for example, Red parent x blue parent = purple.
    What Im wanting to do is more like a punnet square, Parent 1 is RrBb and Parent 2 is rrBb.
    Offspring can be Red (RrBB, RrBb, Rrbb) Blue (rrBB, rrBb) or Nonblue (rrbb) with recessives carrying through generations.

    Whats a good starting point for learning how to do this?
    Thank you
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Read different sources on genetic algorithms. There is no reason red x blue should ever = purple (unless you specifically want it to be that way).
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I'm not sure if this is what you're asking or not, but I read your post and immediately thought it might be fun to try writing real quick. Dunno if this is how genes work or not, but it may get you started on the right path, anyway. Note this is untested code written while very distracted in a meeting.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class GeneSimmons : MonoBehaviour
    5. {
    6.     private char[] parent1 = new char[] {'R', 'r', 'B', 'B'};
    7.     private char[] parent2 = new char[] {'r', 'r', 'B', 'b'};
    8.  
    9.     void Start()
    10.     {
    11.         for (int i = 0; i < 100; i++)
    12.         {
    13.             char[] child = HaveChild(parent1, parent2);
    14.             Debug.Log("Child: " + child.toString());
    15.         }
    16.     }
    17.  
    18.     private char[] HaveChild(char[] parentA, char[] parentB)
    19.     {
    20.         if (parentA.length != parentB.length) {
    21.             Debug.LogError("Genetic anomaly!");
    22.             return null;
    23.         }
    24.  
    25.         char[] child = new char[parentA.length];
    26.  
    27.         for (int i = 0; i < child.length; i++)
    28.         {
    29.             child[i] = Random.value > 0.5f ? parentA[i] : parentB[i];
    30.         }
    31.  
    32.         return child;
    33.     }
    34. }