Ejemplo n.º 1
0
        public static void TestSearch()
        {
            Position position = new Position(Board.EMPTY_BOARD);

            position.Set("hy5", Board.YELLOW);
            position.Set("hr5", Board.RED);
            position.Set("hg5", Board.GREEN);
            position.Set("hb5", Board.BLUE);
            position.Set("y6", Board.BLUE);
            position.Set("r2", Board.GREEN);


            Board board = new Board();

            board.SetPosition(position);

            Algorithm alg = new MaxN(board);

            alg.Root   = new PositionNode(position, null, new DiceRoll(1, 6));
            alg.Player = Board.YELLOW;



            Console.ReadKey();

            //Assert.Inconclusive("Search Time: " + time);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the MaxN Algorithm for a board
        /// </summary>
        /// <param name="board">Board</param>
        public MPMix(Board board, double offensiveThreshold, double defensiveThreshold) : base(board)
        {
            maxNAlgorithm      = new MaxN(board);
            paranoidAlgorithm  = new Paranoid(board);
            offensiveAlgorithm = new Offensive(board);

            this.offensiveThreshold = offensiveThreshold;
            this.defensiveThreshold = defensiveThreshold;
        }
Ejemplo n.º 3
0
 public ComputerPlayer(sbyte team, Personality personality, Difficulty difficulty, BoardView boardView)
     : base(team, false, boardView)
 {
     Difficulty         = difficulty;
     Personality        = personality;
     maxNAlgorithm      = new MaxN(boardView.Board);
     paranoidAlgorithm  = new Paranoid(boardView.Board);
     offensiveAlgorithm = new Offensive(boardView.Board);
     mixAlgorithm       = new MPMix(boardView.Board, 0.5, 0.5);
     mctsAlgorithm      = new MCTS(boardView.Board);
 }
Ejemplo n.º 4
0
        public static sbyte SimulateGame()
        {
            Board     board     = new Board();
            Algorithm mpMix     = new MPMix(board, 1, 0.5);
            Algorithm maxN      = new MaxN(board);
            Algorithm paranoid  = new Paranoid(board);
            Algorithm offensive = new Offensive(board);
            Algorithm mcts      = new MCTS(board);

            int   doublesCount = 0;
            sbyte lastTeam     = 0;
            sbyte team         = 0;
            int   turns        = 0;

            while (!board.IsGameOver())
            {
                Console.Title = turns.ToString();
                lastTeam      = team;

                DiceRoll roll = board.GetRandomRoll();
                Move     m    = null;
                switch (team)
                {
                case 0:
                    m = board.ThinkBest(mcts, roll, team, 0);
                    break;

                case 1:
                    m = board.ThinkBest(maxN, roll, team, 0);
                    break;

                case 2:
                    m = board.ThinkBest(mcts, roll, team, 0);
                    break;

                case 3:
                    m = board.ThinkBest(mcts, roll, team, 0);
                    break;
                }
                if (m != null)
                {
                    board.PerformMove(m);
                }

                if (roll.IsDoubles())
                {
                    doublesCount++;
                    if (doublesCount >= 3)
                    {
                        board.RemoveFrontMarble(team);
                        doublesCount = 0;
                        team         = board.NextPlayer(team);
                        turns++;
                    }
                }
                else
                {
                    doublesCount = 0;
                    team         = board.NextPlayer(team);
                    turns++;
                }
            }

            Console.WriteLine("{0} won ({1} turns)", GetName(lastTeam), turns);
            return(lastTeam);
        }