lundi 30 août 2021

I have a bug when I am sending an array of data from each client over a server

I am working on a web app that uses a genetic algorithm to enable the user to pick the evolution of shapes - when a user makes a choice, it sends an array of data over a server, which is then retrieved on the other end and converted into a shape. I have it set up so that it only sends data when a user makes a choice, however this occasionally creates a bug that results in nothing being processed. This is where the error is occurring in my code:

receiveFit(data) {
  this.receive = data;
  
  this.dataArray.push(this.receive);    
  
  this.population = clientCount;   

  if(this.dataArray.length >= this.population){
      
      // if you want to mix them all 
      
      let i = 0;
      let start = new DNA(this.dataArray[0].genes);
      for (let dna of this.dataArray) {
        if (i!=0) {
            let current = new DNA(this.dataArray[i].genes);
            start = start.crossover(current);
        }
        
        i+=1;
      }
      
      // in theory start now is an amalgamation of all of them

        this.fittest = new Fittest(start, width/2, height/2);
        this.glyph = new Glyphs(start);
        
        this.dataArray = [];
    } 

}

I am receiving an array of data from the server, which I am then pushing onto another array. this.population is a variable that is counting the amount of people on the server - I have written an if statement that says is the array of arrays is greater than or equal to the amount of clients, execute the code that combines all of the choices.

I believe the reason it misses choices is that the array doesn't always equate to the amount of clients if someone decides not to make a choice, however I cant figure out what to do to solve this. Any advice would be appreciated!

Aucun commentaire:

Enregistrer un commentaire