diff --git a/.gitignore b/.gitignore
index 648b64a..6c2d4cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,10 @@
+Report/
+Report.docx
+Report.pdf
+SimilarityDetectionReport.pdf
+AIGCDetectionReport.pdf
+Final/
+
### C++ ###
# Prerequisites
*.d
diff --git a/Build.bat b/Build.bat
index c7086b2..5ba228d 100644
--- a/Build.bat
+++ b/Build.bat
@@ -1,4 +1,5 @@
@echo off
+chcp 65001
set "MSBUILD_PATH="
for /f "delims=" %%i in ('where /r "C:\Program Files\Microsoft Visual Studio" msbuild.exe') do (
set "MSBUILD_PATH=%%i"
diff --git a/CardGame.Test.GamePlay1/CardGame.Test.GamePlay1.vcxproj b/CardGame.Test.GamePlay1/CardGame.Test.GamePlay1.vcxproj
index d02b97d..1cafb1a 100644
--- a/CardGame.Test.GamePlay1/CardGame.Test.GamePlay1.vcxproj
+++ b/CardGame.Test.GamePlay1/CardGame.Test.GamePlay1.vcxproj
@@ -107,6 +107,7 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ /utf-8 %(AdditionalOptions)
Console
diff --git a/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.cpp b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.cpp
new file mode 100644
index 0000000..aa406f0
--- /dev/null
+++ b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.cpp
@@ -0,0 +1,205 @@
+#include
+using namespace std;
+#include "SqList.h"
+#include "SqQueue.h"
+#include "SqStack.h"
+#include "Functions.h"
+
+// 发牌
+void DealCards(int N, SqList*& PA, SqList*& PB, int times)
+{
+ int* CardPile = new int[N]; // 发牌堆
+ srand((int)time(nullptr) + times); // 基于当前时间和游玩次数(对于测试代码,多次测试可能在同一秒完成)设置随机数种子
+ for (int i = 0; i < N; i++) CardPile[i] = 2; // 默认情况下每个面值有两张牌
+ for (int i = 0; i < N * 2; i++)
+ {
+ int j = 1, k = 1;
+ int num = rand() % N; // 获取一个 0~N-1 的随机数
+ while (true)
+ {
+ if (CardPile[num] != 0) // 如果该数对应面值的牌未发完
+ {
+ if (i % 2 == 0) // 发给PA
+ {
+ InsertElem_i(*PA, j++, num + 1);
+ CardPile[num]--;
+ }
+ else // 发给PB
+ {
+ InsertElem_i(*PB, k++, num + 1);
+ CardPile[num]--;
+ }
+ break;
+ }
+ else num = (num + 1) % N; // 若发完则检查下一位数字对应面值的牌
+ }
+ }
+ delete[] CardPile; // 释放发牌堆占用的内存
+}
+
+// 输出B的手牌
+void DisplayPlayerBCards(int*& QB, int N)
+{
+ for (int i = 0; i < N; i++)
+ for (int j = 0; j < QB[i]; j++)
+ cout << i + 1 << " ";
+ cout << endl;
+}
+
+bool IsPlayerAWin(int*& QB, int N)
+{
+ for (int i = 0; i < N; i++)
+ if (QB[i] > 0) return false;
+ return true;
+}
+
+// 玩家B出牌
+int PlayerBPlay(int*& QB, SqStack& Desk, int N)
+{
+ // 如果栈为空,且B有两张相同面值的牌,则出该面值的牌
+ if (StackEmpty(Desk))
+ for (int i = 1; i <= N; i++)
+ if (QB[i - 1] == 2)
+ return i;
+ // 如果栈非空,则从栈底遍历,找到第一张手牌中拥有的牌出之
+ for (int i = 0; i <= Desk.top; i++)
+ {
+ int card = Desk.base[i];
+ if (QB[card - 1] > 0)
+ return card;
+ }
+ // 如果以上情况都不满足,则随机出一张牌
+ int card;
+ do
+ card = rand() % N + 1;
+ while (QB[card - 1] == 0);
+ return card;
+}
+
+int GamePlay2(SqList& PA, SqList& PB, int N)
+{
+ int winner = 0;
+ SqStack* Desk = new SqStack; // 牌桌上的牌
+ InitStack(*Desk, N * 2 + 1);
+ // 玩法2初始化
+ // 对于玩法2,PA为先抓到的牌先出,赢的牌加在牌尾;PB为任意出牌
+ SqQueue* QA = new SqQueue;
+ InitQueue(*QA, N * 2 + 1);
+ // PB手牌存储方式:下标为面值-1,值为张数
+ int* QB = new int[N];
+ for (int i = 0; i < N; i++) QB[i] = 0;
+ // 将PA的牌放入QA
+ for (int i = 1; i <= N; i++)
+ {
+ int e = 0;
+ GetElem_i(PA, i, e);
+ EnQueue(*QA, e);
+ }
+ // 将PB的牌放入QB
+ for (int i = 1; i <= N; i++)
+ {
+ int e = 0;
+ GetElem_i(PB, i, e);
+ QB[e - 1]++;
+ }
+ // Step2 玩牌
+ int a = 0, b = 0, i = 0; // i的奇偶性决定出牌方
+ while (true)
+ {
+ int x = 0;
+ // 双方交替出牌
+ if (i++ % 2 == 0) {
+ DeQueue(*QA, a);
+ x = a;
+ }
+ else {
+ b = PlayerBPlay(QB, *Desk, N);
+ QB[b - 1]--;
+ x = b;
+ }
+ // 如果桌面上没有面值为X的牌,则将牌放到牌桌上
+ if (FindElem(*Desk, x) == -1) Push(*Desk, x);
+ // 如果桌面上有面值为X的牌
+ else
+ {
+ int times = FindElem(*Desk, x);
+ if (IsPlayerA(i)) // 如果是A出的牌
+ {
+ // 将X放入牌尾
+ EnQueue(*QA, x);
+ // 将桌面上直到X的牌依次放入牌尾
+ for (int j = 0; j <= times; j++)
+ {
+ int e = 0;
+ Pop(*Desk, e);
+ EnQueue(*QA, e);
+ }
+ }
+ else // 如果是B出的牌
+ {
+ // 将X放入手牌
+ QB[x - 1]++;
+ // 将桌面上直到X的牌依次放入手牌
+ for (int j = 0; j <= times; j++)
+ {
+ int e = 0;
+ Pop(*Desk, e);
+ QB[e - 1]++;
+ }
+ }
+ }
+ // 判断是否有一方获胜
+ if (QueueEmpty(*QA))
+ {
+ winner = 2;
+ break;
+ }
+ else if (IsPlayerAWin(QB, N))
+ {
+ winner = 1;
+ break;
+ }
+ }
+ DestroyStack(*Desk);
+ DestroyQueue(*QA);
+ delete Desk;
+ delete QA;
+ delete[] QB;
+ return winner;
+}
+
+int main()
+{
+ int counts;
+ cout << "Enter after how many times A win the program stops: ";
+ cin >> counts;
+ int i = 0;
+ int N = 9;
+ int flag = 0;
+ while (true)
+ {
+ i++;
+ SqList* PA = new SqList; // PA的手牌
+ InitList(*PA, N);
+ SqList* PB = new SqList; // PB的手牌
+ InitList(*PB, N);
+ DealCards(N, PA, PB, i);
+ int result = GamePlay2(*PA, *PB, N);
+ if (result == 1)
+ {
+ cout << "-----------------" << endl;
+ DispList(*PA);
+ DispList(*PB);
+ flag++;
+ }
+ DestroyList(*PA);
+ DestroyList(*PB);
+ delete PA;
+ delete PB;
+ if (flag == counts)
+ {
+ cout << "Totally run " << i << " times." << endl;
+ break;
+ }
+ }
+}
\ No newline at end of file
diff --git a/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj
new file mode 100644
index 0000000..fa8760f
--- /dev/null
+++ b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj
@@ -0,0 +1,145 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ Win32Proj
+ {029c5a36-ca7e-4ee4-afa9-873f937689a4}
+ CardGameTestGamePlay2WhenPlayerAWins
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ..\include;$(IncludePath)
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj.filters b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj.filters
new file mode 100644
index 0000000..62f375c
--- /dev/null
+++ b/CardGame.Test.GamePlay2.WhenPlayerAWins/CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj.filters
@@ -0,0 +1,36 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ 头文件
+
+
+ 头文件
+
+
+ 头文件
+
+
+ 头文件
+
+
+
+
+ 源文件
+
+
+
\ No newline at end of file
diff --git a/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.cpp b/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.cpp
index 98b59dd..826abb0 100644
--- a/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.cpp
+++ b/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.cpp
@@ -5,6 +5,31 @@ using namespace std;
#include "SqStack.h"
#include "Functions.h"
+// 计算两张面值相同的牌在同一个人的手牌中的情况
+int CalcTwoCardsWithSameNumInOnePlayersPile(SqList& PA, SqList& PB, int N)
+{
+ int count = 0;
+ int* QA = new int[N];
+ int* QB = new int[N]; for (int i = 0; i < N; i++) QA[i] = QB[i] = 0;
+ for (int i = 1; i <= N; i++)
+ {
+ int e = 0;
+ GetElem_i(PA, i, e);
+ QA[e - 1]++;
+ int f = 0;
+ GetElem_i(PB, i, f);
+ QB[f - 1]++;
+ }
+ for (int i = 0; i < N; i++)
+ {
+ if (QA[i] == 2) count++;
+ if (QB[i] == 2) count++;
+ }
+ delete[] QA;
+ delete[] QB;
+ return count;
+}
+
// 发牌
void DealCards(int N, SqList*& PA, SqList*& PB, int times)
{
@@ -176,6 +201,7 @@ int main()
int N = 9;
int PlayerAWinCount = 0, PlayerBWinCount = 0;
int RealCounts = counts;
+ int TwoCardsWithSameNumInOnePlayersPileA = 0, TwoCardsWithSameNumInOnePlayersPileB = 0;
for (int i = 0; i < counts; i++)
{
SqList* PA = new SqList; // PA的手牌
@@ -184,18 +210,28 @@ int main()
InitList(*PB, N);
DealCards(N, PA, PB, i);
int result = GamePlay2(*PA, *PB, N);
+ if (result == 1)
+ {
+ PlayerAWinCount++;
+ TwoCardsWithSameNumInOnePlayersPileA += CalcTwoCardsWithSameNumInOnePlayersPile(*PA, *PB, N);
+ }
+ else if (result == 2)
+ {
+ PlayerBWinCount++;
+ TwoCardsWithSameNumInOnePlayersPileB += CalcTwoCardsWithSameNumInOnePlayersPile(*PA, *PB, N);
+ }
+ else RealCounts--;
DestroyList(*PA);
DestroyList(*PB);
delete PA;
delete PB;
- if (result == 1) PlayerAWinCount++;
- else if (result == 2) PlayerBWinCount++;
- else RealCounts--;
}
double PlayerAWinRate = (double)PlayerAWinCount / RealCounts;
double PlayerBWinRate = (double)PlayerBWinCount / RealCounts;
cout << "Test Result:\n";
cout << "Total test counts: " << RealCounts << endl;
cout << "Player A wins: " << PlayerAWinCount << " times, rate: " << PlayerAWinRate * 100 << "%" << endl;
+ cout << "Average number of two cards with same number in one player's pile: " << (double)TwoCardsWithSameNumInOnePlayersPileA / PlayerAWinCount << endl;
cout << "Player B wins: " << PlayerBWinCount << " times, rate: " << PlayerBWinRate * 100 << "%" << endl;
+ cout << "Average number of two cards with same number in one player's pile: " << (double)TwoCardsWithSameNumInOnePlayersPileB / PlayerBWinCount << endl;
}
\ No newline at end of file
diff --git a/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.vcxproj b/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.vcxproj
index a359c73..8a825ae 100644
--- a/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.vcxproj
+++ b/CardGame.Test.GamePlay2/CardGame.Test.GamePlay2.vcxproj
@@ -107,6 +107,7 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ /utf-8 %(AdditionalOptions)
Console
diff --git a/CardGame.sln b/CardGame.sln
index 3743fb0..5abbfed 100644
--- a/CardGame.sln
+++ b/CardGame.sln
@@ -9,6 +9,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CardGame.Test.GamePlay1", "
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CardGame.Test.GamePlay2", "CardGame.Test.GamePlay2\CardGame.Test.GamePlay2.vcxproj", "{6383C4B6-1282-4F20-864A-7208EC5805CA}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "杂项", "杂项", "{8CC18327-DB10-409C-B35B-3CE741ECBF57}"
+ ProjectSection(SolutionItems) = preProject
+ MultipleAttemptsTestResult.txt = MultipleAttemptsTestResult.txt
+ TaskInfo.md = TaskInfo.md
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CardGame.Test.GamePlay2.WhenPlayerAWins", "CardGame.Test.GamePlay2.WhenPlayerAWins\CardGame.Test.GamePlay2.WhenPlayerAWins.vcxproj", "{029C5A36-CA7E-4EE4-AFA9-873F937689A4}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -41,6 +49,14 @@ Global
{6383C4B6-1282-4F20-864A-7208EC5805CA}.Release|x64.Build.0 = Release|x64
{6383C4B6-1282-4F20-864A-7208EC5805CA}.Release|x86.ActiveCfg = Release|Win32
{6383C4B6-1282-4F20-864A-7208EC5805CA}.Release|x86.Build.0 = Release|Win32
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Debug|x64.ActiveCfg = Debug|x64
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Debug|x64.Build.0 = Debug|x64
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Debug|x86.ActiveCfg = Debug|Win32
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Debug|x86.Build.0 = Debug|Win32
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Release|x64.ActiveCfg = Release|x64
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Release|x64.Build.0 = Release|x64
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Release|x86.ActiveCfg = Release|Win32
+ {029C5A36-CA7E-4EE4-AFA9-873F937689A4}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/CardGame/CardGame.vcxproj b/CardGame/CardGame.vcxproj
index 6024606..49fbd03 100644
--- a/CardGame/CardGame.vcxproj
+++ b/CardGame/CardGame.vcxproj
@@ -107,6 +107,7 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ /utf-8 %(AdditionalOptions)
Console
diff --git a/ExpReportTemplate.docx b/ExpReportTemplate.docx
deleted file mode 100644
index 06143b6..0000000
Binary files a/ExpReportTemplate.docx and /dev/null differ