SHARE
TWEET

Untitled

Equidea Nov 9th, 2019 (edited) 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace Equine;
  4.  
  5. define('COLOR_BLACK', 1);
  6. define('COLOR_SEALBROWN', 2);
  7.  
  8. define('COLOR_BAY', 3);
  9. define('COLOR_WILDBAY', 4);
  10.  
  11. define('COLOR_CHESTNUT', 5);
  12. define('COLOR_FLAXEN_CHESTNUT', 6);
  13.  
  14. function inherit(ColorDna $mother, ColorDna $father) : ColorDna
  15. {
  16.     $randomGene = function(array $genes) : string {
  17.         return $genes[array_rand($genes)];
  18.     };
  19.        
  20.     $motherAlleles = $mother->getAllAlleles();
  21.     $fatherAlleles = $father->getAllAlleles();
  22.        
  23.     $childAlleles = [];
  24.        
  25.     foreach (array_keys($motherAlleles) as $allele)
  26.     {
  27.         $childAlleles[$allele] = [
  28.             $randomGene($motherAlleles[$allele]),
  29.             $randomGene($fatherAlleles[$allele])
  30.         ];
  31.     }
  32.        
  33.     $child = new ColorDna();
  34.     $child->setAllAlleles($childAlleles);
  35.     return $child;
  36. }
  37.  
  38. function findBasePhenotype(ColorDna $dna) : int
  39. {
  40.     if ($dna->extensionHas(ColorDna::EXTENSION_ACTIVE))
  41.     {
  42.         if ($dna->agoutiHas(ColorDna::AGOUTI_WILDBAY)) {
  43.             return COLOR_WILDBAY;
  44.         }
  45.        
  46.         if ($dna->agoutiHas(ColorDna::AGOUTI_BAY)) {
  47.             return COLOR_BAY;
  48.         }
  49.        
  50.         if ($dna->agoutiHas(ColorDna::AGOUTI_SEALBROWN)) {
  51.             return COLOR_SEALBROWN;
  52.         }
  53.        
  54.         return COLOR_BLACK;
  55.     } else
  56.     {
  57.         if ($dna->flaxenHas(ColorDna::FLAXEN_ACTIVE)) {
  58.             return COLOR_FLAXEN_CHESTNUT;
  59.         }
  60.        
  61.         return COLOR_CHESTNUT;
  62.     }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top