private double FitnessFunction(ICreature creature) { var nn = creature.GetChromosome <INeuralChromosome>("nn"); _environment.Reset(); var i = 0; var j = 0; var prev_action = -1; while (i < MAX_ACTIONS && !_environment.Done) { var percepts = _environment.GetPercepts(); var output = nn.Evaluate(percepts); var action = (uint)Array.IndexOf(output, output.Max()); if (action == prev_action) { j++; } if (j > 5) { break; } prev_action = (int)action; _environment.TakeAction(action); i++; } /*var bonus = !_environment.GoldFound ? -100 : 60 - (10 * * (Math.Abs(_environment.Position.Item1 - _environment.StartPosition.Item1) + * Math.Abs(_environment.Position.Item2 - _environment.StartPosition.Item2)));*/ var bonus = 0; if (!_environment.WumpusAlive) { bonus += 10; } if (_environment.GoldFound) { bonus += 150; } //return _environment.Reward + i + bonus; return(_environment.Reward + bonus); }
public void Navigate(WumpusWorld environment) { environment.Reset(); var i = 0; while (i < MAX_ACTIONS && !environment.Done) { var percepts = environment.GetPercepts(); var output = _network.Evaluate(percepts); var action = (uint)Array.IndexOf(output, output.Max()); System.Diagnostics.Debug.WriteLine($"Action Count: {i}"); System.Diagnostics.Debug.WriteLine($"Percepts: {environment.GetPerceptsText()}"); System.Diagnostics.Debug.WriteLine($"Action: {WumpusWorld.ACTION_MAP[action]}"); environment.Render(); environment.TakeAction(action); i++; Thread.Sleep(TIMEOUT); } }