Ejemplo n.º 1
0
        static Player LearnVsNaive(int gameCount)
        {
            Player white, black;
            var    game = new BackgammonGame(BackgammonGame.DefaultGameBoard, new RealDice());

            if (gameCount % 2 == 0)
            {
                white = new MachAI(game);
                black = new NaiveAI(game, Black);
            }
            else
            {
                black = new MachAI(game);
                white = new NaiveAI(game, White);
            }
            while (!TemporalDifference.GameOver(game.GetGameBoardState()))
            {
                if (game.playerToMove() == White)
                {
                    white.MakeMove();
                }
                else
                {
                    black.MakeMove();
                }
            }
            TemporalDifference.UpdateWeights(game.GetGameBoardState(), game.GetGameBoardState(), (gameCount % 2 == 0) ? White : Black);
            return((game.GetGameBoardState().getCheckersOnTarget(White) == 15) ? white : black);
        }
Ejemplo n.º 2
0
        private MovesCalculator.ReachableState PickLowest(MovesCalculator.ReachableState[] array)
        {
            var best = array[0];

            foreach (var rs in array)
            {
                if (TemporalDifference.ValueFunction(rs.state) < TemporalDifference.ValueFunction(best.state))
                {
                    best = rs;
                }
            }
            return(best);
        }
Ejemplo n.º 3
0
        static CheckerColor PitMachVsNaive(int gameCount)
        { // MachAI
            var    game  = new BackgammonGame(BackgammonGame.DefaultGameBoard, new RealDice());
            Player white = new MachAI(game);
            Player black = new NaiveAI(game, Black);

            while (!TemporalDifference.GameOver(game.GetGameBoardState()))
            {
                if (game.playerToMove() == White)
                {
                    white.MakeMove();
                }
                else
                {
                    black.MakeMove();
                }
            }
            return((game.GetGameBoardState().getCheckersOnTarget(White) == 15) ? White : Black);
        }
Ejemplo n.º 4
0
 internal CheckerColor Run()
 {
     while (!TemporalDifference.GameOver(st))
     {
         var outcome = PickBestOutcome();
         if (outcome == null)
         {
             game.EndTurn(game.playerToMove());
         }
         else
         {
             for (int i = 0; i < outcome.movesMade.Count; i++)
             {
                 game.Move(game.playerToMove(), outcome.movesMade[i].from, outcome.movesMade[i].to);
             }
             TemporalDifference.UpdateWeights(st, outcome.state, game.playerToMove());
             st = outcome.state;
         }
     }
     TemporalDifference.UpdateWeights(st, st, White);
     TemporalDifference.UpdateWeights(st, st, Black); // st1 doesn't matter when game is won.
     return((game.GetGameBoardState().getCheckersOnTarget(White) == 15) ? White : Black);
 }
Ejemplo n.º 5
0
 internal void MakeMoveAndLearn()
 {
     MakeMove();
     TemporalDifference.UpdateWeights(st, outcome.state, game.playerToMove());
 }