Exemple #1
0
        public void PlayGame()
        {
            if (versusIndex == playerIndex)
            {
                versusIndex++;
            }

            if (versusIndex >= Players.Count)
            {
                playerIndex++;
                versusIndex = 0;
            }

            if (playerIndex >= Players.Count)
            {
                if (_currentGenIteration < _iterationsPerGeneration)
                {
                    //resets player
                    versusIndex = 0;
                    playerIndex = 0;
                    _currentGenIteration++;
                }
                else
                {
                    //reset generation
                    _currentGenIteration = 0;
                    versusIndex          = 0;
                    playerIndex          = 0;
                    CreateGen();
                    currentGen++;
                }
            }
            else
            {
                Pig.Player p1 = Players[playerIndex];
                Pig.Player p2 = Players[versusIndex];
                versusIndex++;

                //get two players
                Pig.Pig game = new Pig.Pig(p1, p2);
                game.trainType = trainType;

                while (!game.hasEnded && game.turnCount < game.maxTurns)
                {
                    //breaks here
                    game.PlayRound();
                    Constants.debugGen++;
                }

                p1.gameCount++;
                p2.gameCount++;
                game.CalculateFitness();
            }
        }
        public void PlayGenIteration()
        {
            int playerIndex = 0;
            int versusIndex = 0;

            while (true)
            {
                if (versusIndex == playerIndex)
                {
                    versusIndex++;
                }

                if (versusIndex >= Players.Count)
                {
                    playerIndex++;
                    versusIndex = 0;
                }

                if (playerIndex >= Players.Count)
                {
                    Thread.CurrentThread.Abort();

                    //done the work end thread
                }
                else
                {
                    Pig.Player p1 = Players[playerIndex];
                    Pig.Player p2 = Players[versusIndex];
                    versusIndex++;

                    //get two players
                    Pig.Pig game = new Pig.Pig(p1, p2);

                    while (!game.hasEnded && game.turnCount < game.maxTurns)
                    {
                        //breaks here
                        game.PlayRound();
                        Constants.debugGen++;
                    }

                    p1.gameCount++;
                    p2.gameCount++;
                    game.CalculateFitness();
                }
            }
        }
Exemple #3
0
        public void PlayGame()
        {
            if (versusIndex == playerIndex)
            {
                versusIndex++;
            }

            if (versusIndex >= Players.Count)
            {
                playerIndex++;
                versusIndex = 0;
            }

            if (playerIndex >= Players.Count)
            {
                CreateGen();
                currentGen++;
                versusIndex = 0;
                playerIndex = 0;
            }
            else
            {
                Pig.Player p1 = Players[playerIndex];
                Pig.Player p2 = Players[versusIndex];
                versusIndex++;

                //get two players
                Pig.Pig game = new Pig.Pig(p1, p2);

                while (!game.hasEnded && game.turnCount < game.maxTurns)
                {
                    //breaks here
                    game.PlayRound();
                    Constants.debugGen++;
                }

                p1.gameCount++;
                p2.gameCount++;
                game.CalculateFitness();
            }
        }