IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> (C语言)人机对战五子棋(有可视化界面) -> 正文阅读

[C++知识库](C语言)人机对战五子棋(有可视化界面)

五子棋(用EasyX写的)
大一下的C语言的大作业
历时时间(不说了,反正好长)
下面是代码,(图片文件丢失了,如果有需要可以自己,加图片)
代码变量的命名不规范,结构有些杂糅,不过运行效果还不错
是用鼠标点击下五子棋
有人人对战还有
人机对战(算法不好,机器不太智能,能下过我)
能储存下棋数据将其存在文件中
能悔棋
编译器 vs2019
绘图插件 EasyX
下面是代码

部分图像
下棋界面

#define _CRT_SECURE_NO_WARNINGS
#include"graphics.h"
#include "conio.h"
#include"math.h"
#include"time.h"
#include"string.h"
#include"stdio.h"
#define  sp 36 
#define ps 30
#define  ti 400
#pragma comment(lib,"Winmm.lib" )
int gamesta = 0, high = 36, width = 36;
void show();
void gameover();
void pause();
void startmenu();
void win();
void lose();
void mode();
void judge();
void sense();
void huiqi();
void jiazai();
void xuan_ze();
void cunchu_fun();
int score(int row[], int x);
void reverse(int row[], int len);
int sense_row(int x, int y);
int sense_left_bias(int x, int y);
int sense_col(int x, int y);
int sense_right_bias(int x, int y);
int a[19][19] = { 0 };
int b[19][19] = { 0 };
int win_lose = 0;
int mod = 0;
int mo = 0;
int choice = 0;
int xian_hou = 0;
int hui_qi = 0;
int hui_qi_times = 3;
int q = 0, s = 0;
int k = 0;
char input;
struct position {
	int x;
	int y;
	int score;
};
struct position positions[361], mem1[181], mem2[180];
int position_order = 0;
int ji_lu = 0;
struct cunchu {
	int cixu = 0;
	int shun_win_lose = 0;
	int cv[19][19] = { 0 };
};
struct cunchu f[6], f_2[6];
void initial_positions(void)
{
	positions[0].x = positions[0].y = positions[0].score = 0;
	for (position_order = 1; position_order < 50; position_order++) {
		positions[position_order] = positions[0];
	}
	position_order = 0;
}
void jiazai()
{
	initgraph(900, 900);
	IMAGE img_jz;
	loadimage(&img_jz, _T("C:\\Users\\Lenovo
		\\Desktop\\五子棋\\jiazai.jpg"));
	putimage(0, 0, &img_jz);
	setbkmode(TRANSPARENT);
	settextstyle(100, 0, _T("黑体"));
	settextcolor(RED);
	outtextxy(300, 228, _T("五子棋"));
	solidroundrect(160, 600, 680, 660, ps, ps);
	for (int i = 190; i <= 680; i = i + 5) {
		settextstyle(60, 0, _T("黑体"));
		{
			setfillcolor(RGB(61, 241, 215));
			solidroundrect(300, 530, 540, 590, ps, ps);

			fillroundrect(300, 530, 540, 590, ps, ps);
		}
		{
			setfillcolor(RGB(143, 244, 249));
			outtextxy(330, 530, _T("加载中"));
			fillroundrect(160, 600, i, 660, ps, ps);
			setfillcolor(RGB(143, 244, 249));
			settextcolor(RED);
		}
		if (i == 680)
		{
			setfillcolor(RGB(61, 241, 215));
			solidroundrect(300, 530, 540, 590, ps, ps);
			fillroundrect(300, 530, 540, 590, ps, ps);
			outtextxy(300, 530, _T("加载成功"));
			Sleep(100);
		}
		else
			system("cls");
	}
	Sleep(100);
}
void startmenu()
{
	jiazai();
	initgraph(900, 900);
	IMAGE img_bk;
	loadimage(&img_bk, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\kaishi.jpg"));
	putimage(0, 0, &img_bk);
	setbkmode(TRANSPARENT);
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 228, 400, 288, ps, ps);
	solidroundrect(160, 228, 400, 288, ps, ps);
	fillroundrect(500, 228, 680, 288, ps, ps);
	solidroundrect(500, 228, 680, 288, ps, ps);
	settextstyle(60, 30, _T("黑体"));
	settextcolor(BLACK);
	outtextxy(160, 228, _T("1新游戏"));
	outtextxy(500, 228, _T("2 退出"));
	setfillcolor(RGB(202, 242, 104));
	fillroundrect(350, 360, 530, 420, ps, ps);
	solidroundrect(350, 360, 530, 420, ps, ps);
	outtextxy(350, 360, _T("3 回顾"));
	mciSendString(_T("open C:\\Users\\Lenovo\\Desktop\\五子棋\\bgm.mp3 alias bkm"), NULL, 0, NULL);
	mciSendString(_T("play bkm repeat"), NULL, 0, NULL);
	MOUSEMSG m;
	while (1) {
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (160 < m.x && m.x < 400 && m.y < 288 && 228 < m.y) {
				mode();
			}
			else if (m.x < 680 && 500 < m.x && m.y < 288 && 228 < m.y) {
				gameover();
			}
			else if (m.x < 530 && 350 < m.x && m.y < 420 && 360 < m.y)
			{
				cunchu_fun();
			}
		}
	}
}

void show()
{
	mciSendString(_T("close bkm"), NULL, 0, NULL);
	mciSendString(_T("open C:\\Users\\Lenovo\\Desktop\\五子棋\\kaishibgm.mp3 alias bdm"), NULL, 0, NULL);
	mciSendString(_T("play bdm repeat"), NULL, 0, NULL);
	IMAGE img_yx;
	loadimage(&img_yx, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\youxi.jpg"));
	putimage(0, 0, &img_yx);
	setlinestyle(PS_SOLID, 1);
	setfillcolor(RGB(253, 253, 233));
	solidrectangle(30, 30, 726, 726);
	setcolor(BLACK);
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(750, 228, 870, 288, ps, ps);
	solidroundrect(750, 228, 870, 288, ps, ps);
	fillroundrect(750, 298, 870, 478, ps, ps);
	solidroundrect(750, 298, 870, 478, ps, ps);
	settextstyle(60, 30, _T("黑体"));
	settextcolor(BLACK);
	outtextxy(750, 228, _T("悔棋"));
	settextcolor(RED);
	outtextxy(750, 298, _T("只能"));
	outtextxy(750, 358, _T("悔棋"));
	outtextxy(750, 418, _T("三次"));
	for (int i = 1; i <= 20; i++)
	{
		line(36, i * sp, 720, i * sp);
		line(i * sp, 36, i * sp, 720);
	}
	setlinestyle(PS_SOLID, 4);
	line(30, 30, 726, 30);
	line(30, 30, 30, 726);
	line(30, 726, 726, 726);
	line(726, 726, 726, 30);
	if (mo == 1) {
		memset(a, 0, sizeof(a));
		memset(mem1, 0, sizeof(mem1));
		memset(mem2, 0, sizeof(mem2));
		s = 0;
		q = 0;
		mo = 0;
		hui_qi_times = 3;
		win_lose = 0;
	}
	if (mod == 1) {
		for (int i = 1; i < 20; i++) {
			for (int j = 1; j < 20; j++) {
				if (b[i - 1][j - 1] == 1)
				{
					setcolor(BLACK);
					setfillcolor(BLACK);
					fillcircle(i * 36 + 18, j * 36 + 18, 14);
					circle(i * 36 + 18, j * 36 + 18, 14);
				}
				if (b[i - 1][j - 1] == 2)
				{
					setcolor(RGB(171, 171, 171));
					setfillcolor(RGB(171, 171, 171));
					fillcircle((i * 36 + 18), (j * 36 + 18), 14);
					circle((i * 36 + 18), (j * 36 + 18), 14);

				}
			}
		}
		mod = 0;
	}
	int z, l;
	MOUSEMSG m;
	while (1) {
		m = GetMouseMsg();
		z = (int)(m.x / 36) - 1;
		l = (int)(m.y / 36) - 1;
		if (m.uMsg == WM_LBUTTONDOWN && xian_hou == 0)
		{
			setcolor(BLACK);
			setfillcolor(BLACK);
			if (m.x < 720 && (36 < m.x) && (m.y < 720) && (36 < m.y)) {
				if (a[(int)(m.x / 36) - 1][(int)(m.y / 36) - 1] == 1 || a[(int)(m.x / 36) - 1][(int)(m.y / 36) - 1] == 2)
					continue;
				else {
					a[z][l] = 1;
					m.x = (m.x / 36) * 36 + 18;
					m.y = (m.y / 36) * 36 + 18;
					mem1[s].x = z;
					mem1[s].y = l;
					fillcircle(m.x, m.y, 14);
					circle(m.x, m.y, 14);
					s = s + 1;
					xian_hou = 1;
				}
			}
		}
		judge();
		memcpy(b, a, sizeof(a));
		if (m.x < 870 && (750 < m.x) && (m.y < 288) && (228 < m.y) && m.uMsg == WM_LBUTTONUP && hui_qi_times>0)
		{
			huiqi();
			show();
		}
		switch (choice)
		{
		case 1:
			if (m.uMsg == WM_RBUTTONDOWN && xian_hou == 1)
			{
				setcolor(RGB(171, 171, 171));
				setfillcolor(RGB(171, 171, 171));
				if (m.x < 720 && (36 < m.x) && (m.y < 720) && (36 < m.y)) {
					m.x = (m.x / 36) * 36 + 18;
					m.y = (m.y / 36) * 36 + 18;
					if (a[z][l] == 1 || a[z][l] == 2)
						continue;
					else {
						a[z][l] = 2;
						mem2[q].x = z;
						mem2[q].y = l;
						q = q + 1;
						fillcircle(m.x, m.y, 14);
						circle(m.x, m.y, 14);
						xian_hou = 0;
					}
				}
			}
			break;
		case 2:
			int g = 0, h = 0;
			if (xian_hou == 1) {
				sense();
				int max = 0, max_order = 0, i;
				for (i = 0; i < position_order; i++) {
					if (positions[i].score > max) {
						max = positions[i].score;
						max_order = i;
					}
				}
				a[positions[max_order].y][positions[max_order].x] = 2;
				h = positions[max_order].y;
				g = positions[max_order].x;
				setcolor(RGB(171, 171, 171));
				setfillcolor(RGB(171, 171, 171));
				mem2[q].x = h;
				mem2[q].y = g;
				q = q + 1;
				fillcircle((h + 1) * 36 + 18, (g + 1) * 36 + 18, 14);
				circle((h + 1) * 36 + 18, (g + 1) * 36 + 18, 14);
				xian_hou = 0;
			}
			break;
		}
		memcpy(b, a, sizeof(a));
		if (_kbhit()) {
			input = _getch();
			if (input == 27) {
				pause();
				break;
			}
		}
		judge();
	}
}
void huiqi()
{
	if (xian_hou == 0) {
		a[mem1[q - 1].x][mem1[q - 1].y] = 0;
		a[mem2[s - 1].x][mem2[s - 1].y] = 0;
		q = q - 1;
		s = s - 1;
	}
	if (xian_hou == 1) {
		a[mem1[q].x][mem1[q].y] = 0;
		a[mem2[s - 2].x][mem2[s - 2].y] = 0;
		q--;
		s--;
	}
	mod = 1;
	hui_qi_times = hui_qi_times - 1;
	memcpy(b, a, sizeof(a));
	show();
}
void pause() {
	mciSendString(_T("close bkm"), NULL, 0, NULL);
	mciSendString(_T("close bdm"), NULL, 0, NULL);
	system("cls");
	IMAGE img_st;
	loadimage(&img_st, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\pause.jpg"));
	putimage(0, 0, &img_st);
	setbkmode(TRANSPARENT);
	settextstyle(60, 0, _T("黑体"));
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 228, 340, 288, ps, ps);
	solidroundrect(160, 228, 340, 288, ps, ps);
	fillroundrect(500, 228, 680, 288, ps, ps);
	solidroundrect(500, 228, 680, 288, ps, ps);
	settextcolor(BLACK);
	outtextxy(160, 228, _T("1继续"));
	outtextxy(500, 228, _T("2退出"));
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 340 && 160 < m.x && m.y < 288 && 228 < m.y) {
				mod = 1;
				show();
			}
			else if (m.x < 640 && 500 < m.x && m.y < 288 && 228 < m.y) {
				gameover();
			}
		}
	}
}
void gameover()
{
	IMAGE img_js;
	loadimage(&img_js, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\jieshu.jpg"));
	putimage(0, 0, &img_js);
	setbkmode(TRANSPARENT);
	settextstyle(60, 35, _T("黑体"));
	settextcolor(RGB(232, 54, 40));
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 228, 340, 288, ps, ps);
	solidroundrect(160, 228, 340, 288, ps, ps);
	fillroundrect(500, 228, 680, 288, ps, ps);
	solidroundrect(500, 228, 680, 288, ps, ps);
	outtextxy(160, 228, _T("1分享"));
	outtextxy(500, 228, _T("2打赏"));
	MOUSEMSG m;
	while (1) {
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 340 && 160 < m.x && m.y < 288 && 228 < m.y) {
				IMAGE img_fx;
				loadimage(&img_fx, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\fenxiang.jpg"));
				putimage(0, 0, &img_fx);
				break;
			}
			else if (m.x < 680 && 500 < m.x && m.y < 288 && 228 < m.y) {
				IMAGE img_ds;
				loadimage(&img_ds, _T("C:\\dashang.jpg"));
				putimage(0, 0, &img_ds);
				break;
			}
		}
	}
	char a;
	a = _getch();
	closegraph();
}
void win()
{
	IMAGE img_w;
	loadimage(&img_w, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\win.jpg"));
	putimage(0, 0, &img_w);
	setbkmode(TRANSPARENT);
	settextstyle(60, 0, _T("黑体"));
	outtextxy(160, 228, _T("你赢了"));
	settextstyle(60, 30, _T("黑体"));
	settextcolor(BLACK);
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 360, 400, 420, ps, ps);
	solidroundrect(160, 360, 340, 420, ps, ps);
	fillroundrect(500, 360, 680, 420, ps, ps);
	solidroundrect(500, 360, 680, 420, ps, ps);
	outtextxy(160, 360, _T("1新游戏"));
	outtextxy(500, 360, _T("2 退出"));
	xian_hou = 0;
	setfillcolor(RGB(202, 242, 104));
	fillroundrect(350, 460, 530, 520, ps, ps);
	solidroundrect(350, 460, 530, 520, ps, ps);
	outtextxy(350, 460, _T("3 回顾"));
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 400 && 160 < m.x && m.y < 420 && 360 < m.y) {
				mo = 1;
				mod = 0;
				mode();
				break;
			}
			else if (m.x < 680 && 500 < m.x && m.y < 420 && 360 < m.y) {
				gameover();
			}
			else if (m.x < 530 && 350 < m.x && m.y < 520 && 460 < m.y)
			{
				mo = 1;
				mod = 0;
				cunchu_fun();
			}
		}
	}
}
void lose()
{
	IMAGE img_l;
	loadimage(&img_l, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\lose.jpg"));
	putimage(0, 0, &img_l);
	setbkmode(TRANSPARENT);
	settextcolor(RED);
	settextstyle(60, 0, _T("黑体"));
	outtextxy(160, 228, _T("你输了"));
	settextstyle(60, 30, _T("黑体"));
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 360, 400, 420, ps, ps);
	solidroundrect(160, 360, 400, 420, ps, ps);
	fillroundrect(500, 360, 680, 420, ps, ps);
	solidroundrect(500, 360, 680, 420, ps, ps);
	outtextxy(160, 360, _T("1新游戏"));
	outtextxy(500, 360, _T("2 退出"));
	xian_hou = 0;
	setfillcolor(RGB(202, 242, 104));
	fillroundrect(350, 460, 530, 520, ps, ps);
	solidroundrect(350, 460, 530, 520, ps, ps);
	outtextxy(350, 460, _T("3 回顾"));
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 400 && 160 < m.x && m.y < 420 && 360 < m.y) {
				mo = 1;
				mod = 0;
				mode();
			}
			else if (m.x < 680 && 500 < m.x && m.y < 420 && 360 < m.y) {
				gameover();
			}

			else if (m.x < 530 && 350 < m.x && m.y < 520 && 460 < m.y)
			{
				mo = 1;
				mod = 0;
				cunchu_fun();
			}
		}
	}
}
void mode()
{
	IMAGE img_m;
	loadimage(&img_m, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\mode.jpg"));
	putimage(0, 0, &img_m);
	setbkmode(TRANSPARENT);
	settextstyle(60, 0, _T("黑体"));
	settextstyle(60, 30, _T("黑体"));
	settextcolor(BLACK);
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(160, 360, 400, 420, ps, ps);
	solidroundrect(160, 360, 340, 420, ps, ps);
	fillroundrect(500, 360, 680, 420, ps, ps);
	solidroundrect(500, 360, 680, 420, ps, ps);
	outtextxy(160, 360, _T("1PVP"));
	outtextxy(500, 360, _T("2PVE"));
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 400 && 160 < m.x && m.y < 420 && 360 < m.y) {
				choice = 1;
				show();
			}
			else if (m.x < 680 && 500 < m.x && m.y < 420 && 360 < m.y) {
				choice = 2;
				show();
			}
		}
	}
}
void reverse(int row[], int len)
{
	char temp;
	int i, j;
	for (i = 0, j = len - 1; i <= j; i++, j--) {
		temp = row[i];
		row[i] = row[j];
		row[j] = temp;
	}
}
int score(int row[], int x)
{
	if (x > 2) {
		reverse(row, 5);
		x = 4 - x;
	}
	switch (x) {
	case 0: {
		if (row[1] == 2 && (row[2] == 2 || row[2] == 0) && (row[3] == 2 || row[3] == 0) && (row[4] == 2 || row[4] == 0)) {
			if (row[x + 2] == 0) {		//_O_??
				return(15);
			}
			else if (row[x + 3] == 0) {	//_OO_?
				return(30);//原值50###########################################################################################
			}
			else if (row[x + 4] == 0) {	//_OOO_//原值90###############################################################################
				return(150);
			}
			else {							//_OOOO
				return(1000);
			}
		}
		else if (row[1] == 1 && (row[2] == 1 || row[2] == 0) && (row[3] == 1 || row[3] == 0) && (row[4] == 1 || row[4] == 0)) {
			if (row[x + 2] == 0) {		//_*_??
				return(5);
			}
			else if (row[x + 3] == 0) {	//_**_?
				return(30);
			}
			else if (row[x + 4] == 0) {	//_***_
				return(200);//原值(70)77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
			}
			else {							//_****
				return(500);
			}
		}
	};
		  break;
	case 1: {
		if ((row[0] == 2 || row[0] == 0) && (row[2] == 2 || row[2] == 0) && (row[3] == 2 || row[3] == 0) && (row[4] == 2 || row[4] == 0)) {
			if (row[0] == 2) {
				if (row[2] == 0) {		//O_ _??
					return(15);
				}
				else if (row[3] == 0) {	//O_O_??
					return(50);
				}
				else if (row[4] == 0) {	//O_OO_
					return(90);
				}
				else {						//O_OOO
					return(1000);
				}
			}
			else if (row[2] == 0) {		//_ _ _??
				return(0);
			}
			else if (row[3] == 0) {		//_ _O_?
				return(15);
			}
			else if (row[4] == 0) {		//_ _OO_
				return(50);
			}
			else {							//_ _OOO
				return(80);
			}
		}
		else if ((row[0] == 1 || row[0] == 0) && (row[2] == 1 || row[2] == 0) && (row[3] == 1 || row[3] == 0) && (row[4] == 1 || row[4] == 0)) {
			if (row[0] == 1) {
				if (row[2] == 0) {		//*_ _??
					return(5);
				}
				else if (row[3] == 0) {	//*_*_?
					return(30);
				}
				else if (row[4] == 0) {	//*_**_
					return(70);
				}
				else {						//*_***
					return(500);
				}
			}
			else if (row[2] == 0) {		//_ _ _??
				return(0);
			}
			else if (row[3] == 0) {		//_ _*_?
				return(5);
			}
			else if (row[4] == 0) {		//_ _**_
				return(30);
			}
			else {							//_ _***
				return(60);
			}
		}
	}
		  break;
	case 2: {
		if ((row[0] == 2 || row[0] == 0) && (row[1] == 2 || row[2] == 0) && (row[3] == 2 || row[3] == 0) && (row[4] == 2 || row[4] == 0)) {
			if (row[1] == 2) {
				if (row[3] == 2) {
					if (row[0] == 2) {
						if (row[4] == 2) {//OO_OO
							return(1000);
						}
						else {
							return(90);		//OO_O_
						}
					}
					else {
						if (row[4] == 2) {//_O_OO
							return(90);
						}
						else {				//_O_O_
							return(50);
						}
					}
				}
				else {
					if (row[0] == 2) {	//OO_ _?
						return(40);
					}
					else {					//_O_ _?
						return(15);
					}
				}
			}
			else {
				if (row[3] == 2) {
					if (row[4] == 2) {	//_ _ _OO
						return(40);
					}
					else {					//_ _ _O_
						return(15);
					}
				}
			}
		}
		else if ((row[0] == 1 || row[0] == 0) && (row[1] == 1 || row[2] == 0) && (row[3] == 1 || row[3] == 0) && (row[4] == 1 || row[4] == 0)) {
			if (row[1] == 1) {
				if (row[3] == 1) {
					if (row[0] == 1) {
						if (row[4] == 1) {//**_**
							return(500);
						}
						else {				//**_*_
							return(70);
						}
					}
					else {
						if (row[4] == 1) {//_*_**
							return(70);
						}
						else {				//_*_*_
							return(30);
						}
					}
				}
				else {
					if (row[0] == 1) {	//**_ _ _
						return(20);
					}
					else {					//_*_ _?
						return(5);
					}
				}
			}
			else {
				if (row[3] == 1) {		//_ _ _**
					if (row[4] == 1) {
						return(20);
					}
					else {					//_ _ _*_
						return(5);
					}
				}
			}
		}
	}
		  break;
	}
	return(0);
}
int sense_row(int x, int y)
{
	int sum = 0, i, j;
	int row[5];
	for (i = x - 4; i <= x; i++) {
		if (!(i >= 0 && i + 4 <= 18)) {
			continue;
		}
		else {
			for (j = 0; j < 5; j++) {
				row[j] = a[y][i + j];
			}
			sum += score(row, x - i);
		}
	}
	return(sum);
}
int sense_col(int x, int y)
{
	int sum = 0, i, j;
	int row[5];
	for (i = y - 4; i <= y; i++) {
		if (!(i >= 0 && i + 4 <= 18)) {
			continue;
		}
		else {
			for (j = 0; j < 5; j++) {
				row[j] = a[i + j][x];
			}
			sum += score(row, y - i);
		}
	}
	return(sum);
}
int sense_right_bias(int x, int y)
{
	int sum = 0, i, j;
	int row[5];
	for (i = -4; i <= 0; i++) {
		if (!(y + i >= 0 && x + i >= 0 && y + i + 4 <= 18 && x + i + 4 <= 18)) {
			continue;
		}
		else {
			for (j = 0; j < 5; j++) {
				row[j] = a[y + i + j][x + i + j];
			}
			sum += score(row, -i);
		}
	}
	return(sum);
}
int sense_left_bias(int x, int y)
{
	int sum = 0, i, j;
	int row[5];
	for (i = -4; i <= 0; i++) {
		if (!(y - i <= 18 && x + i >= 0 && y - i - 4 >= 0 && x + i + 4 <= 18)) {
			continue;
		}
		else {
			for (j = 0; j < 5; j++) {
				row[j] = a[y - i - j][x + i + j];
			}
			sum += score(row, -i);
		}
	}
	return(sum);
}
void sense(void)
{
	int x, y, sum = 0;
	initial_positions();
	for (y = 0; y < 19; y++) {
		for (x = 0; x < 19; x++) {
			if (a[y][x] == 1 || a[y][x] == 2) {
				continue;
			}
			sum += sense_col(x, y);
			sum += sense_row(x, y);
			sum += sense_left_bias(x, y);
			sum += sense_right_bias(x, y);
			if (sum != 0) {
				positions[position_order].score = sum;
				positions[position_order].x = x;
				positions[position_order].y = y;
				position_order++;
				sum = 0;
			}
		}
	}
}
void xuan_ze() {
	initgraph(900, 900);
	IMAGE img_l_2;
	loadimage(&img_l_2, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\youxi.jpg"));
	putimage(0, 0, &img_l_2);
	settextcolor(RED);
	settextstyle(60, 0, _T("黑体"));
	setbkmode(TRANSPARENT);
	FILE* fp;
	fp = fopen("C:\\Users\\Lenovo\\Desktop\\五子棋\\text1.txt", "r");
	for (int i = 1; i < 6; i++) {
		fread(&f[i], sizeof(struct cunchu), 1, fp);
	}
	fclose(fp);
	memcpy(f_2, f, sizeof(f));
	for (int i = 1; i < 6; i++)
	{
		setfillcolor(RGB(196, 197, 192));
		fillroundrect(240, 100 + i * 100, 660, 100 + i * 100 + 60, ps, ps);
		solidroundrect(240, 100 + i * 100, 660, 100 + i * 100 + 60, ps, ps);
	}
	for (int i = 1; i <= 5; i++)
	{
		if (f_2[i].shun_win_lose == 2)
		{
			outtextxy(300, 100 + i * 100, _T("记录   失败"));
			outtextxy(420, 100 + i * 100, (char)(i + 48));
		}
		if (f[i].shun_win_lose == 1)
		{
			outtextxy(300, 100 + i * 100, _T("记录   成功"));
			outtextxy(420, 100 + i * 100, (char)(i + 48));
		}
		if (f[i].shun_win_lose == 0)
		{
			outtextxy(360, 100 + i * 100, _T("未记录"));
		}
	}
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{

			if (m.x < 660 && 240 < m.x && m.y < 260 && 200 < m.y) {
				k = 1; break;
			}
			else if (m.x < 660 && 240 < m.x && m.y < 360 && 300 < m.y) {
				k = 2; break;
			}
			else if (m.x < 660 && 240 < m.x && m.y < 460 && 400 < m.y)
			{
				k = 3; break;
			}
			else if (m.x < 660 && 240 < m.x && m.y < 560 && 500 < m.y)
			{
				k = 4; break;
			}
			else if (m.x < 660 && 240 < m.x && m.y < 660 && 600 < m.y)
			{
				k = 5; break;
			}
		}
	}
}/
void cunchu_fun()
{
	xuan_ze();
	IMAGE img_yx;
	loadimage(&img_yx, _T("C:\\Users\\Lenovo\\Desktop\\五子棋\\youxi.jpg"));
	putimage(0, 0, &img_yx);
	setlinestyle(PS_SOLID, 1);
	setfillcolor(RGB(253, 253, 233));
	solidrectangle(30, 30, 726, 726);
	setcolor(BLACK);
	setfillcolor(RGB(143, 244, 249));
	fillroundrect(750, 198, 900, 378, ps, ps);
	solidroundrect(750, 198, 900, 378, ps, ps);
	settextstyle(60, 30, _T("黑体"));
	settextcolor(RGB(255, 183, 111));
	setbkmode(TRANSPARENT);
	if (f_2[k].shun_win_lose == 2) {
		outtextxy(750, 198, _T("吃|长"));
		outtextxy(750, 258, _T("一|一"));
		outtextxy(750, 318, _T("堑|智"));
	}
	else if (f_2[k].shun_win_lose == 1)
	{
		outtextxy(750, 198, _T("仍|续"));
		outtextxy(750, 258, _T("需|努"));
		outtextxy(750, 318, _T("继|力"));
	}
	for (int i = 1; i <= 20; i++)
	{
		line(36, i * sp, 720, i * sp);
		line(i * sp, 36, i * sp, 720);
	}
	setlinestyle(PS_SOLID, 4);
	line(30, 30, 726, 30);
	line(30, 30, 30, 726);
	line(30, 726, 726, 726);
	line(726, 726, 726, 30);
	memcpy(f[k].cv, b, sizeof(b));
	for (int i = 1; i < 20; i++) {
		for (int j = 1; j < 20; j++) {
			if (f_2[k].cv[i - 1][j - 1] == 1)
			{
				setcolor(BLACK);
				setfillcolor(BLACK);
				fillcircle(i * 36 + 18, j * 36 + 18, 14);
				circle(i * 36 + 18, j * 36 + 18, 14);
			}
			if (f_2[k].cv[i - 1][j - 1] == 2)
			{
				setcolor(RGB(171, 171, 171));
				setfillcolor(RGB(171, 171, 171));
				fillcircle((i * 36 + 18), (j * 36 + 18), 14);
				circle((i * 36 + 18), (j * 36 + 18), 14);
			}
		}
	}
	setfillcolor(RGB(116, 250, 240));
	settextcolor(RGB(255, 134, 134));
	fillroundrect(600, 760, 780, 820, ps, ps);
	solidroundrect(600, 760, 780, 820, ps, ps);
	outtextxy(600, 760, _T("新游戏"));
	setfillcolor(RGB(116, 250, 240));
	fillroundrect(260, 760, 560, 820, ps, ps);
	solidroundrect(260, 760, 560, 820, ps, ps);
	settextcolor(RGB(255, 134, 134));
	outtextxy(260, 760, _T("退出本游戏"));
	while (1) {
		MOUSEMSG m;
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x < 780 && 600 < m.x && m.y < 820 && 760 < m.y) {
				xian_hou = 0;
				mo = 1;
				mod = 0;
				mode();
			}
			if (260 < m.x && m.x < 560 && m.y < 820 && 760 < m.y) {
				exit(0);
			}
		}
	}
}

