Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use C language to realize simple Gobang game

Shulou Source: shulou.com Published: 2022-06-02 15:30:59 10月02日 Update

This article mainly introduces "how to use C language to realize simple Gobang game". In daily operation, I believe that many people have doubts about how to use C language to realize simple Gobang game. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use C language to realize simple Gobang game". Next, please follow the editor to study!

1. Initialize the chessboard

Char ret; / / data is stored in a two-dimensional array, players go down *, computers go down #. Char board [row] [col] = {0}; / / start with all spaces InitBoard (board,row,col); / / initialize the chessboard

We use the InitBoard function to initialize the chessboard, using * to represent the player playing chess and # to represent the computer playing chess.

The code is shown below:

Void InitBoard (char board [row] [col], int Row, int Col) {int I = 0; int j = 0; for (I = 0; I < Row; iTunes +) {for (j = 0; j < Col; jacks +) {board [I] [j] =';}

two。 Print chessboard format

Char ret; / / data is stored in a two-dimensional array, players go down *, computers go down #. Char board [row] [col] = {0}; / / start with all spaces InitBoard (board,row,col); / / initialize chessboard DisplayBoard (board,row,col); / / print chessboard

Here we introduce the DispalyBoard function to print the chessboard format.

The code is as follows:

Void DisplayBoard (char board [row] [col], int Row, int Col) {int I, j; for (I = 0; I < Row; iTunes +) {for (j = 0; j < Col; jacks +) {printf ("% c", board [I] [j]); if (j < Col-1) printf ("|");} printf ("\ n"); for (j = 0; j < Col) Jake +) {if (I < Row-1) {printf ("- -");} if (j < Col-1&&i= 1levels & x = 1levels & y

Tags: Chessboard player computer function code input Gobang language Gobang data array space two-dimensional storage learning success format jobless five words next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Docker OPPO Reno vpn