Esempio n. 1
0
                public double Eval()
                {
                    int    myTiles  = 0;
                    int    oppTiles = 0;
                    double q        = 0;

                    int myTurn;
                    int oppTurn;

                    int[,] V = new int[, ]
                    {
                        { 20, -3, 11, 8, 2, 8, 11, -3, 20 },
                        { -3, -7, -4, 1, -3, 1, -4, -7, -3 },
                        { 11, -4, 2, 2, -3, 2, 2, -4, 11 },
                        { 8, 1, 2, -3, -3, -3, 2, 1, 8 },
                        { 11, -4, 2, 2, -3, 2, 2, -4, 11 },
                        { -3, -7, -4, 1, -3, 1, -4, -7, -3 },
                        { 20, -3, 11, 8, 2, 8, 11, -3, 20 }
                    };

                    if (p.WhiteTurn)
                    {
                        myTurn  = 0;
                        oppTurn = 1;
                    }
                    else
                    {
                        myTurn  = 1;
                        oppTurn = 0;
                    }
                    double d = 0;

                    for (int i = 0; i < nodeBoard.GetLength(0); i++)
                    {
                        for (int j = 0; j < nodeBoard.GetLength(1); j++)
                        {
                            if (nodeBoard[i, j] == myTurn)
                            {
                                myTiles++;
                                d += V[i, j];
                            }

                            else if (nodeBoard[i, j] == oppTurn)
                            {
                                oppTiles++;
                                d -= V[i, j];
                            }
                        }
                    }

                    if (myTiles > oppTiles)
                    {
                        q = (100 * myTiles) / (myTiles + oppTiles);
                    }
                    else if (myTiles < oppTiles)
                    {
                        q = -(100.0 * oppTiles) / (myTiles + oppTiles);
                    }
                    else
                    {
                        q = 0;
                    }


                    //corner
                    myTiles  = 0;
                    oppTiles = 0;
                    double c = 0;


                    if (nodeBoard[0, 0] == myTurn)
                    {
                        myTiles++;
                    }
                    else if (nodeBoard[0, 0] == myTurn)
                    {
                        oppTurn++;
                    }
                    if (nodeBoard[0, 8] == myTurn)
                    {
                        myTiles++;
                    }
                    else if (nodeBoard[0, 8] == myTurn)
                    {
                        oppTurn++;
                    }
                    if (nodeBoard[6, 0] == myTurn)
                    {
                        myTiles++;
                    }
                    else if (nodeBoard[6, 0] == myTurn)
                    {
                        oppTurn++;
                    }
                    if (nodeBoard[6, 8] == myTurn)
                    {
                        myTiles++;
                    }
                    else if (nodeBoard[6, 8] == myTurn)
                    {
                        oppTurn++;
                    }

                    c = 25 * (myTiles - oppTiles);

                    //corner closeness
                    myTiles  = 0;
                    oppTiles = 0;

                    if (nodeBoard[0, 0] == -1)
                    {
                        if (nodeBoard[0, 1] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[0, 1] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[1, 1] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[1, 1] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[1, 0] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[1, 0] == oppTurn)
                        {
                            oppTiles++;
                        }
                    }
                    if (nodeBoard[0, 8] == -1)
                    {
                        if (nodeBoard[0, 7] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[0, 7] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[1, 7] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[1, 7] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[1, 8] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[1, 8] == oppTurn)
                        {
                            oppTiles++;
                        }
                    }
                    if (nodeBoard[6, 0] == -1)
                    {
                        if (nodeBoard[6, 1] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[6, 1] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[5, 1] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[5, 1] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[5, 0] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[5, 0] == oppTurn)
                        {
                            oppTiles++;
                        }
                    }
                    if (nodeBoard[6, 8] == -1)
                    {
                        if (nodeBoard[5, 7] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[5, 7] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[6, 7] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[6, 7] == oppTurn)
                        {
                            oppTiles++;
                        }
                        if (nodeBoard[5, 8] == myTurn)
                        {
                            myTiles++;
                        }
                        else if (nodeBoard[5, 8] == oppTurn)
                        {
                            oppTiles++;
                        }
                    }
                    double l = -12.5 * (myTiles - oppTiles);

                    if (myTurn == 0)
                    {
                        myTiles  = p.PossibleMoves(true).Count;
                        oppTiles = p.PossibleMoves(false).Count;
                    }
                    else
                    {
                        myTiles  = p.PossibleMoves(false).Count;
                        oppTiles = p.PossibleMoves(true).Count;
                    }

                    double m = 0;

                    if (myTiles > oppTiles)
                    {
                        myTiles = (100 * myTiles) / (myTiles + oppTiles);
                    }
                    else if (myTiles < oppTiles)
                    {
                        m = -(100 * oppTiles) / (myTiles + oppTiles);
                    }
                    else
                    {
                        m = 0;
                    }

                    double score = (10 * q) + (801.724 * c) + (382.026 * l) + (78.922 * m) + (10 * d);

                    return(d);
                }