超模计算方式修改&自适应合理工作

This commit is contained in:
ZouJin
2024-03-14 14:15:08 +08:00
parent b61b4996f2
commit 6a1c848d6d
2 changed files with 89 additions and 38 deletions

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -14,10 +15,6 @@ namespace VPet_Simulator.Windows.Interface
{
public static class ExtensionFunction
{
/// <summary>
/// 工作计算等级
/// </summary>
public static readonly int[] WorkCalLevel = new int[] { 1, 5, 10, 20, 30, 40, 50, 75, 100, 200 };
/// <summary>
/// 工作获取效率
/// </summary>
@ -25,25 +22,24 @@ namespace VPet_Simulator.Windows.Interface
/// <returns>工作获取效率</returns>
public static double Get(this Work work)
{
double get = 0;
foreach (var lv in WorkCalLevel)
{
get += (work.MoneyBase + Math.Sqrt(lv)) * (1 + work.FinishBonus / 2);
}
get /= WorkCalLevel.Length;
if (work.Type != Work.WorkType.Work)
{
get /= 12;//经验值换算
}
return get;
return MathPow(Math.Abs(work.MoneyBase) * (1 + work.FinishBonus / 2) + 1, 1.25);
}
/// <summary>
/// 求幂(带符号)
/// </summary>
public static double MathPow(double value, double pow)
{
return Math.Pow(Math.Abs(value), pow) * Math.Sign(value);
}
/// <summary>
/// 工作花费效率
/// </summary>
/// <param name="work">工作</param>
/// <returns>工作花费效率</returns>
public static double Spend(this Work work)
{
var spend = ((work.StrengthFood >= 0 ? 1 : -1) * Math.Pow(work.StrengthFood * 2 + 1, 2) / 6 +
(work.StrengthDrink >= 0 ? 1 : -1) * Math.Pow(work.StrengthDrink * 2 + 1, 2) / 9 +
(work.Feeling >= 0 ? 1 : -1) * Math.Pow((work.Type == Work.WorkType.Play ? -1 : 1) * work.Feeling * 2 + 1, 2) / 12) *
(Math.Pow(work.LevelLimit / 2 + 1, 0.5) / 4 + 1) - 0.5;
return spend;
return (MathPow(work.StrengthFood, 1.5) / 3 + MathPow(work.StrengthDrink, 1.5) / 4 + MathPow(work.Feeling, 1.5) / 4 +
work.LevelLimit / 10 + MathPow(work.StrengthFood + work.StrengthDrink + work.Feeling, 1.5) / 10) * 3;
}
/// <summary>
/// 判断这个工作是否超模
@ -54,6 +50,8 @@ namespace VPet_Simulator.Windows.Interface
{//判断这个工作是否超模
if (work.LevelLimit > 100)
return true;
if (work.LevelLimit < 0)
work.LevelLimit = 0;
if (work.FinishBonus < 0)
return true;
var spend = work.Spend();
@ -61,9 +59,76 @@ namespace VPet_Simulator.Windows.Interface
var rel = get / spend;
if (rel < 0)
return true;
if (Math.Abs(get) > (work.LevelLimit + 4) * 3) //等级获取速率限制
if (Math.Abs(get) > 1.1 * work.LevelLimit + 10) //等级获取速率限制
return true;
return rel > 0.75; // 推荐rel为0.5左右 超过0.75就是超模
return rel < 1.3; // 推荐rel为1左右 超过1.3就是超模
}
/// <summary>
/// 数值梯度下降法 修复超模工作
/// </summary>
/// <param name="work"></param>
public static void FixOverLoad(this Work work)
{
// 设置梯度下降的步长和最大迭代次数
double stepSize = 0.01;
int maxIterations = 1000;
for (int i = 0; i < maxIterations; i++)
{
if (work.LevelLimit > 100)
work.LevelLimit = 100;
if (work.FinishBonus < 0)
work.FinishBonus = 0;
while (Math.Abs(work.Get()) > 1.1 * work.LevelLimit + 10) //等级获取速率限制
{
work.MoneyBase /= 2;
}
// 判断是否已经合理
if (!work.IsOverLoad())
{
return;
}
// 计算当前的Spend和Get
double currentSpend = work.Spend();
double currentGet = work.Get();
// 为每个参数增加一个小的delta值然后重新计算Spend和Get
double delta = 0.0001;
work.MoneyBase += delta;
double getGradient = (work.Get() - currentGet) / delta;
work.MoneyBase -= delta; // 还原MoneyBase的值
work.StrengthFood += delta;
work.StrengthDrink += delta;
work.Feeling += delta;
double spendGradient = (work.Spend() - currentSpend) / delta;
// 还原所有的值
work.StrengthFood -= delta;
work.StrengthDrink -= delta;
work.Feeling -= delta;
// 根据梯度更新属性值
work.MoneyBase += stepSize * getGradient;
work.StrengthFood -= stepSize * spendGradient;
work.StrengthDrink -= stepSize * spendGradient;
work.Feeling -= stepSize * spendGradient;
}
// 如果仍然不合理,设定一个默认值
if (work.IsOverLoad())
{//TODO
work.MoneyBase = 10;
work.StrengthFood = 5;
work.StrengthDrink = 5;
work.Feeling = 5;
work.LevelLimit = 10;
}
}
public static string FoodToDescription(this IFood food)

View File

@ -276,7 +276,7 @@ namespace VPet_Simulator.Windows
}
}
//private DateTime timecount = DateTime.Now;
/// <summary>
@ -1564,21 +1564,7 @@ namespace VPet_Simulator.Windows
{
if (work.IsOverLoad())
{
work.MoneyBase = 8;
if (work.Type == Work.WorkType.Work)
{
work.StrengthDrink = 2.5;
work.StrengthFood = 3.5;
work.Feeling = 1.5;
work.FinishBonus = 0;
}
else
{
work.Feeling = 1;
work.FinishBonus = 0;
work.StrengthDrink = 1;
work.StrengthFood = 1;
}
work.FixOverLoad();
}
}
}