C语言/C++求五子棋的程序代码和流程图还有模块设计,求求求,三者都要有~~~求大神帮忙。

作者&投稿:荤香 (若有异议请与网页底部的电邮联系)
求助高手!用C语言编写一个五子棋的代码要有流程图~

给我邮箱,我给你发个去。
你怎么提问两次??

可以不是“黑方用箭头键和回车键操作下子。白方用WASD四个键和空格键控制下子”而是用鼠标点击进行操作吗?用QT写的。

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#define TEXTS 7
#define CURSOR 48
#define CHESSBOARD 352
#define WHITECHESS 103
#define SELECTEDWHITE 55
#define BLACKCHESS 96
#define SELECTEDBLACK 48
#define qx1_num 27
#define qx2_num 26
typedef struct node
{
int step;
int color;
} NODE;
typedef struct point
{
int x;
int y;
}_POINT;
typedef struct qixing
{
char qx[8];
int value;
}QIXING;
HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
_POINT cursor;
int direction[8][2]={{0,-1},{0,1},{-1,0},{1,0},{-1,-1},{1,1},{-1,1},{1,-1}};
QIXING qx1[qx1_num]={{"x1111",200000},{"1x111",200000},{"11x11",200000},{"0x1110",6000},{"01x110",6000},{"101x101",6000},
{"0x111",1100},{"x0111",1100},{"0x1011",1100},{"0x1101",1100},{"01x11",1100},
{"011x1",1100},{"1x011",1100},{"10x11",1100},{"11x01",1100},{"1x101",1100},
{"x011102",250},{"0x110",250},{"01x10",250},{"0x01102",240},{"0x101",240},
{"0x112",20},{"01x12",10},{"011x2",20},{"1x12",10},{"0x10",20},{"0x010",5}};
QIXING qx2[qx2_num]={{"x1111",2000000},{"1x111",2000000},{"11x11",2000000},{"0x1110",24000},{"01x110",24000},{"101x101",24000},
{"0x111",2000},{"x0111",1900},{"0x1011",1900},{"0x1101",2000},{"01x11",2000},
{"011x1",2000},{"1x011",1900},{"10x11",2000},{"1x101",2000},{"x01112",2000},
{"0x110",850},{"01x10",850},{"0x0110",840},{"0x101",840},
{"0x112",125},{"01x12",125},{"011x2",115},{"1x12",115},{"0x10",125},{"0x010",110}};
//------------------------------------------------------------------------------------------------------
void textcolor(int color)
{
SetConsoleTextAttribute(hOutput, color);
}
void gotoxy(int x, int y)
{
COORD coordScreen={0,0};
coordScreen.X=x;
coordScreen.Y=y;
SetConsoleCursorPosition(hOutput,coordScreen);
}
void printnode(NODE chessboard[][15], int x, int y)
{
textcolor(CHESSBOARD);
if(chessboard[x][y].step==0)
{
if(x==cursor.x&&y==cursor.y)
textcolor(CURSOR);
switch(x)
{
case 0:
if(y==0)printf("┏");
else if(y==14)printf("┓");
else printf("┳");
break;
case 3:
if(y==0)printf("┣");
else if(y==3||y==11)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 7:
if(y==0)printf("┣");
else if(y==7)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 11:
if(y==0)printf("┣");
else if(y==3||y==11)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 14:
if(y==0)printf("┗");
else if(y==14)printf("┛");
else printf("┻");
break;
default:
if(y==0)printf("┣");
else if(y==14)printf("┫");
else printf("╋");
}
}
else if(chessboard[x][y].color==0)
{
if(x==cursor.x&&y==cursor.y)
textcolor(SELECTEDWHITE);
else textcolor(WHITECHESS);
printf("●");
}
else
{
if(x==cursor.x&&y==cursor.y)
textcolor(SELECTEDBLACK);
else textcolor(BLACKCHESS);
printf("●");
}
}
void printchessboard(NODE chessboard[][15])
{
int i,j;
char letter[]={" A B C D E F G H I J K L M N O\n"};
for(i=0;i<15;i++)
{
textcolor(TEXTS);
printf("%2d",15-i);
for(j=0;j<15;j++)
printnode(chessboard,i,j);
textcolor(TEXTS);
printf("\n");
}
textcolor(TEXTS);
printf("%s",letter);
printf("移动:方向键 下棋:ENTER 悔棋:U 退出:F12");
}
void renew(NODE chessboard[][15],int x,int y)
{
COORD coordScreen;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(x<0||x>14||y<0||y>14)
return;
if(!GetConsoleScreenBufferInfo(hOutput,&csbi))
return;
coordScreen=csbi.dwCursorPosition;
gotoxy((y-1)*2+4,x+1);
printnode(chessboard,x,y);
SetConsoleCursorPosition(hOutput,coordScreen);
}
void showmenu()
{
textcolor(TEXTS);
system("cls");
printf("1.人机对战\n2.双人对战\n3.退出\n\n请选择[1~3]:");
}
void showsubmenu()
{
textcolor(TEXTS);
system("cls");
printf("1.你先手\n2.电脑先手\n3.返回上级菜单\n\n请选择[1~3]:");
}
int getchoose(int min, int max)
{
int choose;
do
{
choose=getch()-48;
}while(choose<min||choose>max);
printf("%d",choose);
return choose;
}
//-------------------------------------------------------------------------------------------------
bool quit;
bool regret;
bool getmove(NODE chessboard[][15])
{
char c;
for(;;)
{
c=getch();
if(c==-32)
switch(getch())
{
case 72:
cursor.x--;
if(cursor.x<0)cursor.x=0;
renew(chessboard,cursor.x+1,cursor.y);
renew(chessboard,cursor.x,cursor.y);
break;
case 80:
cursor.x++;
if(cursor.x>14)
cursor.x=14;
renew(chessboard,cursor.x-1,cursor.y);
renew(chessboard,cursor.x,cursor.y);
break;
case 75:
cursor.y--;
if(cursor.y<0)cursor.y=0;
renew(chessboard,cursor.x,cursor.y+1);
renew(chessboard,cursor.x,cursor.y);
break;
case 77:
cursor.y++;
if(cursor.y>14)cursor.y=14;
renew(chessboard,cursor.x,cursor.y-1);
renew(chessboard,cursor.x,cursor.y);
break;
case 134:
quit=true;
return true;
}
else if(c==13&&chessboard[cursor.x][cursor.y].step==0)
return true;
else if(c=='U'||c=='u')
{
regret=true;
return true;
}
}
}
void beback(NODE chessboard[][15], int step)
{
int i,j,tempx,tempy;
if(step==1)return;
if(step>2)
{
for(i=0;i<15;i++)
for(j=0;j<15;j++)
{
if(chessboard[i][j].step==step-1)
{
chessboard[i][j].step=0;
renew(chessboard,i,j);
}
else if(chessboard[i][j].step==step-2)
{
chessboard[i][j].step=0;
tempx=cursor.x;
tempy=cursor.y;
cursor.x=i;
cursor.y=j;
renew(chessboard,i,j);
renew(chessboard,tempx,tempy);
}
}
}
else if(step==2)
{
for(i=0;i<15;i++)
for(j=0;j<15;j++)
if(chessboard[i][j].step==step-1)
{
chessboard[i][j].step=0;
renew(chessboard,i,j);
}
tempx=cursor.x;
tempy=cursor.y;
cursor.x=7;
cursor.y=7;
renew(chessboard,i,j);
renew(chessboard,tempx,tempy);
}
}
//-----------------------------------------------------------------------------------------
bool inside(int x,int y)
{
if(x<0||x>14||y<0||y>14)return false;
return true;
}
int line(NODE chessboard[][15],int dirt,int x,int y,int color)
{
int i;
for(i=0;chessboard[x+direction[dirt][0]][y+direction[dirt][1]].step>0&&
chessboard[x+direction[dirt][0]][y+direction[dirt][1]].color==color;i++)
{
x=x+direction[dirt][0];
y=y+direction[dirt][1];
if(!inside(x,y))return i;
}
return i;
}
bool win(NODE chessboard[][15],int x,int y,int color)
{
if(line(chessboard,0,x,y,color)+line(chessboard,1,x,y,color)>3)
return true;
if(line(chessboard,2,x,y,color)+line(chessboard,3,x,y,color)>3)
return true;
if(line(chessboard,4,x,y,color)+line(chessboard,5,x,y,color)>3)
return true;
if(line(chessboard,6,x,y,color)+line(chessboard,7,x,y,color)>3)
return true;
return false;
}
//----------------------------------------------------------------------------------------------
int attacktrend,defenttrend;
bool macth1(NODE chessboard[][15],int x,int y,int dirt,int kind,int color)
{
int k;
char c;
char *p;
p=strchr(qx1[kind].qx,'x');
for(k=0;k<=p-qx1[kind].qx;k++)
{
x-=direction[dirt][0];
y-=direction[dirt][1];
}
for(k=0;(unsigned)k<strlen(qx1[kind].qx);k++)
{
x+=direction[dirt][0];
y+=direction[dirt][1];
if(!inside(x,y))return(false);
if(chessboard[x][y].step>0&&chessboard[x][y].color==color)c='2';
else if(chessboard[x][y].step>0)c='1';
else c='0';
if(c=='0'&&qx1[kind].qx[k]=='x')continue;
if(c!=qx1[kind].qx[k])return(false);
}
return true;
}
int value_qx1(NODE chessboard[][15],int x,int y,int dirt, int color)
{
int i;
for(i=0;i<qx1_num;i++)
if(macth1(chessboard,x,y,dirt,i,color))
return qx1[i].value;
return 0;
}
bool macth2(NODE chessboard[][15],int x,int y,int dirt, int kind,int color)
{
int k;
char c;
char *p;
p=strchr(qx2[kind].qx,'x');
for(k=0;k<=p-qx2[kind].qx;k++)
{
x-=direction[dirt][0];
y-=direction[dirt][1];
}
for(k=0;(unsigned)k<strlen(qx2[kind].qx);k++)
{
x+=direction[dirt][0];
y+=direction[dirt][1];
if(!inside(x,y))return false;
if(chessboard[x][y].step>0&&chessboard[x][y].color==color)c='2';
else if(chessboard[x][y].step>0)c='1';
else c='0';
if(c=='0'&&qx2[kind].qx[k]=='x')continue;
if(c!=qx2[kind].qx[k])return(false);
}
return true;
}
int value_qx2(NODE chessboard[][15],int x,int y,int dirt, int color)
{
int i;
for(i=0;i<qx2_num;i++)
if(macth2(chessboard,x,y,dirt,i,color))
return qx2[i].value;
return 0;
}
void AI(NODE chessboard[][15], int *x,int *y,int color)
{
int max=0;
int maxi,maxj;
int i,j,k;
int probability=1;
int value[15][15]={0};
int valueattack[15][15]={{0}};
int valuedefent[15][15]={{0}};
for(i=0;i<15;i++)
for(j=0;j<15;j++)
{
if(chessboard[i][j].step>0)continue;
for(k=0;k<8;k++)
valuedefent[i][j]+=value_qx1(chessboard,i,j,k,color);
if(maxi<valuedefent[i][j])
maxi=valuedefent[i][j];
}
for(i=0;i<15;i++)
for(j=0;j<15;j++)
{
if(chessboard[i][j].step>0)continue;
for(k=0;k<8;k++)
valueattack[i][j]+=value_qx2(chessboard,i,j,k,color);
if(maxj<valuedefent[i][j])
maxj=valuedefent[i][j];
}
if(rand()%(maxi+maxj+1)>maxi)
{
attacktrend=1;
defenttrend=1;
}
else
{
attacktrend=1;
defenttrend=2;
}
for(i=0;i<15;i++)
for(j=0;j<15;j++)
{
value[i][j]=valuedefent[i][j]*defenttrend+valueattack[i][j]*attacktrend;
if(max<value[i][j])
{
max=value[i][j];
maxi=i;
maxj=j;
probability=1;
}
else if(max==value[i][j])
{
if(rand()%(probability+1)<probability)
probability++;
else
{
probability=1;
max=value[i][j];
maxi=i;
maxj=j;
}
}
}
*x=maxi;
*y=maxj;
}
//-------------------------------------------------------------------------------------------------
bool vshuman;
void Vs(bool human)
{
int i,j;
int color=1;
int lastx,lasty;
int computer;
NODE chessboard[15][15]={{0,0}};
if(!human)
{
showsubmenu();
switch(getchoose(1,3))
{
case 1:
computer=0;
attacktrend=1;
defenttrend=1;
break;
case 2:
computer=1;
attacktrend=1;
defenttrend=2;
break;
case 3:return;
}
}
for(i=0;i<15;i++)
for(j=0;j<15;j++)
chessboard[i][j].step=0;
cursor.x=7;
cursor.y=7;
quit=false;
system("cls");
printf("\n");
printchessboard(chessboard);
for(i=1;i<=225;)
{
gotoxy(0,0);
textcolor(TEXTS);
printf(" 第%03d手, ",i);
if(color==1)printf("黑棋下");
else printf("白棋下");
regret=false;
if(i>1)
{
if(color!=computer||human)getmove(chessboard);
else
{
lastx=cursor.x;
lasty=cursor.y;
AI(chessboard,&cursor.x,&cursor.y,color);
renew(chessboard,lastx,lasty);
}
}
if(quit)return;
if(regret)
{
beback(chessboard,i);
if(i>2)i-=2;
else if(i==2)
{
i=1; color=(color+1)%2;
}
}
else
{
chessboard[cursor.x][cursor.y].step=i++;
chessboard[cursor.x][cursor.y].color=color;
renew(chessboard,cursor.x,cursor.y);
color=(color+1)%2;
}
if(win(chessboard,cursor.x,cursor.y,(color+1)%2)&&!regret)
{
textcolor(TEXTS);
gotoxy(0,0);
printf(" ");
gotoxy(0,0);
if(color==1)printf(" 白棋赢了!");
else printf(" 黑棋赢了!");
getch();
return;
}
}
gotoxy(0,0);
printf(" ");
gotoxy(0,0);
printf(" 平局!");
}
int main()
{
srand((unsigned)time(NULL));
for(;;)
{
showmenu();
switch(getchoose(1,3))
{
case 1:Vs(false);break;
case 2:Vs(true);break;
case 3:printf("\n");return 0;
}
}
return 0;
}

