final
This commit is contained in:
@@ -5,6 +5,31 @@ using namespace std;
|
||||
#include "SqStack.h"
|
||||
#include "Functions.h"
|
||||
|
||||
// 计算两张面值相同的牌在同一个人的手牌中的情况
|
||||
int CalcTwoCardsWithSameNumInOnePlayersPile(SqList<int>& PA, SqList<int>& 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<int>*& PA, SqList<int>*& 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<int>* PA = new SqList<int>; // 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;
|
||||
}
|
||||
@@ -107,6 +107,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
Reference in New Issue
Block a user