Skip to content

Commit

Permalink
Merge pull request #5 from tommai78101/development
Browse files Browse the repository at this point in the history
Updating to v1.0.3
  • Loading branch information
tommai78101 authored Aug 3, 2023
2 parents 5c2d173 + b2b48b1 commit 2cc27f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions GeneticAlgorithmBot.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "..\\BizHawk\\src\\BizHawk.Client.EmuHawk"
}
]
}
Binary file added GeneticAlgorithmBot.sln.lnk
Binary file not shown.
28 changes: 20 additions & 8 deletions src/GeneticAlgorithmBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -636,11 +637,20 @@ private bool LoadBotFile(string path) {
try {
try {
// Attempts to load GeneticAlgorithmBot .BOT file save data.
botData = (BotData) ConfigService.LoadWithType(json);
var data = ConfigService.LoadWithType(json);
// Deserializing a serialized object works.
botData = JsonConvert.DeserializeObject<BotData>(JsonConvert.SerializeObject(data));
}
catch (InvalidCastException) {
// If exception is thrown, attempt to load BasicBot .BOT file save data instead.
botData = Utils.BotDataReflectionCopy(ConfigService.LoadWithType(json));
// Loading the data alternatively.
try {
// Deserializing a serialized object works.
botData = JsonConvert.DeserializeObject<BotData>(json);
}
catch (InvalidCastException) {
// If exception is thrown, attempt to load BasicBot .BOT file save data instead.
botData = Utils.BotDataReflectionCopy(ConfigService.LoadWithType(json));
}
}
}
catch (InvalidCastException e) {
Expand Down Expand Up @@ -713,9 +723,11 @@ private void LoadBotFileInner(BotData botData, string path) {
.OfType<BotControlsRow>()
.ToList();

foreach (var (button, p) in botData.ControlProbabilities) {
var control = probabilityControls.Single(c => c.ButtonName == button);
control.Probability = p;
if (botData.ControlProbabilities != null) {
foreach (var (button, p) in botData.ControlProbabilities) {
var control = probabilityControls.Single(c => c.ButtonName == button);
control.Probability = p;
}
}

MaximizeAddress = botData.Maximize;
Expand Down Expand Up @@ -1249,7 +1261,7 @@ public static BotAttempt BotAttemptReflectionCopy(object source) {
object value = p.GetValue(source);
PropertyInfo targetInfo = typeof(BotAttempt).GetProperty(p.Name);
if (value.GetType() == typeof(int)) {
targetInfo!.SetValue(target, Convert.ToUInt32(value));
targetInfo!.SetValue(target, Convert.ToInt32(value));
}
else if (p.Name.Equals("Log")) {
List<string> logs = (List<string>) targetInfo.GetValue(target);
Expand Down Expand Up @@ -1558,7 +1570,7 @@ public void DeepCopy(FrameInput other) {
public class BotAttempt {
public long Attempt { get; set; }
public long Generation { get; set; }
public int Fitness { get; set; }
public long Fitness { get; set; }
public int Maximize { get; set; }
public int TieBreak1 { get; set; }
public int TieBreak2 { get; set; }
Expand Down

0 comments on commit 2cc27f0

Please sign in to comment.