Exemplo n.º 1
0
        private void UpdateLog()
        {
            String log = DLLInterface.GetString("log") + " ";

            if (log.StartsWith("New Game"))
            {
                textBoxLog.Clear();
            }
            else
            {
                log = "\n" + log;
            }

            int textBoxStart = textBoxLog.Text.Length;

            textBoxLog.AppendText(log);

            foreach (SupplyEntry s in supply)
            {
                String paddedName = " " + s.c.PrettyName() + " ";
                foreach (var instance in log.AllIndexesOf(paddedName))
                {
                    textBoxLog.SelectionStart     = textBoxStart + instance;
                    textBoxLog.SelectionLength    = paddedName.Length;
                    textBoxLog.SelectionBackColor = s.c.BackColor();
                }
            }

            textBoxLog.SelectionStart     = textBoxLog.Text.Length - 1;
            textBoxLog.SelectionLength    = 1;
            textBoxLog.SelectionBackColor = Color.White;
            textBoxLog.ScrollToCaret();
        }
Exemplo n.º 2
0
 private void UpdateBasicState()
 {
     String[] parts = DLLInterface.GetString("basicState").Split('|');
     labelPhase.Text   = parts[1] + "'s " + Utility.PhaseName(Convert.ToInt32(parts[2])) + " Phase";
     labelActions.Text = "Actions: " + parts[3];
     labelBuys.Text    = "Buys: " + parts[4];
     labelMoney.Text   = "$ " + parts[5];
 }
Exemplo n.º 3
0
 public void LoadCardList(String command, ListBox box)
 {
     box.Items.Clear();
     String[] cards = DLLInterface.GetString(command + " " + comboBoxPlayerList.SelectedIndex.ToString()).Split('|');
     foreach (String s in cards)
     {
         box.Items.Add(s);
     }
 }
Exemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            DLLInterface.Init();

            NewGame("");

            InitConfigWindow();

            NewKingdomCardsPressed();
        }
Exemplo n.º 5
0
        private void UpdateSupplyState()
        {
            String[]      parts        = DLLInterface.GetString("supplyState").Split('@');
            List <String> supplyCounts = new List <String>(parts[0].Split('|'));
            List <String> supplyCosts  = new List <String>(parts[1].Split('|'));

            foreach (SupplyEntry s in supply)
            {
                s.countLabel.Text = "$" + supplyCosts[s.index] + " (" + supplyCounts[s.index] + ")";
            }
        }
Exemplo n.º 6
0
        public void NewKingdomCards(string gameOptions)
        {
            DLLInterface.ProcessCommand("newKingdomCards@" + gameOptions);
            InitializeSupply();
            UpdateAllState();

            if (configWindow != null)
            {
                configWindow.UpdateBuildLists();
            }
        }
Exemplo n.º 7
0
 public void NewGame(string parameters)
 {
     if (parameters.Length == 0)
     {
         DLLInterface.ProcessCommand("newGame");
     }
     else
     {
         DLLInterface.ProcessCommand("newGame@" + parameters);
     }
     InitializeSupply();
     UpdateAllState();
 }
Exemplo n.º 8
0
        public void UpdateState(bool updatePlayerList = true)
        {
            if (updatePlayerList)
            {
                UpdatePlayerList();
            }

            LoadCardList("deck", listBoxDeck);
            LoadCardList("discard", listBoxDiscard);
            LoadCardList("playArea", listBoxPlayArea);
            LoadCardList("hand", listBoxHand);

            labelTotalVP.Text = "Total VP: " + Convert.ToInt32(DLLInterface.GetString("victoryPoints " + comboBoxPlayerList.SelectedIndex.ToString()));
        }
Exemplo n.º 9
0
        private void UpdatePlayerList()
        {
            comboBoxPlayerList.Items.Clear();
            String[] playerInfo = DLLInterface.GetString("playerList").Split('|');
            if (playerInfo.Length <= 1)
            {
                return;
            }
            foreach (String s in playerInfo)
            {
                String[] parts = s.Split('@');
                comboBoxPlayerList.Items.Add(parts[0] + " -- " + parts[1]);
            }

            int activePlayer = Convert.ToInt32(DLLInterface.GetString("basicState").Split('|')[0]);

            comboBoxPlayerList.SelectedIndex = activePlayer;
        }
