Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Algorithm-
- 1) Calculate the fitness for N elemenets
- 2) Reproduction/Selection
- - pick 2 "parents" ( the more fitness they have, the higher the chance of them being picked is)
- - making a new element by
- 1. crossover
- 2. mutation
- */
- function generateRandomLetter(){
- var possible = "abcdefghijklmnopqrstuvwxyz";
- return possible[Math.floor(Math.random()*possible.length)] ;
- }
- class DNA{
- constructor(){
- this.genes = [];
- this.createRandomGenerationOfNElements(10);
- this.fitness = 0;
- this.mutationLikelihood = 1; // in percentage
- }
- createRandomGenerationOfNElements(n){
- for(let i = 0;i < n;i++){
- this.genes.push(generateRandomLetter());
- }
- }
- mutate(){
- // TO DO
- }
- crossover(){
- // TO DO
- }
- calcFitness(){
- // TO DO
- }
- }
- var dna = new DNA();
- function makeBorders(){
- context.strokeRect(1,1,canvas.width-1,canvas.height-1);
- }
- function update(){
- }
- function draw(){
- makeBorders();
- //context.fillRect(500,300,20,20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement