Match-3 Board

  • Full Source code
  • Given 2 variables: COUNT_ROWS and COUNT_COLUMNS, COUNT_ROWS represents the amount of rows and COUNT_COLUMNS represents the amount of columns of our board.

    1. Print a log containing the row and column index of every tile.

    Click to expand code snippet
                							
    for (int row = 0; row < COUNT_ROWS; row++) {
        for (int column = 0; column < COUNT_COLUMNS; column++) {
    	Console.WriteLine("Tile row = {0}, column = {1}", row, column); 
        }
    }
                							
            							

    2. Randomly select 5 tiles in the first column that we will consider as "Blocked" tiles that aren't interactive. Print the row index of every tile blocked. Note: duplicate random results are allowed.

    Click to expand code snippet
                							
    Random random = new Random();
    int randomRow = 0;											
    for (int index = 0; index < 5; index++) {
        randomRow = random.Next(0, COUNT_ROWS);
        Console.WriteLine("Blocked row = {0} in the first column", randomRow);
    }
                							
            							

    3. Same question as before but make sure the 5 random rows are unique - without any duplications

    Click to expand code snippet
                							
    Random random = new Random();
    int[] blockedRows = new int[5];
    int count = 0;
    
    while (count < 5) {
        int randomRow = random.Next(0, COUNT_ROWS);
        bool isDuplicate = false;
    
        // Check if the number already exists in the array
        for (int i = 0; i < count; i++) {
            if (blockedRows[i] == randomRow) {
                isDuplicate = true;
                break;
            }
        }
    
        // If it's not a duplicate, add it and increment the count
        if (!isDuplicate) {
            blockedRows[count] = randomRow;
            Console.WriteLine("Blocked row = {0} in the first column", randomRow);
            count++;
        }
    }
                							
            							

    Loops - TBD

    Loops - TBD