これまでのコードは、カードのデッキ、9 - ACE
各スイートの値を作成し、5 枚のカードを 4 人のプレイヤーに配ることを目的としています。カードが配られ3-2-3-2
、2-3-2-3
各プレイヤーは合計 5 枚のカードを持ちます。後で、カードをシャッフルし、ユーカー ゲームでそれらを比較するコードを記述しますが、今のところ、カードを配りたいだけです。とにかく、それは正確には機能しません。私は提案を受け付けています。私が得るエラーは「セグメンテーション違反:11」です
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;
int cards[24]; //array filled with card values
char DECK[24][25] =
{ //array filled with card names. Used for dealing //24elements long //25 characters in each element
"Ace of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades",
"Ace of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts",
"Ace of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs",
"Ace of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"
};
int main (void)
{
char P1[5][25];
char P2[5][25];
char P3[5][25];
char P4[5][25];
for( int i = 0 ; i < 24 ; ++i) // for the total amount of cards
{
for(int j = 0; j < 25; j++)
{
//1st deal 3-2-3-2
if(i < 3) // 0 - 2 // 3 cards
{
P1[i][j] = DECK[i][j];
}
if((i > 2) && (i < 5))// 3 - 4 // 2 cards
{
P2[i][j] = DECK[i][j];
}
if((i > 4) && (i < 8)) // 5 - 7 // 3 cards
{
P3[i][j] = DECK[i][j];
}
if((i > 7) && (i < 10))// 8 - 9 // 2 cards
{
P4[i][j] = DECK[i][j];
}
//2nd deal 2-3-2-3
if((i > 9) && (i < 12)) // 10 - 11 // 2 cards
{
P1[i][j] = DECK[i][j];
}
if((i > 11) && (i < 15))// 12 - 14 // 3 cards
{
P2[i][j] = DECK[i][j];
}
if((i > 14) && (i < 17)) // 15 - 16 // 2 cards
{
P3[i][j] = DECK[i][j];
}
if((i > 16) && (i < 20))// 17 - 19 // 3 cards
{
P4[i][j] = DECK[i][j];
}
}
}
for(int q = 0; q < 5; ++q)
{
cout << "P1 has the card " << P1[q]<< endl;
}
for(int q = 0; q < 5; ++q)
{
cout << "P2 has the card " << P2[q]<< endl;
}
//for(int q = 0; q < 5; ++q)
{
//cout << "P3 has the card " << P3[q]<< endl;
}
//for(int q = 0; q < 5; ++q)
{
//cout << "P4 has the card " << P4[q]<< endl;
}
return 0;
}