Exemplo n.º 1
0
    public static int GetBlackHoleRatio(Board board, PieceEnum player)
    {
        int       myPieces   = 0;
        int       opPieces   = 0;
        PieceEnum opponent   = player.GetOpponent();
        int       blackHoleX = board.blackHoleCoords[0];
        int       blackHoleY = board.blackHoleCoords[1];

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                if (board.board[blackHoleY + i, blackHoleX + j] == player)
                {
                    myPieces++;
                }
                if (board.board[blackHoleY + i, blackHoleX + j] == opponent)
                {
                    opPieces++;
                }
            }
        }

        int result = 100 * (myPieces - opPieces) / (myPieces + opPieces + 1);

        return(result);
    }
Exemplo n.º 2
0
    private int[] GetSuccesfulMoveInDirection(int[] boardSquareCoordinates, int dirX, int dirY, PieceEnum currentPlayer)
    {
        PieceEnum opponent           = currentPlayer.GetOpponent();
        int       hasBeatableEnemies = 0;
        int       tempY = boardSquareCoordinates[0];
        int       tempX = boardSquareCoordinates[1];

        //move to next checked square
        tempX += dirX;
        tempY += dirY;
        while (IsInRange(tempY) && IsInRange(tempX))  //while inside board borders
        {
            if (this.board[tempX, tempY] == opponent) //found opponent
            {
                hasBeatableEnemies = 1;
            }
            else if (hasBeatableEnemies == 1 && this.board[tempX, tempY] == PieceEnum.none)//there are beatable opponents
            {
                return(new int[] { 1, tempY, tempX, dirX, dirY });
            }
            else if (this.board[tempX, tempY] != opponent)//found no enemies, reached dead end
            {
                break;
            }
            tempX += dirX;
            tempY += dirY;
        }
        return(new int[] { 0, tempY, tempX, dirX, dirY });//no beatable enemies found
    }
Exemplo n.º 3
0
    //LEGACY functions
    public static int GetMobility(Board board, PieceEnum player)
    {
        int currentPlayerMovesLength = board.GetValidMovesList(player).Length;
        int opponentMovesLength      = board.GetValidMovesList(player.GetOpponent()).Length;

        int result = currentPlayerMovesLength - opponentMovesLength;

        return(result);
    }
Exemplo n.º 4
0
    public int ChangePieces(int coordX, int coordY, int x, int y, PieceEnum colorCurrent)
    {
        int changed = 0;

        int[] XYDirs = new int[] { coordX, coordY, x, y };
        //Console.WriteLine("{1} [{0}]", string.Join(", ", XYDirs), "XYDirs");
        board[coordY, coordX] = colorCurrent;
        while (board[coordY - x, coordX - y] == colorCurrent.GetOpponent())
        {
            coordX -= y;
            coordY -= x;
            board[coordY, coordX] = colorCurrent;
            changed++;
        }
        return(changed);
    }
Exemplo n.º 5
0
    public static int GetCornerRatio(Board board, PieceEnum player)
    {
        int       myCorners = 0;
        int       opCorners = 0;
        PieceEnum opponent  = player.GetOpponent();

        if (board.board[0, 0] == player)
        {
            myCorners++;
        }
        if (board.board[7, 0] == player)
        {
            myCorners++;
        }
        if (board.board[0, 7] == player)
        {
            myCorners++;
        }
        if (board.board[7, 7] == player)
        {
            myCorners++;
        }

        if (board.board[0, 0] == opponent)
        {
            opCorners++;
        }
        if (board.board[7, 0] == opponent)
        {
            opCorners++;
        }
        if (board.board[0, 7] == opponent)
        {
            opCorners++;
        }
        if (board.board[7, 7] == opponent)
        {
            opCorners++;
        }

        int result = 100 * (myCorners - opCorners) / (myCorners + opCorners + 1);

        return(result);
    }
Exemplo n.º 6
0
    public static int[] GetPieceCount(Board board, PieceEnum playerColor)
    {
        int       playerPieceCount   = 0;
        int       opponentPieceCount = 0;
        PieceEnum opponentColor      = playerColor.GetOpponent();

        for (int i = 0; i < board.boardLength; i++)
        {
            for (int j = 0; j < board.boardLength; j++)
            {
                if (board.board[i, j] == playerColor)
                {
                    playerPieceCount++;
                }
                else if (board.board[i, j] == opponentColor)
                {
                    opponentPieceCount++;
                }
            }
        }
        return(new int[] { playerPieceCount, opponentPieceCount });
    }