Ejemplo n.º 1
0
        public static int[] MakeTurn(Board game, int level)
        {
            int[] bestMove = new int[4];
            int mostValuable = -999999999;
            int tempVal = 0;

            for (int i = 0; i < 8; i++)
                for (int j = 0; j < 8; j++)
                {
                    for (int k = 0; k < 8; k++)
                        if (game.GetPiece(i, j) != null && game.GetPiece(k, j) == null) {
                            if (level < MAXLEVEL - 1)
                                tempVal = GoDeeper(game, i, j, k, j, level, mostValuable);
                            else
                                tempVal = EvaluateMove(game, i, j, k, j, level);

                            if (tempVal != -DONE && tempVal >= mostValuable) {
                                mostValuable = tempVal;
                                bestMove[0] = i;
                                bestMove[1] = j;
                                bestMove[2] = k;
                                bestMove[3] = j;
                            }
                        }
                    for (int l = 0; l < 8; l++)
                        if (game.GetPiece(i, j) != null && game.GetPiece(i, l) == null) {
                            if (level < MAXLEVEL - 1)
                                tempVal = GoDeeper(game, i, j, i, l, level, mostValuable);
                            else
                                tempVal = EvaluateMove(game, i, j, i, l, level);

                            if (tempVal != -DONE && tempVal >= mostValuable) {
                                mostValuable = tempVal;
                                bestMove[0] = i;
                                bestMove[1] = j;
                                bestMove[2] = i;
                                bestMove[3] = l;
                            }
                        }
                }
                        /*
                        for (int l = 0; l < 8; l++) {
                            if ((i == k || j == l) && (game.GetPiece(i, j) != null && game.GetPiece(k, l) ==  null))
                            {
                                if (level < MAXLEVEL - 1)
                                    tempVal = GoDeeper(game, i, j, k, l, level, mostValuable);
                                else
                                    tempVal = EvaluateMove(game, i, j, k, l, level);

                                if (tempVal != -DONE && tempVal >= mostValuable)
                                {
                                    mostValuable = tempVal;
                                    bestMove[0] = i;
                                    bestMove[1] = j;
                                    bestMove[2] = k;
                                    bestMove[3] = l;
                                }
                            }
                        }*/

            // Debug
            //if(level == 0)
            //    System.Windows.Forms.MessageBox.Show(mostValuable + "");

            return bestMove;
        }
Ejemplo n.º 2
0
        // Gets a board an evaluates it.
        private static int EvaluateBoard(Board turn)
        {
            int value = 0;
            int playerColour = turn.GetPlayerColour();

            for (int i = 0; i < 8; i++)
                for (int j = 0; j < 8; j++)
                    if (turn.GetPiece(i, j) != null) {
                        if (turn.GetPiece(i, j).GetColour() == playerColour)
                            value--;
                        else
                            value++;
                        if (turn.GetPiece(i, j).IsDux()) {
                            if (turn.GetPiece(i, j).GetColour() == playerColour)
                                if (turn.IsDuxStuck(i, j))
                                    value += 9001;
                            if (turn.GetPiece(i, j).GetColour() == playerColour * -1)
                                if (turn.IsDuxStuck(i, j))
                                    value -= 1337;
                        }
                    }

            return value;
        }