void judge()
{
	for (int i = 0; i < 19; i++) {
		for (int j = 0; j < 19; j++) {
			if (a[i][j] == 1 && a[i][j + 1] == 1 && a[i][j + 2] == 1 && a[i][j + 3] == 1 && a[i][j + 4] == 1)
			{
				win_lose = 1;  break;
			}
			if (a[i][j] == 1 && a[i + 1][j] == 1 && a[i + 2][j] == 1 && a[i + 3][j] == 1 && a[i + 4][j] == 1)
			{
				win_lose = 1;  break;
			}
			if (a[i][j] == 1 && a[i + 1][j + 1] == 1 && a[i + 2][j + 2] == 1 && a[i + 3][j + 3] == 1 && a[i + 4][j + 4] == 1)
			{
				win_lose = 1;  break;
			}
			if (i > 3 && a[i][j] == 1 && a[i - 1][j + 1] == 1 && a[i - 2][j + 2] == 1 && a[i - 3][j + 3] == 1 && a[i - 4][j + 4] == 1)
			{
				win_lose = 1; break;
			}
			/*******************************************************************************************************************************************/
			if (a[i][j] == 2 && a[i][j + 1] == 2 && a[i][j + 2] == 2 && a[i][j + 3] == 2 && a[i][j + 4] == 2)
			{
				win_lose = 2; break;
			}
			if (a[i][j] == 2 && a[i + 1][j] == 2 && a[i + 2][j] == 2 && a[i + 3][j] == 2 && a[i + 4][j] == 2)
			{
				win_lose = 2; break;
			}
			if (a[i][j] == 2 && a[i + 1][j + 1] == 2 && a[i + 2][j + 2] == 2 && a[i + 3][j + 3] == 2 && a[i + 4][j + 4] == 2)
			{
				win_lose = 2;  break;
			}
			if (i > 3 && a[i][j] == 2 && a[i - 1][j + 1] == 2 && a[i - 2][j + 2] == 2 && a[i - 3][j + 3] == 2 && a[i - 4][j + 4] == 2)
			{
				win_lose = 2;  break;
			}
		}
		if (win_lose == 1 || win_lose == 2)
		{
			break;
		}
	}
	int c_v = 0;
	if (win_lose == 1 || win_lose == 2) {
		if (win_lose == 1 || win_lose == 2) {
			FILE* fp;
			fp = fopen("C:\\Users\\Lenovo\\Desktop\\五子棋\\text1.txt", "r");
			for (int i = 1; i < 6; i++) {
				fread(&f[i], sizeof(struct cunchu), 1, fp);
			}
			fclose(fp);
			for (int i = 1; i <= 6; i++) {
				if (f[i].cixu != 0)
				{
					c_v++;
					if (c_v == 5)
					{
						for (int j = 0; j < 6; j++)
						{
							f[j].cixu = 0;
						}
						c_v = 0;
						i = 0;
					}
					continue;
				}
				else
				{
					memcpy(f[i].cv, a, sizeof(a));
					f[i].shun_win_lose = win_lose;
					f[i].cixu = i;
					break;
				}
			}
			fp = fopen("C:\\Users\\Lenovo\\Desktop\\五子棋\\text1.txt", "w");
			for (int i = 1; i < 6; i++) {
				fwrite(&f[i], sizeof(struct cunchu), 1, fp);
			}
			fclose(fp);
		}
	}
	switch (win_lose) {
	case 1:
		xian_hou = 0;
		Sleep(ti);
		win();
		break;
	case 2:
		xian_hou = 0;
		Sleep(ti);
		lose();
		break;
	}
}
int main() {
	startmenu();
	show();
}
  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-10-28 12:13:13  更:2021-10-28 12:14:52 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 5:43:24-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码