Example #1
0
        private void TestBots()
        {
            foreach (DataRow datarow in dtBotConfig.Rows)
            {
                BotClass bot = new BotClass(0, datarow[0].ToString(), datarow[1].ToString());
                OutputText(String.Format(">Testing {0} .......", bot.Name));

                if (HTTPUtility.GetMove(bot) != "failed")
                {
                    OutputText("test passed.\n");
                    datarow[3] = "Ok";
                }
                else
                {
                    datarow[2] = false;
                    datarow[3] = "Error";
                    OutputText(String.Format("{0} test failed:  Exception {1} \n", bot.Name, "failed to receive"));
                }
            }
        }
Example #2
0
        public void CommenceBattle(UpdateMatchProgressDelegate updateCurrentMatch, int gameCount, int totalGames)
        {
            updateCurrentMatch += this.UpdateCurrentMatch;

            if (HTTPUtility.SendStartInstruction(this._bot1, this._bot2, this._pointsToWin, this._maxRounds, this._dynamite) == "failed")
            {
                AbandonBattle(this._bot2);
                return;
            }

            if (HTTPUtility.SendStartInstruction(this._bot2, this._bot1, this._pointsToWin, this._maxRounds, this._dynamite) == "failed")
            {
                AbandonBattle(this._bot1);
                return;
            }


            int  points           = 1;
            bool maxPointsReached = false;

            for (int rcount = 1; rcount < this._maxRounds && !maxPointsReached; rcount++)
            {
                this._bot1.LastMove = HTTPUtility.GetMove(this._bot1);
                this._bot2.LastMove = HTTPUtility.GetMove(this._bot2);

                HTTPUtility.PostMove(this._bot1, this._bot2.LastMove);
                HTTPUtility.PostMove(this._bot2, this._bot1.LastMove);

                if (this._bot1.LastMove == "failed")
                {
                    AbandonBattle(this._bot2);
                    return;
                }

                if (this._bot2.LastMove == "failed")
                {
                    AbandonBattle(this._bot1);
                    return;
                }

                switch (WinningMove(this._bot1.LastMove, this._bot2.LastMove))
                {
                case 0:
                {
                    points++;
                    break;
                }

                case 1:
                {
                    this._bot1.AddWin(points);
                    points = 1;
                    break;
                }

                case 2:
                {
                    this._bot2.AddWin(points);
                    points = 1;
                    break;
                }

                default:
                    break;
                }
                maxPointsReached = ((this._bot1.TotalPoints >= this._pointsToWin) ||
                                    (this._bot2.TotalPoints >= this._pointsToWin));

                updateCurrentMatch(this, gameCount, totalGames);
            }

            RegisterBattleWinner();
        }