当前位置: 首页>>代码示例>>C#>>正文


C# IGameState.GetRoadsLeft方法代码示例

本文整理汇总了C#中IGameState.GetRoadsLeft方法的典型用法代码示例。如果您正苦于以下问题:C# IGameState.GetRoadsLeft方法的具体用法?C# IGameState.GetRoadsLeft怎么用?C# IGameState.GetRoadsLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGameState的用法示例。


在下文中一共展示了IGameState.GetRoadsLeft方法的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;
                            }
                        }
                    }
                }
            }
        }
开发者ID:rasmusgreve,项目名称:catan,代码行数:85,代码来源:StarterAgent.cs


注:本文中的IGameState.GetRoadsLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。