本文整理汇总了C#中IGameState.GetSettlementsLeft方法的典型用法代码示例。如果您正苦于以下问题:C# IGameState.GetSettlementsLeft方法的具体用法?C# IGameState.GetSettlementsLeft怎么用?C# IGameState.GetSettlementsLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameState
的用法示例。
在下文中一共展示了IGameState.GetSettlementsLeft方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformTurn
public void PerformTurn(IGameState state, IGameActions actions)
{
if (!silent)
Console.WriteLine(id + ": Performing main turn");
for (bool changed = true; changed; )
{
changed = false;
var resources = state.GetOwnResources();
//Build city
if (state.GetCitiesLeft(id) > 0 && resources.Count(r => r == Resource.Grain) >= 2 && resources.Count(r => r == Resource.Ore) >= 3)
{
var pos = state.Board.GetPossibleCities(id);
if (pos.Length > 0)
{
changed = true;
state = actions.BuildCity(FindBestIntersection(pos,state.Board));
}
}
//Build settlement
if (!changed && state.GetSettlementsLeft(id) > 0 && resources.Contains(Resource.Grain) && resources.Contains(Resource.Wool) && resources.Contains(Resource.Lumber) && resources.Contains(Resource.Brick))
{
var pos = state.Board.GetPossibleSettlements(id);
if (pos.Length > 0)
{
changed = true;
state = actions.BuildSettlement(FindBestIntersection(pos,state.Board));
}
}
//Build road
if (!changed && state.GetRoadsLeft(id) > 0 && resources.Contains(Resource.Lumber) && resources.Contains(Resource.Brick))
{
var pos = state.Board.GetPossibleRoads(id);
if (pos.Length > 0)
{
changed = true;
state = actions.BuildRoad(FindBestRoad(pos, state.Board));
}
}
//Trade players
if (!changed && Enum.GetValues(typeof(Resource)).Cast<Resource>().Any(r => resources.Count(res => res == r) > 2))
{
// trade 1 of most for 1 missing
List<List<Resource>> give = resources.OrderByDescending(r => resources.Count(res => res == r))
.GroupBy(r => resources.Count(res => res == r)).First().Distinct()
.Select(r => { var list = new List<Resource>(); list.Add(r); return list; }).ToList();
List<List<Resource>> take = Enum.GetValues(typeof(Resource)).Cast<Resource>()
.OrderBy(r => resources.Count(res => res == r))
.GroupBy(r => resources.Count(res => res == r)).First()
.Select(r => { var list = new List<Resource>(); list.Add(r); return list; }).ToList();
if (give.Count > 0 && take.Count > 0)
{
Dictionary<int,ITrade> answers = actions.ProposeTrade(give, take);
if (answers.Count > 0)
{
// trade with lowest score
int otherPlayer = answers.OrderBy(kv => state.GetPlayerScore(kv.Key)).First().Key;
state = actions.Trade(otherPlayer);
changed = true;
}
}
}
//Trade bank
foreach (Resource give in Enum.GetValues(typeof(Resource)))
{
if (changed) break;
if (resources.Count(r => r == give) > 4)
{
foreach (Resource take in Enum.GetValues(typeof(Resource)))
{
if (changed) break;
if (resources.Count(r => r == take) == 0 && state.ResourceBank[(int)take] > 0)
{
state = actions.TradeBank(give, take);
changed = true;
}
}
}
}
}
}