当前位置:网站首页>Mobile console Gobang (first draft of detailed design)
Mobile console Gobang (first draft of detailed design)
2022-06-11 07:12:00 【lihongtao8209】
1. Program code
/*1.vboard[x][y] x Represents an array row ,Y Represents an array column The index is based on 0 2. Lines entered in the console 、 Columns are based on 1 3. The program is in Huawei NOVA7 Development 、 debugging 4.C The compiler must support UTF-8 */
#include <stdio.h>
#define SIZE 15
#define HEI 0X48 //'H'
#define BAI 0X42 //'B'
#define BLK '0'
#define NUL 0
char *pos="┼";
char *black="●";
char *white="○";
int step=0;
int count=0;
int qizi[2]={
HEI,BAI};
int record[SIZE*SIZE]= {
-1}; // Record
char vboard[SIZE][SIZE+1];
int players[2];// Record who is black and who is white
// initialization ;
void init();
// Show chessboard
void showConsole();
// Show virtual checkerboard
void debugVboard();
// All at once
void inputStep();
// Chess piece record
void recordStep(int x,int y);
// Print chess piece records
void printRecord();
void setValue(int x,int y,int v);
// Take a move
int player(int wc);
// Take turns playing chess
void alternatePlay();
int main()
{
init();
initVboard();
alternatePlay();
/* setValue(15,15,HEI); setValue(14,15,BAI); showConsole(); */
//debugVboard();
//searchVboard();
return 0;
}
init()
{
count=0;
}
void showConsole()
{
char ind[16]="123456789ABCDEF\0";
char *ind2="ABCDEFGHIJKLMNO";
for(int i=0; i<SIZE; i++)
{
// Print left column index
printf("%c",ind[i]);
// Print chess pieces
for(int j=0; j<SIZE; j++)
{
if(vboard[i][j]=='*')
printf("%s ",pos);
else if(vboard[i][j]=='H')
printf("%s ",black);
else if(vboard[i][j]=='B')
printf("%s ",white);
else printf("%s ",pos);
}
printf("\n");
}
// Print the bottom row index
for(int k=0; k<SIZE; k++)
{
printf("%2c",*(ind2+k));
}
putchar('\n');
}
void initVboard()
{
for(int i=0; i<SIZE; i++)
{
for(int j=0; j<SIZE; j++)
{
vboard[i][j]='*';
}
vboard[i][SIZE]=0;
}
}
void debugVboard()
{
for(int i=0; i<SIZE; i++)
{
for(int j=0; j<SIZE; j++)
{
printf("%2c",vboard[i][j]);
}
putchar('\n');
}
}
// The index is based on 1
void setValue(int x,int y,int v)
{
vboard[x-1][y-1]=v;
}
void printRecord()
{
for(int i=0; i<SIZE; i++)
{
for(int j=0; j<SIZE; j++)
{
// Black chess
if(vboard[i][j]=='H')
{
printf("● ROW:%d COL:%d\n",i+1,j+1);
}
// White chess
if(vboard[i][j]=='B')
{
printf("○ ROW:%d COL:%d\n",i+1,j+1);
}
}
}
}
// Record... In a one-dimensional array 225 Step
void recordStep(int x,int y)
{
int i;
i=step;
if(i<225 && record[i]==-1)
{
record[i]=15*x+y;
printf("%d %d %d\n",step,record[i],__LINE__);
step++;
}
}
// All at once
void inputStep()
{
int whofirst=-1;
while(whofirst<0)
{
printf("1 Bai Xian ,2 Heixian , Please select :");
scanf("%d",whofirst);
}
switch(whofirst)
{
case 2:
{
// Default black first
players[0]=HEI;
players[1]=BAI;
break;
}
default:
{
players[0]=BAI;
players[1]=HEI;
}
}
}
// Black and white
int player(int wc)
{
int x,y;
printf("%d",count+1);
if(wc==HEI)
printf("%srow,column:",black);
else if(wc==BAI)
printf("%srow,column:",white);
else{
}
scanf("%d,%d",&x,&y);
getchar();
//printf("ascci=%d",c);
if((x>0&&x<=15)&&(y>0&&y<=15))
{
setValue(x,y,wc);
//recordStep(x,y);
return 0;
}
else
{
}
return 1;
}
// Take turns playing chess
void alternatePlay()
{
int flag=0;
int alter=0;
int heibai;
while(flag==0)
{
showConsole();
alter=count%2;
heibai=qizi[alter];
flag=player(heibai);
count++;
}
}
2. Console input
2.1 Enter black chess

First step , stay 15 That's ok 15 Column input black chess . The format is :15,15 enter .
2.2 Enter white

For example 14 That's ok 15 Column enter white . The format is :14,15 enter .
边栏推荐
- Atomicinteger atomic operation class
- Latex various arrows / arrows with text labels / variable length arrows
- Common troubleshooting tools and analysis artifacts are worth collecting
- Web API、DOM
- Luogu p1091 chorus formation (longest ascending subsequence)
- 【CF#697 (Div. 3)】 A - Odd Divisor
- P5431 [template] multiplicative inverse 2
- Shutter restraint container assembly
- 1269. number of options left in place
- P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
猜你喜欢

LEARNING TARGET-ORIENTED DUAL ATTENTION FOR ROBUST RGB-T TRACKING

Luogu p1091 chorus formation (longest ascending subsequence)

Nodejs database (Part 2)

webserver

Leetcode-141. Linked List Cycle

saltstack部署lnmp

Biological sequence intelligent analysis platform blog (1)
![[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen](/img/93/d1014b07c924195e062dc83d69b14a.png)
[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen

CMAP of Matplotlib

Analysis of key points and difficulties of ES6 promise source code
随机推荐
Leetcode-9.Palindrome Numbber
pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
Nodejs database (Part 2)
[deploy private warehouse based on harbor] 4 push image to harbor
554. brick wall
3.1 naming rules of test functions
【CF#388 (Div. 2)】A. Bachgold Problem
Common troubleshooting tools and analysis artifacts are worth collecting
12. integer to Roman numeral
Grayscale publishing through ingress
Dynamically change the direction of this
Bat (batch processing) processing special symbols (exclamation point, percent sign), etc
R语言并行计算实战教程
Quality-aware Feature Aggregation Networkfor Robust RGBT Tracking
mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):
@JsonProperty注解
一、SQLServer2008安装(带密码)、创建数据库、C#窗体项目测试
This comprehensive understanding
【LeetCode】-- 17.电话号码的字母组合
Mybags puls will report an error invalid bound statement (not found) when writing an SQL statement in the XML file: