AI资源分计算

This commit is contained in:
daixiawu 2025-06-23 22:30:13 +08:00
parent 181e7c1696
commit aaad6994a6

View File

@ -11,7 +11,9 @@ using System.Collections.Generic;
using System.Linq;
using Logic.Action;
using RuntimeData;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using Vector2 = System.Numerics.Vector2;
@ -325,7 +327,55 @@ namespace Logic.AI
// 计算科技对国家的资源分
public int CalCountryTechResourceScore(TechType techType)
{
return 0;
HashSet<CityData> cityList = Map.GetCityDataSetByPlayerId(Player.Id);
int score = 0;
foreach(var city in cityList)
{
HashSet<uint> gridList = new HashSet<uint>();
city.Territory.GetAllTerritoryArea(gridList);
foreach(var gid in gridList)
{
if (!Map.GridMap.GetGridDataByGid(gid, out var grid)) continue;
//计算每一种techActions在grid下的资源分
score += CalcGridTechResourceScore(techType, grid);
}
}
return score;
}
// 计算科技对一个格子的资源分。该函数主要用于计算科技对于一个国家的资源分
public int CalcGridTechResourceScore(TechType techType, GridData gridData)
{
int score = 0;
var techInfo = Table.Instance.TechDataAssets.GetTechInfo(techType);
foreach (var t in techInfo.techActions)
{
if (t.ActionType == CommonActionType.Gain)
{
if (!Table.Instance.GridAndResourceDataAssets.GetResourceInfo(t.ResourceType, out var resourceInfo))
continue;
score += resourceInfo.Exp;
}
if (t.ActionType == CommonActionType.Build)
{
if (!Table.Instance.GridAndResourceDataAssets.GetResourceInfo(t.ResourceType, out var resourceInfo))
continue;
score += t.ResourceType switch
{
ResourceType.LumberHut => gridData.Vegetation == Vegetation.Trees ? 1 : 0,
ResourceType.Farm => gridData.Resource == ResourceType.Crop ? 2 : 0,
ResourceType.Mine => gridData.Resource == ResourceType.Metal ? 2 : 0,
ResourceType.Sawmill => gridData.Vegetation == Vegetation.Trees ? 1 : 0,
ResourceType.Windmill => gridData.Resource == ResourceType.Crop || gridData.Resource == ResourceType.Farm ? 1 : 0,
ResourceType.Forge => gridData.Resource == ResourceType.Metal || gridData.Resource == ResourceType.Mine ? 2 : 0,
ResourceType.Port => gridData.Terrain == TerrainType.ShallowSea ? 1 : 0,
_ => 0
};
}
}
return score;
}
// 科技克制分计算