Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write minesweeping code in C language

Shulou Source: shulou.com Published: 2022-06-01 01:21:52 11月16日 Update

This article mainly introduces the relevant knowledge of how to write mine clearance code in C language, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this C language to realize how to write mine clearance code. let's take a look.

Minesweeping OvO0 is realized by C language. Print menu void menu () {printf ("* *\ n"); printf ("* 1. Play *\ n"); printf ("* 0. Exit *\ n "); printf (" * *\ n ");} 1. Initialize the chessboard

Before initializing the chessboard, we set the chessboard size to 9 × 9

But that doesn't mean we have to create a 9 × 9 two-dimensional array.

Since we are going to use coordinates for demining, we have to print line numbers and column numbers.

We are going to set up two arrays, one to store the number of mines around each location, and one to print a real-time chessboard.

Void initial (char board [ROWS] [COLS], int rows, int cols, char c) {for (int I = 0; I < rows; iTunes +) {for (int j = 0; j < cols; jacks +) {board [I] [j] = c;}

We use the initialization function above to initialize the array.

/ / initialize the information disk to'0' initial (mine, ROWS, COLS,'0'); / / initialize the mineplate to'* 'and mine mine against' * 'when demining / / isn't it a mystery to initial (show, ROWS, COLS,' *'); 2. Print chessboard

We print the chessboard with two for loops.

Void display (char board [ROWS] [COLS], int row, int col) {for (int I = 0; I = 1 & & x = 1 & & y

Tags: Chessboard input code minesweeping language coordinates number information array line number victory function knowledge error jungle regret two content mystery article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Information Microsoft NVidia