Beispiel #1
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();
        }