|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
กระทู้ #3547 [อื่นๆ] (จาก IP: 27.55.7.84)
code เกมส์สมสิบ c++
ช่วยทีครับ คิดไม่ออกแจกไพ่ได้แล้ว คือจะทำเกมไพ่ผสมสิบ โดยแจกไพ่ให้ผู้เล่นคนละ5ใบ แล้วดูว่ามีไพ่ใบไหนบ้างที่รวมกันได้ 10 แต้มบ้าง แล้วแสดงไพ่ที่เหลือที่รวมกันไม่ได้ 10 ถ้าไพ่ที่เหลือของใครมีแต้มน้อยที่สุดจะชนะทันที
|
จากคุณ
:
์ณัฐพงษ์ / nnattapong16@gmail.com [2015-04-06 16:44:01]
|
|
ความคิดเห็น #29222 (จาก IP: 27.55.7.84)
#include <iostream> #include <cstdlib> #include <ctime> #include <iomanip> using std::cout; using std::cin; using std::endl; using std::left; using std::right; using std::setw; void shuffle(int[][13]); void deal(const int[][13], const char *[], const char *[]); int main() { // initialize suit array const char *suit[4] = { "Hearts", "Diamonds", "Clubs", "Spades" };
// initialize face array const char *face[13] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
// initialize deck array int deck[4][13] = { 0 }; srand(time(0)); // seed random number generator shuffle(deck); deal(deck, face, suit);
return 0; // indicates successful termination
} void shuffle(int wDeck[][13]) { int row; int column;
// for each of the 52 cards, choose slot of deck randomly for (int card = 1; card <= 52; card++) {
// choose new random location until unoccupied slot found do { row = rand() % 4; column = rand() % 13; } while (wDeck[row][column] != 0); // end do/while
// place card number in chosen slot of deck wDeck[row][column] = card;
} } void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[]) { cout << "bot1 = "; // for each of the 52 cards for (int card = 1; card <= 5; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; cout << "bot2 = "; for (int card = 6; card <= 10; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; cout << "bot3 = "; for (int card = 11; card <= 15; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; cout << "bot4 = "; for (int card = 16; card <= 20; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; cout << "bot5 = "; for (int card = 21; card <= 25; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; cout << "bot6 = "; for (int card = 26; card <= 30; card++)
// loop through rows of wDeck for (int row = 0; row <= 3; row++)
// loop through columns of wDeck for current row for (int column = 0; column <= 12; column++)
// if slot contains current card, display card if (wDeck[row][column] == card) { cout << wFace[column] << " of " << wSuit[row] << ","; } cout << endl; } อันนี้คือโค้ดที่เขียนถึงแจกไพ่ครับ |
จากคุณ
:
ณัฐพงษ์ / nnattapong16@gmail.com [2015-04-06 16:48:45]
|
|
ความคิดเห็น #29223 (จาก IP: 171.96.168.30)
คิดไม่ออก ก็ไม่รู้จะช่วยยังไงให้คิดออก เอาเป็นว่าเอาเว็บข้อมูลไปดูๆและกันครับ
http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/deck-of-cards.html
http://people.cs.pitt.edu/~khalifa/cs449/spr07/Slides/7_CStructures/cardShuffle.c
ปล. เป็นมือใหม่ที่เก่งนะครับ มี comment ให้ตลอด |
จากคุณ
:
maddog [2015-04-06 19:03:17]
|
|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|