Пример #1
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)
            });
        }
Пример #2
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();
        }