我也正在写,流程图这不好发,还是自己写比较好,思路和关键点的话,你如果需要,我可以给你


“语言”用英文怎么写
language 读音:英 ['læŋɡwɪdʒ] 美 ['læŋɡwɪdʒ]1、 language泛指“语言”时是不可数名词,在句中可用作定语。language用来表示一个国家或民族具体的“语言文字”时,是可数名词,其前要加the。language与the连用还可表示“某种语言的全部词...

语言英语怎么写
语言英语翻译为:language。language:n.语言;语言文字;言语;说话;某种类型的言语(或语言);复数: languages

什么是语言 语言是什么
汉语、英语、西班牙语、俄语、阿拉伯语、法语是世界上的主要语言,也是联合国的工作语言。汉语是全球母语人口最多的语言,英语是全球使用最广泛的语言。语言和文字是两个概念,往往是先有语言,后产生文字。2、语言的三要素是语音、语法和词汇,是由词汇按一定的语法所构成的语音表义系统。根据语言的要素...

语言是什么
语言(人类进行沟通交流的各种表达符号)[yǔ yán]语言是人类最重要的交际工具,是人们进行沟通交流的各种表达符号。人们借助语言保存和传递人类文明的成果。语言是民族的重要特征之一。一般来说,各个民族都有自己的语言。汉语,英语,法语,俄语,西班牙语,阿拉伯语,是世界上的主要语言,也是联合国的工作...

