예제 #1
0
 public static void initSettings(int level)
 {
     searchDepth = level;
     BoardLogic.initUseWeights(useWeights);
 }
예제 #2
0
        public static int[] alphaBeta(Move move, int depth, int A, int B, bool maxPlayer)
        {
            if (depth == 0 /*|| move.boardValue >= 3000 || move.boardValue <= -3000*/)
            {
                return new int[2] {
                           move.boardValue, maxDepth - depth
                }
            }
            ;


            List <int[]> possibleMoves = BoardLogic.getAvailabeMoves(maxPlayer, move.postBoard);

            if (possibleMoves.Count == 0)
            {
                return new int[2] {
                           BoardLogic.getRealScore(move.postBoard), maxDepth - depth
                }
            }
            ;

            if (maxPlayer)
            {
                int[] value = new int[2] {
                    -6000, maxDepth - depth
                };

                foreach (int[] i in possibleMoves)
                {
                    Move tempMove = new Move(i, move.postBoard, true);

                    int[] tempValue = alphaBeta(tempMove, depth - 1, A, B, false);
                    if (tempValue [0] >= value [0])
                    {
                        value = tempValue;
                    }

                    A = Math.Max(value[0], A);
                    if (B <= A)
                    {
                        break;
                    }
                }


                return(value);
            }


            int[] minValue = new int[2] {
                6000, maxDepth - depth
            };
            foreach (int[] i in possibleMoves)
            {
                Move tempMove = new Move(i, move.postBoard, false);

                int[] tempValue = alphaBeta(tempMove, depth - 1, A, B, true);
                if (tempValue [0] <= minValue [0])
                {
                    minValue = tempValue;
                }

                B = Math.Min(minValue[0], B);

                if (B <= A)
                {
                    break;
                }
            }

            return(minValue);
        }