Exemplo n.º 10
0
        private void buttonCompareAIs_Click(object sender, EventArgs e)
        {
            String parameters = AIString();

            if (parameters.Contains("Human"))
            {
                MessageBox.Show("Humans are not valid test subjects.", "Error");
                return;
            }

            DLLInterface.ProcessCommand("testAIs@" + parameters);
            parentWindow.InitializeSupply();
            parentWindow.UpdateAllState();

            labelSampleGameInfo.Visible = true;
            labelSampleGameInfo.Text    = "The main window contains a sample game between the two AIs.";

            double result = DLLInterface.GetDouble("AITestResult");

            labelResult.Text = "Player 1 wins " + result.ToString("P").Replace(" %", "%") + " of games for a spread of " + DominionVisualization.FormatPercentage((result * 100.0 - 50.0) * 2.0) + ".";
        }
Exemplo n.º 11
0
 private void buttonAddCard_Click(object sender, EventArgs e)
 {
     DLLInterface.ProcessCommand("debugAddCard@" + textBoxAddCard.Text.ToLower());
     UpdateState(false);
 }
Exemplo n.º 12
0
        public void InitializeSupply()
        {
            List <String> supplyCards = new List <String>(DLLInterface.GetString("supplyCards").Split('|'));

            panelSupply.Controls.Clear();

            supply = new List <SupplyEntry>();

            int supplyX = 0, supplyY = 0;

            foreach (String s in supplyCards)
            {
                SupplyEntry newEntry = new SupplyEntry();
                newEntry.index = supply.Count;
                supply.Add(newEntry);

                int baseX = supplyX * 60;
                int baseY = supplyY * 85;

                newEntry.c = database.GetCard(s);
                newEntry.c.LoadBitmaps();
                newEntry.p = new PictureBox();

                newEntry.p.Size        = newEntry.c.croppedImage.Size;
                newEntry.p.Left        = baseX + 4;
                newEntry.p.Top         = baseY + 18;
                newEntry.p.BorderStyle = BorderStyle.FixedSingle;

                newEntry.p.Image      = newEntry.c.croppedImage;
                newEntry.p.MouseMove += delegate { pictureBoxCardImage.BackgroundImage = newEntry.c.fullImage; };

                newEntry.nameLabel             = new Label();
                newEntry.nameLabel.Left        = baseX;
                newEntry.nameLabel.Top         = baseY;
                newEntry.nameLabel.Width       = 58;
                newEntry.nameLabel.Height      = 60;
                newEntry.nameLabel.BorderStyle = BorderStyle.FixedSingle;
                newEntry.nameLabel.Text        = newEntry.c.PrettyName();
                newEntry.nameLabel.TextAlign   = ContentAlignment.TopCenter;
                newEntry.nameLabel.BackColor   = newEntry.c.BackColor();
                newEntry.nameLabel.Font        = this.Font;

                newEntry.countLabel           = new Label();
                newEntry.countLabel.Left      = baseX;
                newEntry.countLabel.Top       = baseY + 61;
                newEntry.countLabel.Width     = 58;
                newEntry.countLabel.Height    = 20;
                newEntry.countLabel.Text      = "";
                newEntry.countLabel.TextAlign = ContentAlignment.TopCenter;
                newEntry.countLabel.Font      = this.Font;
                newEntry.countLabel.BackColor = Color.Transparent;

                panelSupply.Controls.Add(newEntry.p);
                panelSupply.Controls.Add(newEntry.nameLabel);
                panelSupply.Controls.Add(newEntry.countLabel);

                supplyX++;

                if (supplyX == 3 && supplyY == 0 && !supplyCards.Contains("platinum"))
                {
                    supplyX++;
                }
                if (supplyX == 4 && supplyY == 0 && !supplyCards.Contains("potion"))
                {
                    supplyX++;
                }
                if (supplyX == 3 && supplyY == 1 && !supplyCards.Contains("colony"))
                {
                    supplyX++;
                }

                if (supplyX >= 5)
                {
                    supplyX = 0;
                    supplyY++;
                }
            }
        }