什么是语言?
语言是思维工具和交际工具,它同思维有密切的联系,是思维的载体和物质外壳以及表现形式。语言是指令系统,是以声音\/符号为物质外壳,以语义内涵为意义内容的,指令、含义结合的词汇建筑材料和语法组织规律的体系。语言是一种社会现象,是人类最重要的交际工具,是进行思维逻辑运用和信息交互\/传递的工具,是...

语言的功能有哪些?
1.认知功能。即语言是人类认知世界的工具,借助语言我们才能了解世界、获取新知识。认知功能联通了语言和思维。2.交流功能。人与人之间的交流通常借助语言才能完成,我们将脑海中的形象转化为语言进行表达,再将接收到的他人的语言在脑海中转化为形象加以理解。3.情感功能。语言可以传递情感、表达我们对客观...

什么是语言?
语言(英文名:Language)是人类最重要的交际工具,是人们进行沟通的主要表达方式。人们借助语言保存和传递人类文明的成果。语言是民族的重要特征之一。一般来说,各个民族都有自己的语言。汉语,法语,俄语,西班牙语,阿拉伯语,英语是世界上的主要语言,也是联合国的工作语言。汉语是世界上使用人口最多的...

言语和语言的区别和联系
言语和语言的区别是言语是个人的,语言是社会的;言语是具体的,语言是抽象的;言语是有阶级性的,语言是全民性的。言语和语言的联系是语言制约着言语,指导人们进行言语实践;语言存在于言语行为和言语作品之中;语言不能够脱离言语,言语也不能脱离语言。语言是符号系统,是以语音为物质外壳,以语义为...

语言的主要特点有哪些
语言的主要特点有任意性、社会性、创新性、文化性、系统性、变异性。1、任意性:语言符号与其代表的现实世界事物之间并没有必然的联系。比如“猫”这个词并没有任何特性让它与小型四足动物之间存在自然的链接。这是语言的约定俗成。2、社会性:语言是一个社会现象。它不仅在社会生活中起着重要的交流作用...

言语和语言的区别
1、概念不同:语言是一种抽象的、全民的、有限的、静态的系统,它是社会成员共享的知识体系,包括了词汇、语法和发音等规则。而言语则是具体的、个人的、无限的、动态的现象,它是人们在特定情境下使用的语言,包括了口头和书面等形式的表达。2、应用不同:语言是社会的产物,它不从属于某一个人,...

岢岚县15151113239: 谁能帮我用C语言做一个五子棋的程序,,我有一个C++版本的 -
夕刘达力: #include <stdio.h>#define N 20int p[N][N]; int t, len; int lastx, lasty;void draw(void); void chess(void); int haswin(void);int main(void) {int n; memset(p, 0, N*N); printf("请问您想玩几子棋?(0~20):");do{scanf("%d", &t);if(t > N || t < ...

岢岚县15151113239: 急求一个五子棋C++程序 -
夕刘达力: 以下代码经测试能在vc++6.0运行 以下是代码的开始-----------------------------------------------------------------#include<iostream>#include<cstdlib> using namespace std; const char outstr[11][4]={"┌","┬","┐","├","┼","┤","└","┴","...

