mod|通过强化学习和官方API制作《星露谷物语》的自动钓鱼mod( 三 )


public int Update(double[
currentState)
{

   Tensor<double> input = new DenseTensor<double>(new[
{3);

   input[0
= currentState[0
;
   input[1
= currentState[1
;
   input[2
= currentState[2
;

   // Setup inputs and outputs
   var inputs = new List<NamedOnnxValue>()
   {
       // the model has only one input the state tuple
       NamedOnnxValue.CreateFromTensor<double>(\"0\" input)
   ;

   using (var results = session.Run(inputs))
   {

       Tensor<double> outputs = results.First().AsTensor<double>();
       var maxValue = https://mparticle.uc.cn/api/outputs.Max();
       var maxIndex = outputs.ToList().IndexOf(maxValue);
       
       return maxIndex;
   

使用 Harmony 进行输入SMAPI 缺少的API是能够在游戏中提供输入 , 因为 99.999% 的mod不需要这样的东西 。为了进行输入我找到了一个名为 Harmony 的 C# 库在可以在运行时更改游戏的内部函数 , 这样我就可以让游戏以为它收到了鼠标输入 。这就是上面让mode自己玩游戏的方法 。非常感谢 Drynwynn , Mod FishingAutomaton 的作者 , 我使用了很多代码来设置我的 mod 。
[HarmonyPatch(typeof(Game1) \"isOneOfTheseKeysDown\")

class IsButtonDownHack
{
   // ...
   // some important stuff
   // ...
   
   // change function return value to true
   // makes the game think a mouse left button click ocurred
   __result = true;
   return;

最终结果目前 , 该模型可以捕获所有“简单”和“中级”的鱼 。还不能训练它捕捉传说中的鱼 。
这个gif是未训练完成的演示

下面是我们训练的结果 , 效果还不错

资源和引用非常感谢 Stardew Valley 的mod社区帮助并让我更好地理解游戏:)
C# mod 和 Python 训练的所有代码都可以在这里找到!
github/ThiagoLira/AutoFisher-SV
https://www.overfit.cn/post/8f82fe918b644ce58a8e525243db87a4
作者:Thiago Lira