Exemplo n.º 13
0
        private void ProcessDecision()
        {
            List <Card> result = new List <Card>();
            int         choice = -1;

            foreach (ButtonBase b in panelDecision.Controls)
            {
                if (b is CardCheckBox && (b as CardCheckBox).Checked)
                {
                    result.Add((b as CardCheckBox).c);
                }
                if (b is CardRadioButton && (b as CardRadioButton).Checked)
                {
                    result.Add((b as CardRadioButton).c);
                }
                if (b is ChoiceRadioButton && (b as ChoiceRadioButton).Checked)
                {
                    choice = (b as ChoiceRadioButton).choice;
                }
            }
            if (decision.type == "choice")
            {
                //
                // discrete choice decision
                //
                if (choice >= 0)
                {
                    String response = "response@" + choice.ToString();
                    DLLInterface.ProcessCommand(response);
                    UpdateAllState();
                }
                else
                {
                    labelError.Text = "You must choose an option.";
                }
            }
            else if (decision.type == "selectCard")
            {
                //
                // card select decision
                //
                if (result.Count >= decision.minimumCount && result.Count <= decision.maximumCount)
                {
                    String response = "response@";
                    foreach (Card c in result)
                    {
                        response += c.name + "|";
                    }
                    DLLInterface.ProcessCommand(response);
                    UpdateAllState();
                }
                else
                {
                    if (decision.minimumCount == 1 && decision.minimumCount == 1)
                    {
                        labelError.Text = "You must choose a card.";
                    }
                    else if (decision.minimumCount == decision.maximumCount)
                    {
                        labelError.Text = "You must select exactly " + decision.minimumCount + " cards.";
                    }
                    else
                    {
                        labelError.Text = "You must select between " + decision.minimumCount + " and " + decision.maximumCount + " cards.";
                    }
                }
            }
        }
Exemplo n.º 14
0
        public string Strategize(int generationCount, int chamberCount)
        {
            if (supply == null || supply.Count == 0)
            {
                return("");
            }

            string directory = Utility.MD5Hash(DLLInterface.GetString("kingdomDescription"));

            Directory.CreateDirectory("kingdomsIntermediate/");
            Directory.CreateDirectory("kingdomsFinal/");
            Directory.CreateDirectory("kingdomsIntermediate/" + directory);
            Directory.CreateDirectory("kingdomsIntermediate/" + directory + "/generations");
            Directory.CreateDirectory("kingdomsIntermediate/" + directory + "/leaderboard");
            Directory.CreateDirectory("kingdomsIntermediate/" + directory + "/progression");

            using (StreamWriter parameterFile = new System.IO.StreamWriter("TournamentParameters.txt"))
            {
                parameterFile.WriteLine(DLLInterface.GetString("kingdomDescription").Replace("@", "|"));
                parameterFile.WriteLine("kingdomsIntermediate/" + directory + "/");
                parameterFile.WriteLine("generations=" + generationCount.ToString());
                parameterFile.WriteLine("chambers=" + chamberCount.ToString());
                parameterFile.Close();
            }

            if (activeProcess == null)
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow         = false;
                startInfo.RedirectStandardOutput = false;
                startInfo.RedirectStandardInput  = false;
                startInfo.WindowStyle            = ProcessWindowStyle.Minimized;

                startInfo.UseShellExecute = true;
                startInfo.FileName        = "TestingGroundsInternal.exe";

                activeProcess           = new Process();
                activeProcess.StartInfo = startInfo;
                activeProcess.Start();

                return("kingdomsIntermediate/" + directory + "/leaderboard/");
            }
            else
            {
                MessageBox.Show("Cannot launch a new tournament while the previous one is still running.", "Error");
                return("");
            }

            /*DLLInterface.ProcessCommand("trainAIStart@kingdoms/" + directory + "/@1");
             *
             * for (int generationIndex = 0; generationIndex < 64; generationIndex++)
             * {
             *  DLLInterface.ProcessCommand("trainAIStep");
             *
             *  List<string> leaderboardFiles = new List<string>(Directory.EnumerateFiles("kingdoms/" + directory + "/leaderboard", "*.txt"));
             *  foreach (var f in leaderboardFiles)
             *  {
             *      if (!File.Exists(f.Replace(".txt", ".png")))
             *      {
             *          DominionVisualization vis = new DominionVisualization(database, f, f.Replace(".txt", ".png"));
             *      }
             *  }
             *
             *  List<string> progressionFiles = new List<string>(Directory.EnumerateFiles("kingdoms/" + directory + "/progression", "*.txt"));
             *  foreach (var f in progressionFiles)
             *  {
             *      if (!File.Exists(f.Replace(".txt", ".png")))
             *      {
             *          DominionVisualization vis = new DominionVisualization(database, f, f.Replace(".txt", ".png"));
             *      }
             *  }
             * }
             *
             * Utility.SafeFileCopy(directory + "/leaderboard/063.png", "kingdomVisualizations/" + directory + "_l.png");
             * Utility.SafeFileCopy(directory + "/progression/063.png", "kingdomVisualizations/" + directory + "_p.png");*/
        }
