From fc638a00bbc6e1aa1c98334cf852e9285676e3ce Mon Sep 17 00:00:00 2001 From: KILNETA <47145154+KILNETA@users.noreply.github.com> Date: Thu, 17 Jun 2021 01:04:22 +0800 Subject: [PATCH] Robot v1.0 Robot v1.0 --- Main.cpp | 3 +- MultiplayerGame.cpp | 131 +++++++++++++++++++++++++++++++++++++------- Player.cpp | 8 +++ Player.h | 3 + 4 files changed, 122 insertions(+), 23 deletions(-) diff --git a/Main.cpp b/Main.cpp index cfadd1f..a8113ee 100644 --- a/Main.cpp +++ b/Main.cpp @@ -16,11 +16,10 @@ using namespace std; int main() { - _getch(); Title(); - PlaySound(L"Music\\MainScreen_JazzSong.WAV", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); while (1) { + PlaySound(L"Music\\MainScreen_JazzSong.WAV", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); switch (MainScreen()) { case 1:break;//單 人 遊 戲 diff --git a/MultiplayerGame.cpp b/MultiplayerGame.cpp index af5f570..59a3c01 100644 --- a/MultiplayerGame.cpp +++ b/MultiplayerGame.cpp @@ -268,6 +268,7 @@ void ShowPlayerCard(int playerNumber) { string species[] = { "紅心","方塊","梅花","黑桃" }; string ranks[] = { "A","2","3","4","5","6","7","8","9","10","J","Q","K" }; + if (player[playerNumber].getBot() == true){return;} for (int i = 0; i < 2; i++) { @@ -335,32 +336,29 @@ int ShowWinner() { if(!player[j].getFold()) { - for (int i = 0; i < 5; i++) + if (nowWinnerPlayerMaxWinMode < player[j].getMaxWinMode()) { - if (nowWinnerPlayerMaxWinMode < player[j].getMaxWinMode()) + nowWinnerPlayerNumber = j ; + nowWinnerPlayerMaxWinMode = player[j].getMaxWinMode(); + for(int i=0;i<5;i++) { - nowWinnerPlayerNumber = j ; - nowWinnerPlayerMaxWinMode = player[j].getMaxWinMode(); - for(int i=0;i<5;i++) - { - nowWinnerPlayerMaxWinNumber[i] = player[j].getMaxWinNumber(i); - } + nowWinnerPlayerMaxWinNumber[i] = player[j].getMaxWinNumber(i); } - else - { - if (nowWinnerPlayerMaxWinMode == player[j].getMaxWinMode()) + } + else + { + if (nowWinnerPlayerMaxWinMode == player[j].getMaxWinMode()) + { + for (int i = 0; i < 5; i++) { - for (int i = 0; i < 5; i++) + if (nowWinnerPlayerMaxWinNumber[i] < player[j].getMaxWinNumber(i)) { - if (nowWinnerPlayerMaxWinNumber[i] < player[j].getMaxWinNumber(i)) + nowWinnerPlayerNumber = j; + for (int f = 0; f < 5; f++) { - nowWinnerPlayerNumber = j ; - for (int f = 0; f < 5; f++) - { - nowWinnerPlayerMaxWinNumber[f] = player[j].getMaxWinNumber(f); - } - break; + nowWinnerPlayerMaxWinNumber[f] = player[j].getMaxWinNumber(f); } + break; } } } @@ -461,7 +459,7 @@ void CheckCard(vector Cards,int playerNumber) int flush = 0, straight = 0, four_of_a_kind = 0, three_of_a_king = 0, i; int pair = 0, count = 0, a_straight = 0, start, end=0; int kind[4] = { 0 }, scard[13] = {}; // 4種花色 13個卡號 - int compareNum[5] = {}; + int compareNum[5] = {-1,-1,-1,-1,-1}; Card Cards_2[5]={}; for (i = 0; i < 5; i++) @@ -521,7 +519,7 @@ void RecordingMaxWinNumber(int* compareNum,int cardNumber) { for (int i=0;i<5;i++) { - if (*(compareNum + i) == 0) + if (*(compareNum + i) == -1) { *(compareNum + i) = cardNumber; return; @@ -616,6 +614,73 @@ void PlayerOperating(int playerNumber) gotoxyGame(x + 79, y + 24); while(1){ if (player[playerNumber].getFold()){return;}//此玩家已棄牌 + if (player[playerNumber].getBot() == true) + { + while(1) + { + int num = rand() % 10 + 1; + if (num==1|| num == 2) + { //加 注 + LastBet = LastBet * 2; + AllBet += LastBet; + gotoxyGame(x + 38, y + 15); cout << ">"; + player[playerNumber].setEnd(true); + player[playerNumber].setLastOperation(1); + if (AllBetExplosion) { return; } + gotoxyGame(x + 38, y + 15); cout << " "; + PreviousplayerNumber = playerNumber; + return; + } + if (num == 3 || num == 4|| num == 5 || num == 6 || num == 7) + { //跟 注 + gotoxyGame(x + 38, y + 17); cout << ">"; + AllBet += LastBet; + gotoxyGame(x + 39, y + 23); cout << "彩池:" << right << setw(8) << AllBet << " $"; + gotoxyGame(x + 39, y + 17); + player[playerNumber].setLastOperation(2); + AllBetExplosionVerification(); + if (AllBetExplosion) { return; } + gotoxyGame(x + 38, y + 17); cout << " "; + PreviousplayerNumber = playerNumber; + return; + } + if (num == 8 || num == 9) + { //過 牌 + if (PreviousplayerNumber != -1) + { + if (player[PreviousplayerNumber].getLastOperation() != 1 && First_lap) + { + gotoxyGame(x + 38, y + 19); cout << ">"; + player[playerNumber].setLastOperation(3); + gotoxyGame(x + 38, y + 19); cout << " "; + PreviousplayerNumber = playerNumber; + return; + } + } + else + { + gotoxyGame(x + 38, y + 17); cout << ">"; + AllBet += LastBet; + gotoxyGame(x + 39, y + 23); cout << "彩池:" << right << setw(8) << AllBet << " $"; + gotoxyGame(x + 39, y + 17); + player[playerNumber].setLastOperation(2); + AllBetExplosionVerification(); + if (AllBetExplosion) { return; } + gotoxyGame(x + 38, y + 17); cout << " "; + PreviousplayerNumber = playerNumber; + return; + } + } + if (num == 10) + { //蓋 牌 + gotoxyGame(x + 38, y + 21); cout << ">"; + player[playerNumber].Folding(); + gotoxyGame(x + 38, y + 21); cout << " "; + PreviousplayerNumber = playerNumber; + return; + } + } + } switch (_getch()) { case 114://加 注 @@ -688,6 +753,29 @@ void PlayerBlind(int playerNumber,int Blind) break; } while (1) { + if (player[playerNumber].getBot() == true) + { + if (Blind == 1) + { + gotoxyGame(x + 38, y + 15); cout << ">"; + LastBet = LastBet + 20; + AllBet += LastBet; + player[playerNumber].setLastOperation(4); + gotoxyGame(x + 38, y + 15); cout << " "; + Blind++; + return; + } + else//大 盲 注 + { + gotoxyGame(x + 38, y + 15); cout << ">"; + player[playerNumber].setLastOperation(5); + LastBet *= 2; + AllBet += LastBet; + gotoxyGame(x + 38, y + 15); cout << " "; + Blind++; + return; + } + } if(_getch()== 98) { if (Blind == 1) @@ -717,6 +805,7 @@ void PlayerBlind(int playerNumber,int Blind) //驗證 void Verification(int playerNumber) { + if (player[playerNumber].getBot() == true) { return; } if (player[playerNumber].getFold()) { return; } srand(time(0)); //取時間 int verificationNumber = (rand()%36)+1; diff --git a/Player.cpp b/Player.cpp index d4c68aa..e09a9fc 100644 --- a/Player.cpp +++ b/Player.cpp @@ -77,6 +77,10 @@ void Player::Folding() { Fold = true; } +void Player::setBot() +{ + bot = true; +} int Player::getCardNumber(int num) @@ -119,4 +123,8 @@ bool Player::getEnd() bool Player::getFold() { return Fold; +} +bool Player::getBot() +{ + return bot; } \ No newline at end of file diff --git a/Player.h b/Player.h index 291bf81..2d2b1ed 100644 --- a/Player.h +++ b/Player.h @@ -13,6 +13,7 @@ class Player int LastOperation = -1; bool End = false; bool Fold = false; + bool bot = true; bool CalculationMaxWinNumber(int[]); void ArrangeCards(); @@ -25,6 +26,7 @@ class Player void setLastOperation(int); void setEnd(bool); void Folding(); + void setBot(); int getCardNumber(int); int getCardSpecies(int); @@ -36,6 +38,7 @@ class Player int getLastOperation(); bool getEnd(); bool getFold(); + bool getBot(); };