예제 #1
0
        public void PatternJudgeWontTakeHalfThreeAsFive()
        {
            var boardString = new[]
            {
                // 2345678910
                "           ", // 0
                " O         ", // 1
                "  X        ", // 2
                "   XX   X  ", // 3
                "    XOOO   ", // 4
                "    XXO    ", // 5
                "    OOOX   ", // 6
                "           ", // 7
                "           ", // 8
                "           ", // 9
                "           ", // 10
            };

            var context = new BoardProperties(boardString.Length, boardString[0].Length);

            var positions           = new PositionFactory().Create(context);
            var patterns            = new PatternFactory().Create();
            var matcher             = new PatternMatcher(patterns);
            var boardFactory        = new BoardFactory(context, positions);
            var patternBoardFactory = new PatternBoardFactory(context, positions, matcher);
            var centerScorer        = new CenterScorer(context, positions);
            var patternScorer       = new PatternScorer(positions, patterns, matcher);
            var aggregatedScorer    = new AggregatedScorer(new[]
            {
                new Tuple <IScorer, double>(patternScorer, 1),
                new Tuple <IScorer, double>(centerScorer, 0.01)
            });
            var judge  = new PatternJudge(positions, patterns, matcher);
            var board  = Utils.ParseBoard(boardString, context, positions);
            var winner = judge.GetWinner(board);

            Assert.AreEqual(PieceType.Empty, winner);
        }
예제 #2
0
        private IEnumerable <IPlayer> GetAiPlayers(BoardProperties context, PositionManager positions, PieceType player)
        {
            var patterns            = new PatternFactory().Create();
            var matcher             = new PatternMatcher(patterns);
            var patternBoardFactory = new PatternBoardFactory(context, positions, matcher);
            var centerScorer        = new CenterScorer(context, positions);
            var patternScorer       = new PatternScorer(positions, patterns, matcher);
            var aggregatedScorer    = new AggregatedScorer(new[]
            {
                new Tuple <IScorer, double>(patternScorer, 1),
                new Tuple <IScorer, double>(centerScorer, 0.01)
            });
            var judge = new BasicJudge(context, positions);
            var emptyMoveEnumerator  = new EmptyPositionMoveEnumerator(positions);
            var scoredMoveEnumerator = new ScoredMoveEnumerator(positions, aggregatedScorer);

            return(new[]
            {
                new AbPruningAi(player, 1, aggregatedScorer, scoredMoveEnumerator, patternBoardFactory, judge),
                new AbPruningAi(player, 2, aggregatedScorer, scoredMoveEnumerator, patternBoardFactory, judge),
                new AbPruningAi(player, 3, aggregatedScorer, scoredMoveEnumerator, patternBoardFactory, judge)
            });
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var context             = new BoardProperties();
            var positions           = new PositionFactory().Create(context);
            var patterns            = new PatternFactory().Create();
            var matcher             = new PatternMatcher(patterns);
            var boardFactory        = new BoardFactory(context, positions);
            var patternBoardFactory = new PatternBoardFactory(context, positions, matcher);
            var centerScorer        = new CenterScorer(context, positions);
            var patternScorer       = new PatternScorer(positions, patterns, matcher);
            var aggregatedScorer    = new AggregatedScorer(new[]
            {
                new Tuple <IScorer, double>(patternScorer, 1),
                new Tuple <IScorer, double>(centerScorer, 0.01)
            });
            var judge = new PatternJudge(positions, patterns, matcher);
            var emptyMoveEnumerator  = new EmptyPositionMoveEnumerator(positions);
            var scoredMoveEnumerator = new ScoredMoveEnumerator(positions, aggregatedScorer);

            IGame game = new GameFactory().CreateGame(boardFactory,
                                                      //new HumanPlayer(),
                                                      //new RandomPlayer(positions),
                                                      //new RandomPlayer(positions),
                                                      new AbPruningAi(PieceType.P1, 3, aggregatedScorer, scoredMoveEnumerator, patternBoardFactory, judge),
                                                      new AbPruningAi(PieceType.P2, 3, aggregatedScorer, scoredMoveEnumerator, patternBoardFactory, judge),
                                                      //new AbPruningAi(PieceType.P2, 2, patternScorer, emptyMoveEnumerator, patternBoardFactory, judge),
                                                      judge
                                                      );

            game.Start();
            var board = game.Board;

            DisplayBoard(board, context);

            do
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                game.Run();

                stopWatch.Stop();
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = $"{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
                Console.WriteLine($"Elapsed time {elapsedTime}.");
                Debug.WriteLine($"Elapsed time {elapsedTime}.");

                DisplayBoard(board, context);

                DebugInfo(positions, board, matcher);

                if (game.GameStatus == GameStatus.P1Win)
                {
                    Console.WriteLine("Winner is player 1.");
                }
                else if (game.GameStatus == GameStatus.P2Win)
                {
                    Console.WriteLine("Winner is player 2.");
                }
                else if (game.GameStatus == GameStatus.Tie)
                {
                    Console.WriteLine("Game ties.");
                }
                //System.Threading.Thread.Sleep(500);
                //Console.ReadLine();
            } while (game.GameStatus == GameStatus.NotEnd);
            Console.ReadLine();
        }