Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language to realize simple Gobang game

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report