当前位置:网站首页>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 .
边栏推荐
- WPF data binding (IV)
- 一、SQLServer2008安装(带密码)、创建数据库、C#窗体项目测试
- R语言并行计算实战教程
- SQL query. Only the column name is displayed but not the data
- Education expert Mr. wangzhongze: family education focuses on self growth
- Menu double linkage effect in uniapp
- [deploy private warehouse based on harbor] 2 machine preparation
- Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation
- .NET C#基础(6):命名空间 - 有名字的作用域
- [matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
猜你喜欢

WPF data binding (IV)

Listen to the left width of the browser to calculate the distance

byte和bit的区别

big.js--使用/实例

The gap between the parent box and the child box

生物序列智能分析平台blog(1)

Installation de SQL Server 2008 (avec mot de passe), création d'une base de données, test de projet de formulaire C

Drawing with qpainter

教育专家王中泽老师一招解决学生问题

VTK vtkplane and vtkcutter use
随机推荐
1300. the array closest to the target value after transforming the array and
【CF#697 (Div. 3)】 A - Odd Divisor
WPF data binding (IV)
河南高考VS天津高考(2008年-2021年)
Summary and review
[deploy private warehouse based on harbor] 2 machine preparation
matplotlib的cmap
@JsonProperty注解
Difference between byte and bit
Installation de SQL Server 2008 (avec mot de passe), création d'une base de données, test de projet de formulaire C
213. house raiding II
【LeetCode】-- 17.电话号码的字母组合
Bat (batch processing) processing special symbols (exclamation point, percent sign), etc
Leetcode-104. Maximum Depth of Binary Tree
Explain the difference between void 0 and undefined
农房一体脚本的心得记录
1、 Sqlserver2008 installation (with password), database creation, C form project test
Interview question 02.06 Palindrome linked list
1190. invert the substring between each pair of parentheses
Detailed explanation of mutationobserver