fix
This commit is contained in:
@@ -37,6 +37,7 @@ void DealCards(int N, SqList<int>*& PA, SqList<int>*& PB, int times)
|
|||||||
delete[] CardPile; // 释放发牌堆占用的内存
|
delete[] CardPile; // 释放发牌堆占用的内存
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 输出B的手牌
|
||||||
void DisplayPlayerBCards(int*& QB, int N)
|
void DisplayPlayerBCards(int*& QB, int N)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
@@ -45,7 +46,7 @@ void DisplayPlayerBCards(int*& QB, int N)
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPlayerBWin(int*& QB, int N)
|
bool IsPlayerAWin(int*& QB, int N)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
if (QB[i] > 0) return false;
|
if (QB[i] > 0) return false;
|
||||||
@@ -153,7 +154,7 @@ int GamePlay2(SqList<int>& PA, SqList<int>& PB, int N)
|
|||||||
winner = 2;
|
winner = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (IsPlayerBWin(QB, N))
|
else if (IsPlayerAWin(QB, N))
|
||||||
{
|
{
|
||||||
winner = 1;
|
winner = 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -43,11 +43,13 @@ void GamePlay1(SqList<int>& PA, SqList<int>& PB, int N)
|
|||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
// 双方交替出牌
|
// 双方交替出牌
|
||||||
if (i++ % 2 == 0) {
|
if (i++ % 2 == 0) // 奇数回合A出牌
|
||||||
|
{
|
||||||
DeQueue(*QA, a);
|
DeQueue(*QA, a);
|
||||||
x = a;
|
x = a;
|
||||||
}
|
}
|
||||||
else {
|
else // 偶数回合B出牌
|
||||||
|
{
|
||||||
DeQueue(*QB, b);
|
DeQueue(*QB, b);
|
||||||
x = b;
|
x = b;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using namespace std;
|
|||||||
#include "FuncRef.h"
|
#include "FuncRef.h"
|
||||||
#include "Functions.h"
|
#include "Functions.h"
|
||||||
|
|
||||||
|
// 输出B的手牌
|
||||||
void DisplayPlayerBCards(int*& QB, int N)
|
void DisplayPlayerBCards(int*& QB, int N)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
@@ -26,7 +27,7 @@ void DisplayStatus(SqQueue<int>& QA, int*& QB, SqStack<int>& Desk, int i, int N)
|
|||||||
DispStack(Desk);
|
DispStack(Desk);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPlayerBWin(int*& QB, int N)
|
bool IsPlayerAWin(int*& QB, int N)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
if (QB[i] > 0) return false;
|
if (QB[i] > 0) return false;
|
||||||
@@ -134,7 +135,7 @@ void GamePlay2(SqList<int>& PA, SqList<int>& PB, int N)
|
|||||||
cout << "Player B wins!" << endl;
|
cout << "Player B wins!" << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (IsPlayerBWin(QB, N))
|
else if (IsPlayerAWin(QB, N))
|
||||||
{
|
{
|
||||||
cout << "Player A wins!" << endl;
|
cout << "Player A wins!" << endl;
|
||||||
break;
|
break;
|
||||||
|
|||||||
BIN
ExpReportTemplate.docx
Normal file
BIN
ExpReportTemplate.docx
Normal file
Binary file not shown.
Binary file not shown.
@@ -18,12 +18,12 @@ inline void DealCards(int N, SqList<int>*& PA, SqList<int>*& PB)
|
|||||||
{
|
{
|
||||||
if (CardPile[num] != 0) // 如果该数对应面值的牌未发完
|
if (CardPile[num] != 0) // 如果该数对应面值的牌未发完
|
||||||
{
|
{
|
||||||
if (i % 2 == 0) // 发给PA
|
if (i % 2 == 0) // 如果发牌次数(i+1)为奇数,则发给PA
|
||||||
{
|
{
|
||||||
InsertElem_i(*PA, j++, num + 1);
|
InsertElem_i(*PA, j++, num + 1);
|
||||||
CardPile[num]--;
|
CardPile[num]--;
|
||||||
}
|
}
|
||||||
else // 发给PB
|
else // 否则发给PB
|
||||||
{
|
{
|
||||||
InsertElem_i(*PB, k++, num + 1);
|
InsertElem_i(*PB, k++, num + 1);
|
||||||
CardPile[num]--;
|
CardPile[num]--;
|
||||||
@@ -49,10 +49,4 @@ inline int FindElem(SqStack<int>& S, int e)
|
|||||||
inline bool IsPlayerA(int i)
|
inline bool IsPlayerA(int i)
|
||||||
{
|
{
|
||||||
return i % 2 == 1;
|
return i % 2 == 1;
|
||||||
}
|
|
||||||
|
|
||||||
// 返回栈元素数量
|
|
||||||
inline int StackSize(SqStack<int>& S)
|
|
||||||
{
|
|
||||||
return S.top + 1;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user