Пример #1
0
        protected override int GetHeuristic(Board board, BoardState state)
        {
            if (board.CountPieces(enPiece.Empty) < 12)
            {
                int whiteCount = board.CountPieces(enPiece.White);
                int blackCount = board.CountPieces(enPiece.Black);

                return(whiteCount - blackCount);
            }
            else
            {
                //Count Pieces
                int nMobility = (board.CountMoves(enPiece.White) - board.CountMoves(enPiece.Black));
                return(nMobility);
            }
        }
Пример #2
0
        protected override int GetHeuristic(Board board, BoardState state)
        {
            //Count Pieces
            int whiteCount = board.CountPieces(enPiece.White);
            int blackCount = board.CountPieces(enPiece.Black);
            int nCount     = whiteCount - blackCount;

            if (state.GameOver)
            {
                return(10000 * nCount);
            }

            //Mobility
            int nMobility = (board.CountMoves(enPiece.White) - board.CountMoves(enPiece.Black));

            //Mask
            int nMask = MaskBasedScore(board);

            return(m_nMobilityWeight * nMobility + m_nMaskWeight * nMask + m_nCountWeight * nCount);
        }
Пример #3
0
        protected override int GetHeuristic(Board board, BoardState state)
        {
            int    my_tiles = 0, opp_tiles = 0, i, j, k, my_front_tiles = 0, opp_front_tiles = 0, x, y;
            double p = 0, c = 0, l = 0, m = 0, f = 0, d = 0;

            int[] X1 = new int[] { -1, -1, 0, 1, 1, 1, 0, -1 };
            int[] Y1 = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 };

            int[,] V = new int[, ] {
                { 20, -3, 11, 8, 8, 11, -3, 20 },
                { -3, -7, -4, 1, 1, -4, -7, -3 },
                { 11, -4, 2, 2, 2, 2, -4, 11 },
                { 8, 1, 2, -3, -3, 2, 1, 8 },
                { 8, 1, 2, -3, -3, 2, 1, 8 },
                { 11, -4, 2, 2, 2, 2, -4, 11 },
                { -3, -7, -4, 1, 1, -4, -7, -3 },
                { 20, -3, 11, 8, 8, 11, -3, 20 }
            };
            // Piece difference, frontier disks and disk squares
            for (i = 0; i < 8; i++)
            {
                for (j = 0; j < 8; j++)
                {
                    if (board[i, j] == enPiece.White)
                    {
                        d += V[i, j];
                        my_tiles++;
                    }
                    else if (board[i, j] == enPiece.Black)
                    {
                        d -= V[i, j];
                        opp_tiles++;
                    }
                    if (board[i, j] != enPiece.Empty)
                    {
                        for (k = 0; k < 8; k++)
                        {
                            x = i + X1[k]; y = j + Y1[k];

                            if (x >= 0 && x < 8 && y >= 0 && y < 8 && board[x, y] == enPiece.Empty)
                            {
                                if (board[i, j] == enPiece.White)
                                {
                                    my_front_tiles++;
                                }
                                else
                                {
                                    opp_front_tiles++;
                                }
                                break;
                            }
                        }
                    }
                }
            }

            p = (100.0 * (my_tiles - opp_tiles)) / (my_tiles + opp_tiles);

            if (state.GameOver)
            {
                return((int)Math.Round(p));
            }

            f = -(100.0 * (my_front_tiles - opp_front_tiles)) / (my_front_tiles + opp_front_tiles);

            // Corner occupancy
            my_tiles = opp_tiles = 0;
            if (board[0, 0] == enPiece.White)
            {
                my_tiles++;
            }
            else if (board[0, 0] == enPiece.Black)
            {
                opp_tiles++;
            }
            if (board[0, 7] == enPiece.White)
            {
                my_tiles++;
            }
            else if (board[0, 7] == enPiece.Black)
            {
                opp_tiles++;
            }
            if (board[7, 0] == enPiece.White)
            {
                my_tiles++;
            }
            else if (board[7, 0] == enPiece.Black)
            {
                opp_tiles++;
            }
            if (board[7, 7] == enPiece.White)
            {
                my_tiles++;
            }
            else if (board[7, 7] == enPiece.Black)
            {
                opp_tiles++;
            }
            c = 25 * (my_tiles - opp_tiles);
            // Corner closeness
            my_tiles = opp_tiles = 0;
            if (board[0, 0] == enPiece.Empty)
            {
                if (board[0, 1] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[0, 1] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[1, 1] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[1, 1] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[1, 0] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[1, 0] == enPiece.Black)
                {
                    opp_tiles++;
                }
            }
            if (board[0, 7] == enPiece.Empty)
            {
                if (board[0, 6] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[0, 6] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[1, 6] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[1, 6] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[1, 7] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[1, 7] == enPiece.Black)
                {
                    opp_tiles++;
                }
            }
            if (board[7, 0] == enPiece.Empty)
            {
                if (board[7, 1] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[7, 1] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[6, 1] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[6, 1] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[6, 0] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[6, 0] == enPiece.Black)
                {
                    opp_tiles++;
                }
            }
            if (board[7, 7] == enPiece.Empty)
            {
                if (board[6, 7] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[6, 7] == enPiece.Black)
                {
                    opp_tiles++;
                }
                if (board[6, 6] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[6, 6] == enPiece.Black)
                {
                    opp_tiles++;
                }

                if (board[7, 6] == enPiece.White)
                {
                    my_tiles++;
                }
                else if (board[7, 6] == enPiece.Black)
                {
                    opp_tiles++;
                }
            }
            l = -12.5 * (my_tiles - opp_tiles);
            // Mobility
            my_tiles  = board.CountMoves(enPiece.White);
            opp_tiles = board.CountMoves(enPiece.Black);

            m = (100.0 * (my_tiles - opp_tiles)) / (my_tiles + opp_tiles);

            // final weighted score
            double score = (10 * p) + (801.724 * c) + (382.026 * l) + (78.922 * m) + (74.396 * f) + (10 * d);

            return((int)Math.Round(score));
        }