1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
const int NROWS = 4 ;
const int NCOLS = 3 ;
using board = int[NROWS][NCOLS] ;
void display_board( const board& brd )
{
for( const auto& row : brd )
{
for( int v : row )
{
if( v == 0 ) std::cout << " NULL " ;
else std::cout << std::setw(4) << v << " " ;
}
std::cout << '\n' ;
}
}
int display_random_board( const board brds[], int num_boards )
{
if( num_boards < 1 ) return num_boards ;
const int random_board_number = std::rand() % num_boards ;
std::cout << "board #" << random_board_number << "\n--------\n" ;
display_board( brds[random_board_number] ) ;
return random_board_number ;
}
void begin_game( board brds[], int num_boards )
{
[[maybe_unused]] const int chosen_board = display_random_board( brds, num_boards ) ;
// ...
}
int main()
{
std::srand( std::time(nullptr) ) ;
const int NBOARDS = 3 ;
board game_boards[NBOARDS] =
{ { 38, 11, 83, 15, 6, 33, 10, 2, 20, 86, 0, 95 }, // note: brace elision
{ 28, 10, 55, 89, 17, 98, 22, 4, 31, 60, 0, 78 },
{ 90, 9, 45, 66, 12, 48, 34, 7, 70, 44, 0, 26 }
};
begin_game( game_boards, NBOARDS ) ;
}
|