Example #1
0
        public List <float> CalculateScoresThroughSequence(Board board)
        {
            board.RecalculateScore();

            var result = new List <float> {
                board.Score
            };

            board = board.MakeMove(Move);
            board.RecalculateScore();

            result.Add(board.Score);

            var nextmove = NextMove;

            while (nextmove != null)
            {
                board = board.MakeMove(nextmove.Move);
                board.RecalculateScore();
                result.Add(board.Score);

                nextmove = nextmove.NextMove;
            }

            return(result);
        }
Example #2
0
        public List <MoveSequence> AlphaBetaRecursive(Board board, int depth, bool isWhite)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var result = new List <MoveSequence>();

            _numberOfLeafEvaluations = 0;
            _numberOfBranchesPruned  = 0;

            MoveSequence alpha = new MoveSequence {
                Value = float.NegativeInfinity
            };
            MoveSequence beta = new MoveSequence {
                Value = float.PositiveInfinity
            };

            board.RecalculateScore();

            var moves = board.GetMovesForPlayer(isWhite ? EnumBoardSquare.White : EnumBoardSquare.Black);

            if (isWhite)
            {
                moves = moves.OrderByDescending(x => x.ScoreChange).ToArray();
            }
            else
            {
                moves = moves.OrderBy(x => x.ScoreChange).ToArray();
            }

            foreach (var move in moves)
            {
                var scoreChange = AlphaBetaRecursive(board, move, depth - 1, alpha, beta, !isWhite);
                result.Add(scoreChange);
            }

            //Parallel.ForEach(moves, (Move move) =>
            //{
            //    var scoreChange = AlphaBetaRecursive(board, move, depth - 1, alpha, beta, !isWhite);

            //    lock (_lock)
            //    {
            //        result.Add(scoreChange);
            //    }
            //});


            _durationMilliseconds = sw.ElapsedMilliseconds;

            if (isWhite)
            {
                return(Shuffle(result).OrderByDescending(x => x.Value).ToList());
            }
            else
            {
                return(Shuffle(result).OrderBy(x => x.Value).ToList());
            }
        }