Merge branch 'main' of http://10.27.16.144:3000/kawagiri/TH1 into main
This commit is contained in:
commit
b5d946fcd0
@ -228,7 +228,7 @@ namespace Logic.AI
|
||||
}
|
||||
|
||||
// 克制关系分数计算
|
||||
private float GetRestraintScore(UnitData self, UnitData target)
|
||||
public float GetRestraintScore(UnitData self, UnitData target)
|
||||
{
|
||||
var score = 6f;
|
||||
if (target.GetMoveRange() >= 2 && self.GetAttackRange() < 2) score--;
|
||||
@ -238,7 +238,9 @@ namespace Logic.AI
|
||||
if (target.UnitType == UnitType.Defender && self.UnitType != UnitType.Minder) score--;
|
||||
return score / 6f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 城市评分, 我方城市相对其他所有城市的差值
|
||||
private void CalculateCityScore(MapData mapData, PlayerData playerData, CalculateResult result)
|
||||
{
|
||||
|
||||
@ -33,6 +33,8 @@ namespace Logic.AI
|
||||
public float UnitExploreStarfishScore;
|
||||
|
||||
public float FutureScoreTransformValue;
|
||||
|
||||
public float MilitaryConstructionRatioValue;
|
||||
|
||||
public List<AICalculatorTechInfo> TechInfoList = new List<AICalculatorTechInfo>();
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
|
||||
using Logic.Action;
|
||||
using RuntimeData;
|
||||
|
||||
|
||||
@ -13,33 +14,134 @@ namespace Logic.AI
|
||||
{
|
||||
public class AITechScoreCalculator
|
||||
{
|
||||
public static float CalculateTechScore(MapData map, PlayerData player, TechType tech)
|
||||
//tech专用的unit兵种克制计算函数
|
||||
private float GetRestraintScoreForTech(UnitType selfType,GiantType giantType, UnitData target)
|
||||
{
|
||||
if (tech == TechType.Climbing)
|
||||
{
|
||||
var count = 0;
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
{
|
||||
if (!map.GridMap.GetGridDataByGid(gridId, out var gridData)) continue;
|
||||
if (gridData.Feature != TerrainFeature.Mountain) continue;
|
||||
count++;
|
||||
}
|
||||
Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(selfType, giantType, out var self);
|
||||
var score = 6f;
|
||||
if (target.GetMoveRange() >= 2 && self.AttackRange < 2) score--;
|
||||
if (target.GetAttackRange() >= 2 && self.AttackRange < 2) score--;
|
||||
if (target.GetAttackRange() < 2 && self.MoveRange >= 2) score--;
|
||||
if (target.UnitType == UnitType.Minder && self.UnitType == UnitType.Defender) score--;
|
||||
if (target.UnitType == UnitType.Defender && self.UnitType != UnitType.Minder) score--;
|
||||
return score / 6f;
|
||||
}
|
||||
|
||||
//获得当前生产一个unitType的军事得分
|
||||
private float GetUnitTypeMilitaryScoreForTech(MapData map,UnitType type, PlayerData player,AIConfigAsset cfg)
|
||||
{
|
||||
var military = 0f;
|
||||
foreach (var unit in map.UnitMap.UnitList)
|
||||
if(map.GetPlayerDataByUnitId(unit.Id,out var tmpPlayer)
|
||||
&& tmpPlayer.Id != player.Id)
|
||||
military += GetRestraintScoreForTech(type,GiantType.None, unit);
|
||||
return military * cfg.MilitaryConstructionRatioValue;
|
||||
}
|
||||
|
||||
//获得当前建设某种资源的建设得分
|
||||
private float GetResourceTypeConstructScoreForTech(MapData map,ResourceType type, PlayerData player,AIConfigAsset cfg)
|
||||
{
|
||||
var count = 0f;
|
||||
if (type == ResourceType.None)
|
||||
return count;
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
{
|
||||
if (!map.GridMap.GetGridDataByGid(gridId, out var gridData)) continue;
|
||||
if (gridData.Resource == type)
|
||||
{
|
||||
if (Table.Instance.GridAndResourceDataAssets.GetResourceInfo(type, out var resourceInfo))
|
||||
count += resourceInfo.Exp;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public float CalculateTechScore(MapData map, PlayerData player, TechType tech, AIConfigAsset cfg)
|
||||
{
|
||||
var techInfo = Table.Instance.TechDataAssets.GetTechInfo(tech);
|
||||
//建设得分
|
||||
var construct = 0f;
|
||||
//奇观得分
|
||||
var wonder = 0f;
|
||||
//军事得分
|
||||
var military = 0f;
|
||||
//其他得分
|
||||
var other = 0f;
|
||||
|
||||
foreach(var action in techInfo.techActions)
|
||||
{
|
||||
//常规单位 计算军事得分
|
||||
if (action.ActionType == CommonActionType.TrainUnit)
|
||||
military += GetUnitTypeMilitaryScoreForTech(map,action.UnitType,player,cfg);
|
||||
//常规建筑 计算经验得分
|
||||
if (action.ActionType == CommonActionType.Gain)
|
||||
construct += GetResourceTypeConstructScoreForTech(map,action.ResourceType,player,cfg);
|
||||
if (action.ActionType == CommonActionType.Build)
|
||||
{
|
||||
ResourceType t = ResourceType.None;
|
||||
if(action.ResourceType == ResourceType.Farm) t = ResourceType.Crop;
|
||||
if(action.ResourceType == ResourceType.Mine) t = ResourceType.Metal;
|
||||
if(action.ResourceType == ResourceType.Forge) t = ResourceType.Mine;
|
||||
if(action.ResourceType == ResourceType.Sawmill) t = ResourceType.LumberHut;
|
||||
if(action.ResourceType == ResourceType.Windmill) t = ResourceType.Farm;
|
||||
construct += GetResourceTypeConstructScoreForTech(map,t,player,cfg);
|
||||
|
||||
//lumberhut要单独处理
|
||||
if (action.ResourceType == ResourceType.LumberHut || action.ResourceType == ResourceType.ForestTemple)
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
if (map.GridMap.GetGridDataByGid(gridId, out var gridData)
|
||||
&& gridData.Vegetation == Vegetation.Trees) construct += 1;
|
||||
//market要单独处理
|
||||
if (action.ResourceType == ResourceType.Market)
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
if (map.GridMap.GetGridDataByGid(gridId, out var gridData)
|
||||
&& (gridData.Resource == ResourceType.Forge
|
||||
|| gridData.Resource == ResourceType.Windmill
|
||||
|| gridData.Resource == ResourceType.Sawmill))
|
||||
construct += gridData.buildingLevel;
|
||||
//port要单独处理
|
||||
if (action.ResourceType == ResourceType.Port)
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
if (map.GridMap.GetGridDataByGid(gridId, out var gridData)
|
||||
&& gridData.Terrain == TerrainType.ShallowSea)
|
||||
construct += 1;
|
||||
//mountaintemple temple watertemple 要单独处理
|
||||
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
{
|
||||
if (!map.GridMap.GetGridDataByGid(gridId, out var gridData)) continue;
|
||||
if (action.ResourceType == ResourceType.Temple
|
||||
&& gridData.Terrain == TerrainType.Land
|
||||
&& gridData.Feature != TerrainFeature.Mountain
|
||||
&& gridData.Vegetation != Vegetation.Trees
|
||||
&& gridData.Resource == ResourceType.None)
|
||||
construct += 1;
|
||||
if (action.ResourceType == ResourceType.MountainTemple
|
||||
&& gridData.Resource == ResourceType.None
|
||||
&& gridData.Feature == TerrainFeature.Mountain)
|
||||
construct += 1;
|
||||
if (action.ResourceType == ResourceType.WaterTemple
|
||||
&& gridData.Resource == ResourceType.None
|
||||
&& gridData.Terrain != TerrainType.Land)
|
||||
construct += 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//奇观得分
|
||||
if (action.ActionType == CommonActionType.StartWonder)
|
||||
{
|
||||
wonder += 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (tech == TechType.Fishing)
|
||||
{
|
||||
var count = 0;
|
||||
foreach (var gridId in player.Sight.SightGidSet)
|
||||
{
|
||||
if (!map.GridMap.GetGridDataByGid(gridId, out var gridData)) continue;
|
||||
if (gridData.Terrain != TerrainType.ShallowSea) continue;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
//其他单独处理
|
||||
if (tech == TechType.Philosophy)
|
||||
other += 26 - player.TechTree.TechList.Count;
|
||||
if (tech == TechType.Roads)
|
||||
other += map.GetCityCount(player.Id) * 2;
|
||||
|
||||
if (tech == TechType.Sailing)
|
||||
{
|
||||
@ -51,10 +153,10 @@ namespace Logic.AI
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
other += count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return construct + military + wonder + other;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user