Update C code projects and configurations
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
# 排除IDE配置文件
|
||||
.idea/
|
||||
.vscode/
|
||||
.vs/
|
||||
|
||||
# 排除Trae AI配置文件
|
||||
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE"
|
||||
],
|
||||
"compilerPath": "D:/Program Files/mingw64/bin/gcc.exe",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"compilerArgs": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wshadow",
|
||||
"-fsanitize=address",
|
||||
"-g3"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "d:/Code/C_code/.trae/rules",
|
||||
"program": "d:/Code/C_code/.trae/rules/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "c17",
|
||||
"C_Cpp_Runner.cppStandard": "c++17",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"files.associations": {
|
||||
"*.gbk": "cpp",
|
||||
"stdlib.h": "c",
|
||||
"game_mode.h": "c",
|
||||
"windows.h": "c",
|
||||
"stdio.h": "c",
|
||||
"stat.h": "c",
|
||||
"init_board.h": "c",
|
||||
"init.h": "c",
|
||||
"record.h": "c",
|
||||
"ai.h": "c",
|
||||
"string.h": "c",
|
||||
"direct.h": "c"
|
||||
}
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks":
|
||||
[
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "C/C++: gcc.exe 生成活动文件",
|
||||
"command": "D:\\Program Files\\mingw64\\bin\\gcc.exe",
|
||||
"args":
|
||||
[
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-std=c++17",
|
||||
"-fsanitize=address",
|
||||
"-static-libasan"
|
||||
],
|
||||
"options": {"cwd": "${fileDirname}"},
|
||||
"problemMatcher": ["$gcc"],
|
||||
"group": {"kind": "build","isDefault": true},
|
||||
"detail": "调试器生成的任务。"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
@@ -16,6 +16,4 @@ int main()
|
||||
}
|
||||
printf("%d\n",n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+6
-2
@@ -9,9 +9,13 @@
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
// !链表
|
||||
// !链表的清除
|
||||
/*
|
||||
1.
|
||||
1. 清除链表中的所有节点
|
||||
2. 释放链表占用的内存
|
||||
2.1 使用malloc申请的动态内存需要释放
|
||||
2.2 用malloc申请的内存,即使没有赋值,也会被赋值一个特定的值
|
||||
赋值就是使用,所以没必要为这种内存清空赋值
|
||||
*/
|
||||
|
||||
typedef struct _node{
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# 代码改进建议
|
||||
编译再次成功。既然代码已经没有编译问题,我将对代码提出一些改进建议,以提高其质量和可维护性。
|
||||
1. 全局变量问题 :大量使用全局变量(如 board , step_count 等)会使代码难以理解和维护。状态的改变可能发生在任何地方,增加了调试难度。建议将这些变量封装到一个 GameState 结构体中,并通过函数参数传递这个结构体的指针。
|
||||
2. 代码结构 :目前 gobang.h 包含了游戏核心逻辑和AI逻辑的声明,而 game_mode.h 包含了游戏模式的声明。可以考虑将AI相关的函数声明(如 evaluate_pos , dfs , ai_move )分离到一个新的头文件 ai.h 中,使其职责更清晰。
|
||||
3. 魔法数字 :代码中使用了一些“魔法数字”,例如在 handle_player_turn 中使用 -1 , -2 , -3 作为特殊输入的标识。最好使用 enum 或 #define 为这些数字定义有意义的名称,例如 INPUT_UNDO , INPUT_SAVE , INPUT_EXIT 。
|
||||
4. 输入处理 : handle_player_turn 函数中的输入处理逻辑比较复杂,可以考虑将其拆分为更小的函数,例如一个专门用于解析用户输入的函数。
|
||||
5. 函数长度 : gobang.c 中的一些函数可能过长,特别是AI相关的函数。将它们分解为更小的、功能单一的函数可以提高可读性。
|
||||
6. 错误处理 :文件操作(如 save_game , load_game )可以增加更健壮的错误处理,例如检查 fopen 的返回值,并在失败时向用户提供明确的错误信息。
|
||||
7. 代码注释 :虽然代码中有一些注释,但可以对复杂的算法(如AI的评估函数 evaluate_pos 和 dfs )添加更详细的注释,解释其工作原理和设计决策。
|
||||
BIN
Binary file not shown.
@@ -1,13 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
long int n;
|
||||
scanf("%ld", &n);
|
||||
long m;
|
||||
scanf("%ld", &m);
|
||||
long long int a[n];
|
||||
long long b;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
double a, b, c;
|
||||
scanf("%lf %lf", &a, &b);
|
||||
c = a / b;
|
||||
printf("%.0f/%.0f=%.2f\n", a, b, c);
|
||||
|
||||
return 0;
|
||||
@@ -1,26 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int max(int a, int b);
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b,c;
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
c = max(a, b);
|
||||
|
||||
printf("%d和%d的最大数是%d", a, b, c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max(int a, int b)
|
||||
{
|
||||
int c = a;
|
||||
|
||||
if (a<b)
|
||||
{
|
||||
c = b;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int sign = 1;
|
||||
int n;
|
||||
printf("ÇëÊäÈën: ");
|
||||
scanf("%d", &n);
|
||||
double deno = 2.0, sum = 1.0, term;
|
||||
|
||||
while (deno <= n)
|
||||
{
|
||||
sign = -sign;
|
||||
term = sign / deno;
|
||||
sum = sum + term;
|
||||
deno = deno + 1;
|
||||
}
|
||||
printf("%f\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c = 'Y';
|
||||
putchar(66); // B
|
||||
putchar('O'); // O
|
||||
putchar(c); // Y
|
||||
putchar('\n');
|
||||
|
||||
char a, b;
|
||||
a = getchar();
|
||||
b = getchar();
|
||||
putchar(a);
|
||||
putchar(b);
|
||||
|
||||
putchar(getchar());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c1, c2;
|
||||
printf("请输入一个大写字母");
|
||||
c1 = getchar();
|
||||
c2 = c1 + 32;
|
||||
printf("转换后的小写字母为");
|
||||
putchar(c2);
|
||||
putchar('\n');
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b, c;
|
||||
a = b = c = 0;
|
||||
a++ &&b++ | c++;
|
||||
printf("%d,%d,%d\n",a,b,c);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
double a, b,c;
|
||||
printf("输入你的体重(kg)和你的身高(cm)\n");
|
||||
scanf("%lf %lf",&a,&b);
|
||||
|
||||
b /= 100;
|
||||
c=a/(b*b);
|
||||
|
||||
if(c< 18)
|
||||
{
|
||||
printf("BMI是%.2f,你太轻了\n",c);
|
||||
}
|
||||
else if (c > 24)
|
||||
{
|
||||
printf("BMI是%.2f,你有点胖\n",c);
|
||||
}
|
||||
else if (18 <= c && c <= 24)
|
||||
{
|
||||
printf("BMI是%.2f,你的体重正常\n",c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user