public void CaluculateScore(Creature creature) { Pod creaturepod = _pod.Clone(); for (int i = 0; i < GenomeSize / 3; i++) // move the pod x steps { double turnGen = creature.Genome[i * 3]; double trustGen = creature.Genome[i * 3 + 1]; double shieldGen = creature.Genome[i * 3 + 2]; Vector v = Vector.CreateVectorAngleSizeRad(creaturepod.AngleRad + (turnGen - 0.5) * Math.PI / 5.0, 1000); v += creaturepod.Position; int thrust = (int)(trustGen * 150) - 20; thrust = (thrust > 100) ? 100 : (thrust < 0) ? 0 : thrust; creaturepod.SetAction(v, thrust, false, false); creaturepod.Rotate(); creaturepod.Thrust(); // bounces here creaturepod.Move(); if ((_raceInfo.Checkpoints[creaturepod.NextCheckPointId].Position - creaturepod.Position).Size < 500) { creaturepod.NextCheckPointId = (creaturepod.NextCheckPointId + 1) % _raceInfo.CheckpointCount; } } // calculate the score of that position creature.Score = GetCurrentPositionScore(creaturepod); }
public void Optimize(Pod p, Checkpoint target, Checkpoint next_target) { int x = 0; double diff_score = 1; double time_to_next = 0; double scoreTurnUp, scoreTurnDown, scoreSpeedUp, scoreSpeedDown; double old_score = -1000; Pod clone; // Find direction of maximal improvement .. while (old_score < score) { old_score = score; while (x < 3) { scoreTurnUp = -1000; scoreTurnDown = -1000; scoreSpeedDown = -1000; scoreSpeedUp = -1000; if (moves[x].dAngle < 18) { clone = p.Clone(); moves[x].dAngle += 0.5; time_to_next = clone.simulate(this, target, next_target); scoreTurnUp = this.Evaluate(clone, target, next_target, time_to_next); if (scoreTurnUp > score) { score = scoreTurnUp; } else { moves[x].dAngle -= 0.5; if (moves[x].dAngle > -18) { clone = p.Clone(); moves[x].dAngle -= 0.5; time_to_next = clone.simulate(this, target, next_target); scoreTurnDown = this.Evaluate(clone, target, next_target, time_to_next); if (scoreTurnDown > score) { score = scoreTurnDown; } else { moves[x].dAngle += 0.5; } } } } if (moves[x].thrust < 100) { clone = p.Clone(); moves[x].thrust += 1; time_to_next = clone.simulate(this, target, next_target); scoreSpeedUp = this.Evaluate(clone, target, next_target, time_to_next); if (scoreSpeedUp > score) { score = scoreSpeedUp; } else { moves[x].thrust -= 1; if (moves[x].thrust > 0) { clone = p.Clone(); moves[x].thrust -= 1; time_to_next = clone.simulate(this, target, next_target); scoreSpeedDown = this.Evaluate(clone, target, next_target, time_to_next); if (scoreSpeedDown > score) { score = scoreSpeedDown; } else { moves[x].thrust += 1; } } } } x += 1; } } }