Bingo

  1. Let's consider the 75-ball American version of Bingo.
  2. At the beginning of the game, each player is given a Bingo card which contain 25 squares arranged in five vertical columns and five rows. Each space in the grid contains a number.
  3. The five columns of the card are labeled 'B', 'I', 'N', 'G', and 'O' from left to right. The range of numbers that can appear on the card is normally restricted by column, with the 'B' column only containing numbers between 1 and 15 inclusive, the 'I' column containing only 16 through 30, 'N' containing 31 through 45, 'G' containing 46 through 60, and 'O' containing 61 through 75.
  4. A player wins by completing three straight lines in a row, column, or diagonal.
  5. Write a program which randomly generate 25 numbers and show them on the screen.
  6. Then the user manually inputs an integer. After an integer is input, the program check whether it is on the Bingo card. If so, show the integer with background color yellow.
  7. Repeat the previous step until the user completes 3 straight lines in a row, column, or diagonal.
  8. The main program "bingo1-main.cpp" is given, and cannot be modified:
    #include <cstdlib>
    #include <ctime>
    #include <curses.h>
    
    #include "bingo1.h"
    
    int main() {
        Number card[BOARD_WIDTH][BOARD_WIDTH];
        int line;
        int x;
    
        initscr();
        start_color();
        init_pair(1, COLOR_BLACK, COLOR_YELLOW);
    
        time_t t = time(NULL);
        srand(t);
        initCard(card);
        while (true) {
            line = showCard(card);
            if (line >= LINE_THRESHOLD)
                break;
            x = getNumber();
            check(card, x);
        }
    
        showMessage("Bingo!");
        getch();
        endwin();
        return 0;
    }
  9. This is the header file "bingo1.h" where the function prototypes are specified:
    #define BOARD_WIDTH     5
    #define LINE_THRESHOLD  3
    #define MAX_NUMBER      75
    
    struct Number {
        int value;
        bool match;
    };
    
    void initCard(Number card[][BOARD_WIDTH]);
    int showCard(Number card[][BOARD_WIDTH]);
    int getNumber();
    void showMessage(char* s);
    void check(Number card[][BOARD_WIDTH], int x);
    
  10. Your work is to develop "bingo1.cpp" which contains the implementation of the 5 functions:
    1. initCard()
    2. showCard()
    3. getNumber()
    4. showMessage()
    5. check()
  11. After your code is ready, you should be able to compile these files into an executable program with:
    1. g++ -c bingo1-main.cpp
    2. g++ -c bingo1.cpp
      • The compiler may warn that "deprecated conversion from string constant". Please feel safe to ignore it.
    3. g++ bingo1-main.o bingo1.o -lcurses -o bingo1.exe
    4. ./bingo1.exe

    Bingo