#define _CRT_SECURE_NO_WARNINGS
#ifdef UNICODE
#undef UNICODE
#endif
#include<iostream>
#include<string>
#include<memory.h>
#include<set>
#include<deque>
#include<vector>
#include<easyx.h>
#include<graphics.h>
#include<conio.h>
#define WIDTH 450
#define HEIGHT 450
using namespace std;
struct mm
{
int x;
int y;
};
mm my = { 0,0 };
//全局声明
// 结果枚举
enum GameResult { CONTINUE, BLACK_WIN, WHITE_WIN, DRAW };
// 全局变量,用于记录胜负结果
int blackWins = 0;//AI胜利
int whiteWins = 0;//玩家胜利
// 函数声明
GameResult checkGameResult(uint8_t board[15][15]);
void showResultDialog(GameResult result);
void drawWinRate();
void machine_human_play();
// 在游戏结束后显示胜负结果对话框,并根据用户选择决定下一步操作
void showResultDialog(GameResult result) {
string message;
if (result == BLACK_WIN) {
message = "黑棋获胜!是否开始下一局?";
blackWins++;
}
else if (result == WHITE_WIN) {
message = "白棋获胜!是否开始下一局?";
whiteWins++;
}
else {
message = "平局!是否开始下一局?";
}
int choice = MessageBox(GetHWnd(), message.c_str(), "游戏结束", MB_YESNO);
if (choice == IDYES) {
// 清空棋盘并重新开始游戏
cleardevice();
machine_human_play();
}
else {
// 退出游戏
closegraph();
exit(0);
}
}
// 在左上角显示胜负比例
void drawWinRate() {
char rateStr[256] = "";
double totalGames = blackWins + whiteWins;
// double blackWinRate = (blackWins / totalGames) * 100.0;
// double whiteWinRate = (whiteWins / totalGames) * 100.0;
double AIUSER = (whiteWins / totalGames) * 100;
sprintf(rateStr, "<第%.0f场>_[AI黑 VS 玩家白]_<%d:%d>_玩家胜率<%0.2lf ﹪>",
totalGames + 1, (int)blackWins, (int)whiteWins, AIUSER);
settextstyle(15, 0, "宋体");
settextcolor(YELLOW);
outtextxy(25, 5, rateStr);
}
// 在游戏结束后检查胜负结果
GameResult checkGameResult(uint8_t board[15][15]) {
// 这里添加你检查胜负结果的代码
return CONTINUE;
}
//
class GameTree {
private:
class Node {
public:
int32_t value;
uint32_t depth;
Node* father;
set<Node*> children;
uint8_t cntX, cntY;
uint8_t board[15][15]{};
Node() {
father = nullptr;
children.clear();
value = INT32_MIN;
depth = cntX = cntY = 0;
memset(board, 0, sizeof(board));
}
Node(Node* node, uint8_t opeX, uint8_t opeY) {
depth = node->depth + 1;
value = is_max_node() ? INT32_MIN : INT32_MAX;
father = node;
children.clear();
cntX = opeX;
cntY = opeY;
memcpy(board, node->board, sizeof(board));
board[cntX][cntY] = (depth & 1u) ? 'B' : 'W';
}
bool is_max_node() {
return (depth & 1u) ^ 1u;
}
static int32_t evaluate_black(string& s) {
string patterns[31] = {
"B0000", "0B000", "00B00", "000B0", "0000B",
"BB000", "0BB00", "00BB0", "000BB", "B0B00", "0B0B0", "00B0B", "B00B0", "0B00B", "B000B",
"BBB00", "0BBB0", "00BBB", "BB0B0", "0BB0B", "B0BB0", "0B0BB", "BB00B", "B00BB", "B0B0B",
"BBBB0", "BBB0B", "BB0BB", "B0BBB", "0BBBB", "BBBBB",
};
int32_t scores[31] = {
1, 1, 1, 1, 1,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
10000, 10000, 10000, 10000, 10000, 1000000,
};
for (uint8_t i = 0; i < 31; i++)
if (s == patterns[i]) return scores[i];
return 0;
}
static int32_t evaluate_white(string& s) {
string patterns[31] = {
"W0000", "0W000", "00W00", "000W0", "0000W",
"WW000", "0WW00", "00WW0", "000WW", "W0W00", "0W0W0", "00W0W", "W00W0", "0W00W", "W000W",
"WWW00", "0WWW0", "00WWW", "WW0W0", "0WW0W", "W0WW0", "0W0WW", "WW00W", "W00WW", "W0W0W",
"WWWW0", "WWW0W", "WW0WW", "W0WWW", "0WWWW", "WWWWW",
};
int32_t scores[31] = {
1, 1, 1, 1