Esempio n. 1
0
        public override Route NextClaim(Game current)
        {
            //focus on unmet destinations then any big route
            foreach (var destination in Destinations.Concat(new[] { DestinationCard.DestinationCardNull }))
            {
                IOrderedEnumerable <Route> routes;
                if (destination == DestinationCard.DestinationCardNull)
                {
                    routes = current.Board.AvailableRoutes().OrderByDescending(r => r.Tag.Length);
                }
                else
                {
                    if (current.Board.IsMet(destination, this))
                    {
                        continue;
                    }

                    routes = current.Board.ShortestRoute(destination, this)
                             .Where(r => r.Tag.Owner == null)
                             .OrderByDescending(r => r.Tag.Length);
                }

                if (!routes.Any())
                {
                    continue;
                }

                foreach (var route in routes)
                {
                    var resources = Tickets.Count(t => t.Color == Color.Any || t.Color == route.Tag.Color);
                    resources = resources < Trains ? resources : Trains;
                    if (route.Tag.Length <= resources)
                    {
                        return(route);
                    }
                }
            }

            //there are no available claims
            throw new ArgumentException("Stupid me, there was nothing I could claim!");
        }