岢岚县15151113239: 用C++怎么编五子棋游戏的程序?
夕刘达力: #define CROSSRU 0xbf /*右上角点*/ #define CROSSLU 0xda /*左上角点*/ #define CROSSLD 0xc0 /*左下角点*/ #define CROSSRD 0xd9 /*右下角点*/ #define CROSSL 0xc3 /*左边*/ #define CROSSR 0xb4 /*右边*/ #define CROSSU 0xc2 /*上边*/ #define CROSSD 0xc1 /*下边*/ #define CROSS 0xc5 /*十字交叉点*/

岢岚县15151113239: 求C++五子棋游戏的程序
夕刘达力: #include "types.h" #include "mouse.h" #include "shell.h" #include "luffar.h" int main(void) { InitMouse(); InitGraphics(); DrawBackground(); SetPoint(1,1); // L刧ger musen p?punkten 1,1. ShowPoint(); BOOL bWantToExit = FALSE; ...

岢岚县15151113239: 用c++写五子棋游戏的程序
夕刘达力: /************************************************************************************ 五子棋,双人对战,界面简易,主要函数是判断胜负函数************************************************************************************/#include<iostream>//#include"data.h"...

岢岚县15151113239: 求一个C++例子 -
夕刘达力: 用C语言写的五子棋#include #include #include #include #include #define CROSSRU 0xbf /*右上角点*/#define...

岢岚县15151113239: 求C语言编写的五子棋程序. -
夕刘达力: #include #include #include #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b #define SPACE 0x3920 #define BILI 20 #define JZ 4 #define JS 3 #define N 19 int box[N][N]; int step_x,...

岢岚县15151113239: 编写一个五子棋的游戏程序(数据结构(C语言版)), -
夕刘达力: 仅仅用C语言估计很难实现,要是用C++的话就简单很多了,当然你可以考虑用C++做界面,然后用C语言实现相应的功能,C++对C是兼容的.

岢岚县15151113239: 我们想用C++ Builder写一个五子棋小游戏的程序,不知道怎么写,求指教, -
夕刘达力: 第一步,不考虑AI的情况下,先简单实现 单人 点击落子,点一次换一次黑白,落一次子判断一次输赢.第二步,加入socket通信两个人互落子.实现开局,落子,判断输赢,悔棋,认输,重新开局基本操作.第三步,加入AI,人机对战.

岢岚县15151113239: 求C语言编写的五子棋程序.
夕刘达力: #includeamp;lt;stdio.hamp;gt;nbsp;#includeamp;lt;stdlib.hamp;gt;nbsp;#includeamp;lt;graphics.hamp;gt;nbsp;#includeamp;lt;bios.hamp;gt;nbsp;#includeamp;lt;conio.hamp;gt;nbsp;#definenbsp;LEFTnbsp;0x4b00nbsp;#definenbsp;RIGHTnbsp;0x4d...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网