SHARE
TWEET

JS

a guest Feb 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3. Algorithm-
  4. 1) Calculate the fitness for N elemenets
  5. 2) Reproduction/Selection
  6. - pick 2 "parents" ( the more fitness they have, the higher the chance of them being picked is)
  7. - making a new element by
  8. 1. crossover
  9. 2. mutation
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. */
  17.  
  18. function generateRandomLetter(){
  19.     var possible = "abcdefghijklmnopqrstuvwxyz";
  20.     return possible[Math.floor(Math.random()*possible.length)] ;
  21. }
  22.  
  23. class DNA{
  24.     constructor(){
  25.         this.genes = [];
  26.         this.createRandomGenerationOfNElements(10);
  27.         this.fitness = 0;
  28.         this.mutationLikelihood = 1; // in percentage
  29.     }
  30.     createRandomGenerationOfNElements(n){
  31.         for(let i = 0;i < n;i++){
  32.             this.genes.push(generateRandomLetter());
  33.         }
  34.     }
  35.     mutate(){
  36.         // TO DO
  37.     }
  38.     crossover(){
  39.         // TO DO
  40.     }
  41.     calcFitness(){
  42.         // TO DO
  43.     }
  44. }
  45. var dna = new DNA();
  46. function makeBorders(){
  47.     context.strokeRect(1,1,canvas.width-1,canvas.height-1);
  48. }
  49. function update(){
  50.    
  51. }
  52. function draw(){
  53.     makeBorders();
  54.     //context.fillRect(500,300,20,20);
  55. }
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
 
Top