7 Commits

21 changed files with 401 additions and 173 deletions
+7 -1
View File
@@ -39,4 +39,10 @@ Thumbs.db
# 动态库文件
*.dll
*.so
*.dylib
*.dylib
# 资源文件
*.res
*.ico
# 打包文件
+78
View File
@@ -0,0 +1,78 @@
# 为五子棋游戏添加图标指南
## 问题说明
在尝试为可执行文件添加图标时,发现icon文件夹中的图标文件格式不正确:
- `gobang_icon1.ico``gobang_icon2.ico` 实际上是HTML文件和PNG文件,而不是真正的ICO格式文件
## 解决方案
### 方法一:获取正确的ICO文件
1. **下载或创建真正的ICO文件**
- 使用在线ICO转换工具将PNG/JPG转换为ICO格式
- 推荐网站:https://www.icoconverter.com/
- 或使用GIMP、Photoshop等图像编辑软件导出ICO格式
2. **替换现有文件**
- 将正确的ICO文件保存为 `icon/gobang_icon.ico`
- 确保文件是真正的ICO格式(文件头应为 00 00 01 00)
3. **修改资源文件**
- 编辑 `gobang.rc` 文件
- 取消注释图标行:`IDI_APPLICATION ICON "icon\\gobang_icon.ico"`
4. **重新编译**
```bash
windres gobang.rc -o gobang.res
gcc -std=c17 -o gobang.exe *.c gobang.res -lws2_32
```
### 方法二:使用现有PNG文件(需要转换)
如果你有PNG格式的图标文件,可以:
1. **在线转换**
- 访问 https://convertio.co/png-ico/
- 上传PNG文件并转换为ICO格式
- 下载转换后的ICO文件
2. **使用ImageMagick(如果已安装)**
```bash
magick convert icon/your_image.png icon/gobang_icon.ico
```
### 方法三:使用Windows资源编辑器
1. 编译不带图标的exe文件(当前状态)
2. 使用Resource Hacker等工具后期添加图标
3. 下载Resource Hackerhttp://www.angusj.com/resourcehacker/
## 当前状态
- ✅ 程序可以正常编译和运行
- ✅ 包含版本信息资源
- ❌ 暂时没有应用程序图标
- ✅ 提供了完整的构建脚本
## 编译指令
### 不带图标版本(当前可用)
```bash
gcc -std=c17 -o gobang.exe *.c -lws2_32
```
### 带图标版本(需要正确的ICO文件)
```bash
windres gobang.rc -o gobang.res
gcc -std=c17 -o gobang.exe *.c gobang.res -lws2_32
```
## 验证ICO文件格式
可以使用以下PowerShell命令检查文件是否为真正的ICO格式:
```powershell
Get-Content icon/gobang_icon.ico -AsByteStream -TotalCount 4 | ForEach-Object { '{0:X2}' -f $_ }
```
正确的ICO文件应该显示:`00 00 01 00`
+59
View File
@@ -0,0 +1,59 @@
项目要求文档 - 五子棋游戏
1. 项目概述
- 开发一个基于C语言的五子棋游戏,支持本地多人、AI对战和网络对战模式。
- 游戏应运行在Windows环境下,支持命令行界面。
- 包括游戏配置、记录保存和复盘功能。
2. 功能需求
- **游戏模式**
- 单人模式:玩家 vs AI
- 双人模式:本地两人对战
- 网络模式:通过TCP/IP进行远程对战
- **棋盘和规则**
- 默认15x15棋盘,支持自定义大小(5-25)
- 支持禁手规则选项
- 先手黑子,五连珠获胜
- **AI功能**
- 实现AI算法,支持不同难度级别(1-5级)
- AI应能计算最佳落子位置
- 支持Alpha-Beta剪枝算法和威胁检测
- **配置管理**
- 支持修改棋盘大小、禁手规则、计时器、网络端口等
- 配置保存到INI文件
- 默认配置和重置功能
- 统一的输入验证机制
- **游戏记录**
- 自动保存对局记录到CSV文件
- 支持复盘功能,查看历史对局
- 记录包含时间戳、玩家信息、棋局步骤等
- **用户界面**
- 命令行界面显示棋盘
- 支持坐标输入落子(数字格式:行 列)
- 显示当前玩家、计时、游戏状态等信息
- 菜单系统和配置界面
- **网络功能**
- 支持服务器/客户端模式
- 实时传输棋子位置
- 超时和断线处理
- 支持端口配置
3. 技术要求
- 使用C语言开发
- Windows平台,包含Winsock网络库(-lws2_32链接)
- 模块化设计:分离游戏逻辑、AI、配置、网络、UI等模块
- 错误处理和统一的输入验证
- 支持跨平台编译(Windows/Linux
4. 非功能需求
- 性能:响应时间<1秒(AI计算除外)
- 可维护性:代码模块化,注释清晰
- 兼容性:Windows 11,支持GCC编译器
- 可扩展性:易于添加新的AI算法和游戏模式
5. 交付物
- 源代码文件(.c/.h文件)
- 配置文件(gobang_config.ini
- 记录文件夹(records/
- 文档:README.md、AI增强指南、架构重构指南、网络功能说明、图标指南等
- 代码统计报告和项目简介
+9
View File
@@ -1,3 +1,12 @@
/**
* @file ai.c
* @note 本文件定义了AI模块的函数和变量
* @note 包括:
* 1. 评估一个落子位置的综合得分(结合进攻和防守)
* 2. 评估指定位置的价值
* 3. 评估棋盘价值
*/
#include "gobang.h"
#include "ai.h"
#include "config.h"
+1
View File
@@ -6,6 +6,7 @@
* 2. 评估指定位置的价值
* 3. 评估棋盘价值
*/
#ifndef AI_H
#define AI_H
+27 -104
View File
@@ -1,3 +1,9 @@
/**
* @file config.c
* @brief 五子棋游戏参数配置源文件
* @note 本文件集中定义了五子棋游戏的所有参数配置,便于统一管理和修改
*/
#include "config.h"
#include "ui.h"
#include "game_mode.h"
@@ -146,27 +152,10 @@ void display_current_config()
void config_board_size()
{
printf("\n当前棋盘大小: %d x %d\n", BOARD_SIZE, BOARD_SIZE);
printf("请输入新的棋盘大小 (%d-%d): ", MIN_BOARD_SIZE, MAX_BOARD_SIZE);
int new_size;
if (scanf("%d", &new_size) == 1)
{
if (new_size >= MIN_BOARD_SIZE && new_size <= MAX_BOARD_SIZE)
{
BOARD_SIZE = new_size;
printf("棋盘大小已设置为: %d x %d\n", BOARD_SIZE, BOARD_SIZE);
}
else
{
printf("无效的棋盘大小!\n");
}
}
else
{
printf("输入格式错误!\n");
// 清除输入缓冲区
while (getchar() != '\n');
}
int new_size = get_integer_input("请输入新的棋盘大小: ", MIN_BOARD_SIZE, MAX_BOARD_SIZE);
BOARD_SIZE = new_size;
printf("棋盘大小已设置为: %d x %d\n", BOARD_SIZE, BOARD_SIZE);
}
/**
@@ -175,19 +164,10 @@ void config_board_size()
void config_forbidden_moves()
{
printf("\n当前禁手规则: %s\n", use_forbidden_moves ? "开启" : "关闭");
printf("是否启用禁手规则?(1=开启, 0=关闭): ");
int choice;
if (scanf("%d", &choice) == 1)
{
use_forbidden_moves = (choice != 0);
printf("禁手规则已%s\n", use_forbidden_moves ? "开启" : "关闭");
}
else
{
printf("输入格式错误!\n");
while (getchar() != '\n');
}
int choice = get_integer_input("是否启用禁手规则?(1=开启, 0=关闭): ", 0, 1);
use_forbidden_moves = (choice != 0);
printf("禁手规则已%s\n", use_forbidden_moves ? "开启" : "关闭");
}
/**
@@ -196,36 +176,18 @@ void config_forbidden_moves()
void config_timer()
{
printf("\n当前计时器: %s\n", use_timer ? "开启" : "关闭");
printf("是否启用计时器?(1=开启, 0=关闭): ");
int choice;
if (scanf("%d", &choice) == 1)
int choice = get_integer_input("是否启用计时器?(1=开启, 0=关闭): ", 0, 1);
use_timer = choice;
if (use_timer)
{
use_timer = choice;
if (use_timer)
{
printf("请输入时间限制(分钟): ");
int new_limit;
if (scanf("%d", &new_limit) == 1 && new_limit > 0)
{
time_limit = new_limit * 60; // 转换为秒数存储
printf("计时器已开启,时间限制: %d 分钟\n", time_limit / 60);
}
else
{
printf("无效的时间限制!\n");
while (getchar() != '\n');
}
}
else
{
printf("计时器已关闭\n");
}
int new_limit = get_integer_input("请输入时间限制(分钟): ", 1, 999);
time_limit = new_limit * 60; // 转换为秒数存储
printf("计时器已开启,时间限制: %d 分钟\n", time_limit / 60);
}
else
{
printf("输入格式错误!\n");
while (getchar() != '\n');
printf("计时器已关闭\n");
}
}
@@ -238,45 +200,13 @@ void config_network()
printf("当前网络端口: %d\n", network_port);
printf("当前网络超时: %d 毫秒\n", network_timeout);
printf("\n请输入新的网络端口 (%d-%d): ", MIN_NETWORK_PORT, MAX_NETWORK_PORT);
int new_port;
if (scanf("%d", &new_port) == 1)
{
if (new_port >= MIN_NETWORK_PORT && new_port <= MAX_NETWORK_PORT)
{
network_port = new_port;
printf("网络端口已设置为: %d\n", network_port);
}
else
{
printf("无效的端口号!端口范围: %d-%d\n", MIN_NETWORK_PORT, MAX_NETWORK_PORT);
}
}
else
{
printf("输入格式错误!\n");
while (getchar() != '\n');
}
int new_port = get_integer_input("请输入新的网络端口: ", MIN_NETWORK_PORT, MAX_NETWORK_PORT);
network_port = new_port;
printf("网络端口已设置为: %d\n", network_port);
printf("\n请输入网络超时时间(毫秒, 建议1000-10000): ");
int new_timeout;
if (scanf("%d", &new_timeout) == 1)
{
if (new_timeout > 0)
{
network_timeout = new_timeout;
printf("网络超时已设置为: %d 毫秒\n", network_timeout);
}
else
{
printf("无效的超时时间!\n");
}
}
else
{
printf("输入格式错误!\n");
while (getchar() != '\n');
}
int new_timeout = get_integer_input("请输入网络超时时间(毫秒, 建议1000-10000): ", 1000, 60000);
network_timeout = new_timeout;
printf("网络超时已设置为: %d 毫秒\n", network_timeout);
}
/**
@@ -292,14 +222,7 @@ void config_management_menu()
display_settings_menu();
display_current_config();
printf("请选择操作: ");
if (scanf("%d", &choice) != 1)
{
printf("输入格式错误!\n");
while (getchar() != '\n');
pause_for_input("按任意键继续...");
continue;
}
choice = get_integer_input("请选择操作(0-5): ", 0, 5);
switch (choice)
{
@@ -318,7 +241,7 @@ void config_management_menu()
case 5:
printf("AI难度设置功能开发中...\n");
break;
case 6:
case 0:
save_game_config();
return;
default:
+22 -22
View File
@@ -32,36 +32,36 @@
#define INPUT_SURRENDER -4 // 认输
//---------- 游戏设置默认值 ----------//
#define DEFAULT_USE_FORBIDDEN_MOVES false // 默认不启用禁手规则
#define DEFAULT_USE_TIMER 0 // 默认不启用计时器
#define DEFAULT_TIME_LIMIT 30 // 默认时间限制为30秒(内部存储)
#define DEFAULT_USE_FORBIDDEN_MOVES false // 默认不启用禁手规则
#define DEFAULT_USE_TIMER 0 // 默认不启用计时器
#define DEFAULT_TIME_LIMIT 30 // 默认时间限制为30秒(内部存储)
//---------- AI参数 ----------//
#define DEFAULT_AI_DEPTH 5 // 默认AI搜索深度(从3提升到5
#define DEFAULT_DEFENSE_COEFFICIENT 1.5 // 默认防守系数(从1.2提升到1.5
#define DEFAULT_AI_DEPTH 5 // 默认AI搜索深度
#define DEFAULT_DEFENSE_COEFFICIENT 1.5 // 默认防守系数
//---------- 网络参数 ----------//
#define DEFAULT_NETWORK_PORT 8888 // 默认网络端口
#define MIN_NETWORK_PORT 1024 // 最小网络端口
#define MAX_NETWORK_PORT 65535 // 最大网络端口
#define NETWORK_TIMEOUT_MS 5000 // 网络超时时间(毫秒)
#define NETWORK_BUFFER_SIZE 1024 // 网络缓冲区大小
#define DEFAULT_NETWORK_PORT 8888 // 默认网络端口
#define MIN_NETWORK_PORT 1024 // 最小网络端口
#define MAX_NETWORK_PORT 65535 // 最大网络端口
#define NETWORK_TIMEOUT_MS 5000 // 网络超时时间(毫秒)
#define NETWORK_BUFFER_SIZE 1024 // 网络缓冲区大小
// 网络配置
#define DEFAULT_PORT 8888 // 默认端口(与DEFAULT_NETWORK_PORT保持一致)
#define BUFFER_SIZE 1024 // 缓冲区大小(与NETWORK_BUFFER_SIZE保持一致)
#define MAX_IP_LENGTH 16 // 最大IP地址长度
#define DEFAULT_PORT 8888 // 默认端口(与DEFAULT_NETWORK_PORT保持一致)
#define BUFFER_SIZE 1024 // 缓冲区大小(与NETWORK_BUFFER_SIZE保持一致)
#define MAX_IP_LENGTH 16 // 最大IP地址长度
// 网络消息类型
#define MSG_MOVE 1 // 落子消息
#define MSG_CHAT 2 // 聊天消息
#define MSG_SURRENDER 3 // 认输消息
#define MSG_UNDO_REQUEST 4 // 悔棋请求
#define MSG_UNDO_RESPONSE 5 // 悔棋回应
#define MSG_GAME_START 6 // 游戏开始
#define MSG_GAME_END 7 // 游戏结束
#define MSG_HEARTBEAT 8 // 心跳包
#define MSG_DISCONNECT 9 // 断线消息
#define MSG_MOVE 1 // 落子消息
#define MSG_CHAT 2 // 聊天消息
#define MSG_SURRENDER 3 // 认输消息
#define MSG_UNDO_REQUEST 4 // 悔棋请求
#define MSG_UNDO_RESPONSE 5 // 悔棋回应
#define MSG_GAME_START 6 // 游戏开始
#define MSG_GAME_END 7 // 游戏结束
#define MSG_HEARTBEAT 8 // 心跳包
#define MSG_DISCONNECT 9 // 断线消息
//---------- 评分参数 ----------//
// 棋型评分 - 用于calculate_step_score函数
+17 -7
View File
@@ -1,3 +1,13 @@
/**
* @file game_mode.c
* @brief 五子棋游戏框架源文件
* @note 本文件定义了五子棋游戏的四种主要模式:
* 1. AI对战模式
* 2. 双人对战模式
* 3. 网络对战模式
* 4. 复盘模式
*/
#include "game_mode.h"
#include "init_board.h"
#include "gobang.h"
@@ -349,18 +359,18 @@ void run_ai_game()
scores_calculated = 0;
// AI对战模式
int AI_DEPTH = 3;
int AI_DEPTH = DEFAULT_AI_DEPTH;
AI_DEPTH = get_integer_input("请选择AI难度(1~5), 数字越大越强,注意数字越大AI思考时间越长!):", 1, 5);
/**
* @brief AI的防守系数,系数越大越倾向于防守
* @note 1~1.2
* 2~1.3
* 3~1.4
* 4~1.5
* 5~1.6
* @note 1~1.5
* 2~1.6
* 3~1.7
* 4~1.8
* 5~1.9
*/
defense_coefficient = 1.2 + (AI_DEPTH - 1) * 0.1;
defense_coefficient = DEFAULT_DEFENSE_COEFFICIENT + (AI_DEPTH - 1) * 0.1;
empty_board();
int current_player = determine_first_player(PLAYER, AI);
-2
View File
@@ -2,8 +2,6 @@
* @file globals.c
* @author 刘航宇(3364451258@qq.com、15236416560@163.com、lhy3364451258@outlook.com)
* @brief 全局变量定义和初始化文件
* @version 6.0
* @date 2025-07-10
* @note 集中管理所有全局变量的定义和初始化,提高代码可维护性
*/
+7
View File
@@ -1,3 +1,10 @@
/**
* @file gobang.c
* @brief 五子棋游戏源文件
* @note 本文件定义了五子棋游戏的主要数据结构、函数和全局变量。
* 它包含了游戏棋盘的表示、玩家操作、规则检查以及AI决策等功能。
*/
#include "game_mode.h"
#include "init_board.h"
#include "gobang.h"
+1
View File
@@ -4,6 +4,7 @@
* @note 本文件定义了五子棋游戏的主要数据结构、函数和全局变量。
* 它包含了游戏棋盘的表示、玩家操作、规则检查以及AI决策等功能。
*/
#ifndef GO_BANG_H
#define GO_BANG_H
+7
View File
@@ -1,3 +1,10 @@
/**
* @file init_board.c
* @brief 初始化游戏棋盘源文件
* @note 本文件定义了初始化游戏棋盘的相关函数。
* 它负责设置游戏的初始状态,包括棋盘大小、玩家标识、游戏规则等。
*/
#include "init_board.h"
#include "gobang.h"
#include "game_mode.h"
+1
View File
@@ -4,6 +4,7 @@
* @note 本文件定义了初始化游戏棋盘的相关函数和全局变量。
* 它负责设置游戏的初始状态,包括棋盘大小、玩家标识、游戏规则等。
*/
#ifndef INIT_BOARD_H
#define INIT_BOARD_H
+55
View File
@@ -0,0 +1,55 @@
; NSIS Installation Script
!include "MUI2.nsh"
; Basic Information
Name "Gobang Game"
OutFile "..\\Gobang_Setup.exe"
InstallDir "$PROGRAMFILES\Gobang"
RequestExecutionLevel admin
; Interface Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
; Installation Pages
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; Language Settings
!insertmacro MUI_LANGUAGE "SimpChinese"
; Installation Section
Section "Main"
SetOutPath "$INSTDIR"
; Copy configuration and documentation files
File "..\\gobang_config.ini"
File "..\\README.md"
; Copy executable file if exists
IfFileExists "..\\gobang.exe" 0 +2
File "..\\gobang.exe"
; Create program group directory
CreateDirectory "$SMPROGRAMS\Gobang"
; Create shortcuts (only if executable exists)
IfFileExists "$INSTDIR\gobang.exe" 0 +3
CreateShortCut "$DESKTOP\Gobang.lnk" "$INSTDIR\gobang.exe"
CreateShortCut "$SMPROGRAMS\Gobang\Gobang.lnk" "$INSTDIR\gobang.exe"
; Write uninstall information
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang" \
"DisplayName" "Gobang Game"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang" \
"UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
SectionEnd
; Uninstall Section
Section "Uninstall"
RMDir /r "$INSTDIR"
Delete "$DESKTOP\Gobang.lnk"
RMDir /r "$SMPROGRAMS\Gobang"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gobang"
SectionEnd
+57
View File
@@ -0,0 +1,57 @@
; Inno Setup Script for Gobang Game
; Generated by Inno Setup Script Wizard
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
AppId={{A92AAE42-5C7E-4C8E-9F2B-8D4E5F6A7B8C}
AppName=Gobang Game
AppVersion=1.0
AppPublisher=Gobang Game Developer
DefaultDirName={autopf}\Gobang
DefaultGroupName=Gobang Game
AllowNoIcons=yes
OutputDir=..
OutputBaseFilename=Gobang_Setup
SetupIconFile=compiler:SetupClassicIcon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
; 可执行文件
Source: "..\\gobang.exe"; DestDir: "{app}"; Flags: ignoreversion
; 配置文件
Source: "..\\gobang_config.ini"; DestDir: "{app}"; Flags: ignoreversion
; 指定的TXT文件
Source: "..\\TXT\\*"; DestDir: "{app}\TXT"; Flags: ignoreversion
; 文档文件
Source: "..\\README.md"; DestDir: "{app}"; Flags: ignoreversion
[Dirs]
; 创建空的records目录(不包含存档文件)
Name: "{app}\records"
[Icons]
Name: "{group}\Gobang Game"; Filename: "{app}\gobang.exe"; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
Name: "{group}\{cm:UninstallProgram,Gobang Game}"; Filename: "{uninstallexe}"
Name: "{autodesktop}\Gobang Game"; Filename: "{app}\gobang.exe"; Tasks: desktopicon; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
[Run]
Filename: "{app}\gobang.exe"; Description: "{cm:LaunchProgram,Gobang Game}"; Flags: nowait postinstall skipifsilent; Check: FileExists(ExpandConstant('{app}\gobang.exe'))
[Code]
function FileExists(const FileName: string): Boolean;
begin
Result := FileExists(FileName);
end;
+15 -8
View File
@@ -1,3 +1,17 @@
/**
* @file main.c
* @brief 五子棋游戏主函数文件
* @note 本文件包含了游戏的主循环、模式选择和游戏初始化等功能
* @brief 将以下指令复制到powershell
* gcc -std=c17 -o gobang.exe *.c -lws2_32
.\gobang.exe
* @detail gcc 为编译器,添加了-lws2_32链接Windows网络库
* @detail 编译指令:gcc -std=c17 -o gobang.exe *.c -lws2_32
* @detail 运行指令:.\gobang.exe
* @brief & "D:\Program Files (x86)\NSIS\makensis.exe" "installer\\installer.nsi"
* @brief & "D:\Program Files (x86)\Inno Setup 6\iscc.exe" installer\\setup.iss
*/
#include "game_mode.h"
#include "ui.h"
#include "config.h"
@@ -7,13 +21,6 @@
#include <direct.h>
#endif
/**
* @brief 将指令复制到powershell
* gcc -std=c17 -o gobang.exe *.c -lws2_32
.\gobang.exe
* gcc 为编译器,添加了network.c网络模块,-lws2_32链接Windows网络库
*/
int main(int argc, char *argv[])
{
// 设置控制台编码为UTF-8
@@ -81,4 +88,4 @@ int main(int argc, char *argv[])
}
return 0;
}
}
-4
View File
@@ -2,10 +2,6 @@
* @file network.c
* @author 刘航宇(3364451258@qq.com、15236416560@163.com、lhy3364451258@outlook.com)
* @brief 五子棋网络对战模块实现
* @version 6.0
* @date 2025-07-10
*
* @copyright Copyright (c) 2025
*/
#include "network.h"
+8 -3
View File
@@ -1,3 +1,10 @@
/**
* @file record.c
* @brief 游戏复盘与记录源文件
* @note 本文件定义了游戏复盘与记录相关的函数和数据结构。
* 它负责管理游戏的历史记录、加载和保存游戏文件、计算游戏评分等功能。
*/
#include "record.h"
#include "game_mode.h"
#include "gobang.h"
@@ -289,10 +296,8 @@ void display_game_scores(int game_mode)
*/
void handle_save_record(int game_mode)
{
int save_choice = 0;
printf("===== 游戏结束 =====\n");
printf("是否保存游戏记录? (1-是, 0-否): ");
scanf("%d", &save_choice);
int save_choice = get_integer_input("是否保存游戏记录? (1-是, 0-否): ", 0, 1);
if (save_choice == 1)
{
+20 -20
View File
@@ -23,9 +23,9 @@
* @brief 记录一步棋的详细信息
*/
typedef struct {
int player; // 执行该步的玩家标识
int x; // 落子的行坐标 (0-based)
int y; // 落子的列坐标 (0-based)
int player; // 执行该步的玩家标识
int x; // 落子的行坐标 (0-based)
int y; // 落子的列坐标 (0-based)
} Step;
/**
@@ -33,9 +33,9 @@ typedef struct {
* @details 用于评估棋形,例如判断活三、冲四等关键形态
*/
typedef struct {
int continuous_chess; // 连续同色棋子的数量
bool check_start; // 棋子序列的起始端是否为空位(即是否开放)
bool check_end; // 棋子序列的末尾端是否为空位(即是否开放)
int continuous_chess; // 连续同色棋子的数量
bool check_start; // 棋子序列的起始端是否为空位(即是否开放)
bool check_end; // 棋子序列的末尾端是否为空位(即是否开放)
} DirInfo;
// ==================== AI相关数据结构 ====================
@@ -45,8 +45,8 @@ typedef struct {
* @details 用于AI移动排序,存储候选移动及其评估分数
*/
typedef struct {
int x, y; // 位置坐标
int score; // 评估分数
int x, y; // 位置坐标
int score; // 评估分数
} ScoredMove;
/**
@@ -54,12 +54,12 @@ typedef struct {
* @details 用于AI威胁检测系统
*/
typedef enum {
THREAT_NONE = 0, // 无威胁
THREAT_WIN = 5, // 直接获胜
THREAT_FOUR = 4, // 活四/冲四
THREAT_THREE = 3, // 活三
THREAT_DOUBLE = 2, // 双威胁
THREAT_POTENTIAL = 1 // 潜在威胁
THREAT_NONE = 0, // 无威胁
THREAT_WIN = 5, // 直接获胜
THREAT_FOUR = 4, // 活四/冲四
THREAT_THREE = 3, // 活三
THREAT_DOUBLE = 2, // 双威胁
THREAT_POTENTIAL = 1 // 潜在威胁
} ThreatLevel;
// ==================== 网络相关数据结构 ====================
@@ -69,11 +69,11 @@ typedef enum {
* @details 用于网络对战中的消息传输
*/
typedef struct {
int type; // 消息类型
int player_id; // 玩家ID
int x, y; // 坐标(用于落子)
char message[256]; // 消息内容(用于聊天等)
time_t timestamp; // 时间戳
int type; // 消息类型
int player_id; // 玩家ID
int x, y; // 坐标(用于落子)
char message[256]; // 消息内容(用于聊天等)
time_t timestamp; // 时间戳
} NetworkMessage;
/**
@@ -87,7 +87,7 @@ typedef struct {
int local_player_id; // 本地玩家ID
int remote_player_id; // 远程玩家ID
char remote_ip[16]; // 远程IP地址(MAX_IP_LENGTH = 16
int port; // 端口号
int port; // 端口号
} NetworkGameState;
#endif // TYPE_H
+9 -2
View File
@@ -1,3 +1,10 @@
/**
* @file ui.c
* @brief
* @note 本文件定义了用户界面相关的函数和数据结构。
* 它负责处理用户输入、显示游戏界面、提示信息等与用户交互的功能。
*/
#include "ui.h"
#include "gobang.h"
#include "config.h"
@@ -123,7 +130,7 @@ void display_settings_menu()
printf("3. 计时器设置\n");
printf("4. 网络配置设置\n");
printf("5. AI难度设置\n");
printf("6. 返回主菜单\n");
printf("0. 返回主菜单\n");
printf("==================\n");
}
@@ -186,7 +193,7 @@ void display_about()
{
printf("\n===== 关于五子棋游戏 =====\n");
printf("🎮 游戏名称:五子棋人机对战\n");
printf("📦 版本:4.0\n");
printf("📦 版本:7.0\n");
printf("👨‍💻 开发者:刘航宇\n");
printf("📧 联系邮箱:3364451258@qq.com\n");
printf("🌐 项目主页:https://github.com/LHY0125/Gobang-Game\n\n");
+1
View File
@@ -4,6 +4,7 @@
* @note 本文件定义了用户界面相关的函数和数据结构。
* 它负责处理用户输入、显示游戏界面、提示信息等与用户交互的功能。
*/
#ifndef UI_H
#define UI_H