Exemplo n.º 15
0
 private void UpdateHand()
 {
     UpdateArea(panelHand, DLLInterface.GetString("hand"));
 }
Exemplo n.º 16
0
 private void UpdatePlayArea()
 {
     UpdateArea(panelPlayArea, DLLInterface.GetString("playArea"));
 }
Exemplo n.º 17
0
        private void UpdateDecision()
        {
            panelDecision.Controls.Clear();
            labelError.Text = null;

            int x = 0;
            int y = 0;

            List <String> s = new List <String>(DLLInterface.GetString("decision").Split('@'));

            decision.type = s[0];

            if (decision.type == "none")
            {
                labelDecision.Text = "No decision?";
            }
            else if (decision.type == "gameover")
            {
                labelActiveCard.Text        = "";
                labelActiveCardName.Visible = false;
                labelDecision.Text          = "Game Over!";
            }
            else if (decision.type == "selectCard")
            {
                String playerName = s[2];
                labelDecision.Text    = "(" + playerName + ") " + s[3];
                decision.minimumCount = Convert.ToInt32(s[4]);
                decision.maximumCount = Convert.ToInt32(s[5]);

                String activeCardName = s[6];
                if (activeCardName.StartsWith("phase"))
                {
                    labelActiveCard.Text        = Utility.PhaseName(Convert.ToInt32(activeCardName.Split('|')[1])) + " Phase";
                    labelActiveCardName.Visible = false;
                }
                else
                {
                    Card activeCard = database.GetCard(activeCardName);
                    labelActiveCard.Text          = "Active Card:";
                    labelActiveCardName.Text      = activeCard.PrettyName();
                    labelActiveCardName.BackColor = activeCard.BackColor();
                    labelActiveCardName.Visible   = true;
                }

                var sortedList = new List <String>(s[7].Split('|'));
                var cards      = sortedList.Select(z => database.GetCard(z));
                cards = cards.OrderByDescending(a => a.cost).ThenBy(a => a.name).ToList();
                foreach (Card c in cards)
                {
                    ButtonBase button;
                    if (decision.maximumCount == 1)
                    {
                        button        = new CardRadioButton(c);
                        button.Click += delegate { ProcessDecision(); };
                    }
                    else
                    {
                        button = new CardCheckBox(c);
                    }

                    button.Left        = x * 150 + 3;
                    button.Top         = y * 25 + 3;
                    button.MaximumSize = new Size(145, 23);
                    button.Text        = c.PrettyName();
                    button.BackColor   = c.BackColor();
                    button.Font        = panelDecision.Font;
                    button.AutoSize    = true;
                    button.MouseMove  += delegate { pictureBoxCardImage.BackgroundImage = c.fullImage; };
                    button.Padding     = new Padding(3, 1, 1, 1);
                    panelDecision.Controls.Add(button);

                    y++;
                    if (y == 5)
                    {
                        x++;
                        y = 0;
                    }
                }
            }
            else if (decision.type == "choice")
            {
                String   playerName = s[2];
                String[] parts      = s[3].Split('|');
                labelDecision.Text = "(" + playerName + ") " + parts[0];

                for (int choiceIndex = 1; choiceIndex < parts.Length; choiceIndex++)
                {
                    ButtonBase button = new ChoiceRadioButton(choiceIndex - 1);
                    button.Click += delegate { ProcessDecision(); };

                    button.Left        = x * 190 + 3;
                    button.Top         = y * 25 + 3;
                    button.MaximumSize = new Size(185, 23);
                    button.Text        = parts[choiceIndex];
                    button.Font        = panelDecision.Font;
                    button.AutoSize    = true;
                    button.Padding     = new Padding(3, 1, 1, 1);
                    panelDecision.Controls.Add(button);

                    y++;
                    if (y == 5)
                    {
                        x++;
                        y = 0;
                    }
                }
            }
        }