Esempio n. 1
0
        void ShowExtensionCards()
        {
            ExtensionsCardsPanel.Controls.Clear();
            ExtensionsCardsPanel.Controls.Add(ExtensionsCardsLabel);

            var differentCards = PresetGames.Get(Games.AllCards1stEdition).Where(c => !gameParams.Cards.Contains(c));
            var nec            = differentCards.ToList();

            int y = 5, x = 0;

            foreach (var card in differentCards.OrderBy(a => a.Name).OrderBy(a => a.Price))
            {
                var button = new Button()
                {
                    Text      = $"{card.Name} ${card.Price.ToString()}",
                    Location  = new Point(55 + x * dx, y += (x == 0 ? dy : 0)),
                    Tag       = card,
                    Anchor    = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                    ForeColor = Color.Black,
                    BackColor = card.ToBackColor(),
                    Width     = 138,
                    Height    = 25,
                    UseVisualStyleBackColor = false,
                    FlatStyle      = FlatStyle.Flat,
                    FlatAppearance = { BorderColor = Color.DarkGray }
                };

                x             = x == 0 ? 1 : 0;
                button.Click += AddToKingdom;
                ExtensionsCardsPanel.Controls.Add(button);
            }
        }
Esempio n. 2
0
        //static readonly char sep = Path.DirectorySeparatorChar;
        //static string directoryPath = $"..{sep}..{sep}..{sep}AI{sep}Provincial{sep}data{sep}kingdoms{sep}";
        //static string directoryPath = $"..{sep}..{sep}..{sep}AI{sep}";

        static void Main(string[] args)
        {
            string     directoryPath = BuyAgenda.DirectoryPath;
            List <int> numbers       = new List <int> {
                -1, 2, 4, 7, 10
            };

            foreach (var item in new Subsets(numbers, 2))
            {
                WriteLine(item.Aggregate("", (e, f) => e + " " + f.ToString()));
            }

            List <Card> cards = PresetGames.Get(Games.BigMoney);

            string first       = "Tens";
            var    firstAgenda = new SimpleManager(directoryPath, "Tens_").LoadBest(cards);

            User getFirst() => new ProvincialAI(firstAgenda, first);

            string second       = "Fives";
            var    secondAgenda = new CachedManager(directoryPath, 5, "Fives_").LoadBest(cards);

            User getSecond() => new ProvincialAI(secondAgenda, second);

            Game game    = new Game(new User[] { getFirst(), getSecond() }, cards.GetKingdom(2), new MyLogger());
            var  task    = game.Play();
            var  results = task.Result;

            ReadLine();
        }
Esempio n. 3
0
        public static GameParams Load()
        {
            var par = new GameParams();

            try
            {
                using (var reader = new StreamReader(path))
                {
                    Enum.TryParse(reader.ReadLine().Split('=')[1], out AIType aiType);
                    par.AIType    = aiType;
                    par.User1Name = reader.ReadLine().Split('=')[1];
                    par.User2Name = reader.ReadLine().Split('=')[1];

                    foreach (var card in reader.ReadLine().Split('=')[1].Split(','))
                    {
                        Enum.TryParse(card, out CardType cardType);
                        par.Cards.Add(Card.Get(cardType));
                    }
                }
            }
            catch (Exception)
            {
                par.AIType    = AIType.Tens;
                par.User1Name = "Human";
                par.User2Name = "Friend";
                par.Cards     = PresetGames.Get(Games.FirstGame);
            }

            return(par);
        }
Esempio n. 4
0
 public static List <Card> AddRequiredCards(this IEnumerable <Card> cards)
 {
     return(cards.Concat(PresetGames.VictoryAndTreasures())
            .Concat(cards.Select(c => c.RequiredCards).Where(c => c != null).Distinct()).ToList());
 }
Esempio n. 5
0
 void SetPresetGame(object sender, EventArgs e)
 {
     gameParams.Cards = PresetGames.Get((Games)int.Parse((sender as Button).Tag as string));
     ShowCurrentKingdomCards();
     ShowExtensionCards();
 }
