private RocketParameters Crossover(RocketParameters parentA, RocketParameters parentB) { RocketParameters child = new RocketParameters(lifeSpan); int randomPick = random.Next(0, lifeSpan); for (int i = 0; i < lifeSpan; i++) { if (i <= randomPick) { child.angleCopy[i] = parentA.angleCopy[i] + random.Next(-3, 3); child.angle[i] = child.angleCopy[i]; child.force[i] = parentA.force[i] * ((float)random.Next(90, 110) / 100); } else { child.angleCopy[i] = parentB.angleCopy[i] + random.Next(-3, 3); child.angle[i] = child.angleCopy[i]; child.force[i] = parentB.force[i] * ((float)random.Next(90, 110) / 100); } if (child.force[i] <= 3) { child.force[i] *= 1.4f; //zwiekszenie sily w przypadku wartosci nizszych niz 3 dla poprawnosci dzialania programu } } return(child); }
private bool CheckForCrash(RocketParameters item) { if (item.coordinatesX[item.counter] >= btm.Width || item.coordinatesX[item.counter] <= 0 || item.coordinatesY[item.counter] >= btm.Height || item.coordinatesY[item.counter] <= 0) { item.crashed = true; return(true); } else if (item.coordinatesX[item.counter] >= obstacleCoordinate.X && item.coordinatesX[item.counter] <= obstacleCoordinate.X + obstacleCoordinate.Width && item.coordinatesY[item.counter] >= obstacleCoordinate.Y && item.coordinatesY[item.counter] <= obstacleCoordinate.Y + obstacleCoordinate.Height) { item.crashed = true; return(true); } else if (item.coordinatesX[item.counter] >= obstacleCoordinate2.X && item.coordinatesX[item.counter] <= obstacleCoordinate2.X + obstacleCoordinate2.Width && item.coordinatesY[item.counter] >= obstacleCoordinate2.Y && item.coordinatesY[item.counter] <= obstacleCoordinate2.Y + obstacleCoordinate2.Height) { item.crashed = true; return(true); } else if (item.coordinatesX[item.counter] >= targetCoordinate.X && item.coordinatesX[item.counter] <= targetCoordinate.X + targetCoordinate.Width && item.coordinatesY[item.counter] >= targetCoordinate.Y && item.coordinatesY[item.counter] <= targetCoordinate.Y + targetCoordinate.Height) { item.crashed = true; item.hitTarget = true; return(true); } else { return(false); } }
private void CalculateFitness(RocketParameters variable) { //variable.fitness = 1 / (float)(Math.Sqrt((((targetCoordinate.X + targetCoordinate.Width / 2) - variable.coordinatesX[variable.counter]) * ((targetCoordinate.X + targetCoordinate.Width / 2) - variable.coordinatesX[variable.counter])) // + (((targetCoordinate.Y + targetCoordinate.Height/2) - variable.coordinatesY[variable.counter]) * ((targetCoordinate.Y + targetCoordinate.Height / 2) - variable.coordinatesY[variable.counter])))); variable.fitness = 1 / ((((targetCoordinate.X + targetCoordinate.Width / 2) - variable.coordinatesX[variable.counter]) * ((targetCoordinate.X + targetCoordinate.Width / 2) - variable.coordinatesX[variable.counter])) + (((targetCoordinate.Y + targetCoordinate.Height / 2) - variable.coordinatesY[variable.counter]) * ((targetCoordinate.Y + targetCoordinate.Height / 2) - variable.coordinatesY[variable.counter]))); }
private void MoveRockets(RocketParameters variable) { variable.ApplyForce(); for (int i = 0; i < variable.coordinatesX.Count; i++) { variable.coordinatesX[i] += (0.65F * ClientSize.Width) / 2; variable.coordinatesY[i] += (0.9F * ClientSize.Height) - 50; } }