Esempio n. 6
0
        // params
        // -f -s 5 -t 4

        static void Main(string[] args)
        {
            // params
            EvolutionType et = EvolutionType.Tens;
            int           startIndex = 0, count = 1, parallelDegreeExt = -1, parallelDegreeInt = -1;

            var rnd = new ThreadSafeRandom();
            //char sep = Path.DirectorySeparatorChar;
            //string directoryPath = $"..{sep}..{sep}..{sep}AI{sep}Provincial{sep}data{sep}kingdoms{sep}";
            //string directoryPath = $"..{sep}..{sep}..{sep}AI{sep}";
            string directoryPath = BuyAgenda.DirectoryPath;

            string           subsetFile = null;
            BuyAgendaManager manager    = new SimpleManager(directoryPath, "Tens_");

            IEnumerator <string> kingdoms = null;

            // params handling
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] != '-')
                {
                    continue;
                }
                for (int j = 1; j < args[i].Length; j++)
                {
                    try
                    {
                        switch (args[i][j])
                        {
                        case 'c':
                            count = int.Parse(args[++i]);
                            break;

                        case 'd':
                            et      = EvolutionType.Tens;
                            manager = new SimpleManager(directoryPath, "Tens_");
                            break;

                        case 'f':
                            et = EvolutionType.Subsets;
                            //manager = new CachedManager(directoryPath, 5, "Fives_");
                            manager    = new SimpleManager(directoryPath, "Fives_");
                            subsetFile = "fives";
                            break;

                        case 'h':
                            et = EvolutionType.Subsets;
                            //manager = new CachedManager(directoryPath, 3, "Threes_");
                            manager    = new SimpleManager(directoryPath, "Threes43_");  // TODO 43
                            subsetFile = "threes";
                            break;

                        case 'n':
                            et = EvolutionType.NamedGames;
                            break;

                        case 's':
                            startIndex = int.Parse(args[++i]);
                            break;

                        case 't':
                            parallelDegreeExt = 1;
                            parallelDegreeInt = int.Parse(args[++i]);
                            break;

                        default:
                            break;
                        }
                    }
                    catch
                    {
                        WriteLine($"Parameter {i} failed.");
                    }
                }
            }

            WriteLine($"evolution: {et.ToString()}");

            if (et == EvolutionType.Subsets)
            {
                kingdoms = File.ReadAllLines($"{directoryPath}{BuyAgenda.sep}{subsetFile}.txt").Skip(startIndex).Take(count).GetEnumerator();
                WriteLine($"count: {count}");
                WriteLine($"start index: {startIndex}");
            }

            else
            {
                WriteLine($"kingdom: random");
            }

            for (int i = 0; i < count; i++)
            {
                //    try
                {
                    switch (et)
                    {
                    case EvolutionType.Tens:
                    {
                        //cards = PresetGames.Get(Games.FirstGame).AddRequiredCards();
                        List <Card> cards = null;

                        // get random 10 cards
                        cards = Enumerable.Range((int)CardType.Adventurer, 25)
                                .Select(t => ((t, r: rnd.NextDouble())))
                                .OrderBy(a => a.r)
                                .Take(10)
                                .Select(((int type, double)a) => Card.Get((CardType)a.type))
                                .ToList();

                        var kingdomName = cards.OrderBy(p => p.Type).Select(p => (int)p.Type).Aggregate("kingdom", (a, b) => a + " " + b);
                        WriteLine($"kingdom {i}: {kingdomName}");
                        if (manager.Load(cards) != null)
                        {
                            WriteLine($"Skipping kingdom.");
                            continue;
                        }

                        var evolution = new Evolution(new Params
                            {
                                Kingdom           = cards,
                                Evaluator         = new ProvincialEvaluator(),
                                ParallelDegreeExt = parallelDegreeExt,
                                ParallelDegreeInt = parallelDegreeInt,
                                LeaderCount       = 10,
                                PoolCount         = 50,
                                Generations       = 50,
                            }, new Logger());
                        var agenda = evolution.Run();
                        manager.Save(cards, agenda);
                    }
                    break;

                    case EvolutionType.Subsets:
                    {
                        List <Card> cards = null;
                        kingdoms.MoveNext();

                        cards = kingdoms.Current.Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(a => Card.Get((CardType)int.Parse(a))).ToList();

                        var kingdomName = cards.OrderBy(p => p.Type).Select(p => (int)p.Type).Aggregate("kingdom", (a, b) => a + " " + b);
                        WriteLine($"kingdom {i}: {kingdomName}");

                        if (manager.Load(cards) != null)
                        {
                            WriteLine("skipping");
                            continue;
                        }

                        var evolution = new Evolution(new Params
                            {
                                Kingdom           = cards,
                                Evaluator         = new ProvincialEvaluator(),
                                ParallelDegreeExt = parallelDegreeExt,
                                ParallelDegreeInt = parallelDegreeInt,
                                LeaderCount       = 10,
                                PoolCount         = 50,
                                Generations       = 50,
                            }, new Logger());
                        var agenda = evolution.Run();
                        manager.Save(cards, agenda);
                    }
                    break;

                    case EvolutionType.NamedGames:
                    {
                        //cards = PresetGames.Get(Games.FirstGame).AddRequiredCards();
                        List <(List <Card> Cards, string Name)> games = new List <(List <Card>, string)>
                        {
                            (PresetGames.Get(Games.BigMoney), "bigMoneyGame"),
                            (PresetGames.Get(Games.Interaction), "interaction"),
                            (PresetGames.Get(Games.FirstGame), "firstGame"),
                            (PresetGames.Get(Games.SizeDistortion), "sizeDistortion"),
                            (PresetGames.Get(Games.ThrashHeap), "trasheap"),
                            (PresetGames.Get(Games.VillageSquare), "village"),
                            //((new int[]{ 9, 12, 15, 18, 22, 24, 27, 28, 31, 32}.Select(c => Card.Get((CardType)c)).ToList()), "badCards")
                            //(new List<Card>{Card.Get(CardType.Curse)}, "bigMoney")
                        };

                        games.ForEach(item =>
                            {
                                var kingdomName = item.Cards.OrderBy(p => p.Type).Select(p => (int)p.Type).Aggregate("kingdom", (a, b) => a + " " + b);
                                WriteLine($"kingdom {i}: {item.Name} {kingdomName}");
                                var evolution = new Evolution(new Params
                                {
                                    Kingdom     = item.Cards,
                                    Evaluator   = new ProvincialEvaluator(),
                                    LeaderCount = 10,
                                    PoolCount   = 50,
                                    Generations = 50,
                                }, new Logger());     //manager.First(a => a.Id == item.Name));
                                var agenda = evolution.Run();
                                manager.Save(item.Cards, agenda);
                            });
                    }
                    break;

                    default:
                        break;
                    }
                }
                //catch (Exception e)
                //{
                //    WriteLine(e.Message);
                //}
            }
            ReadLine();
        }