質問編集履歴
1
ソースコードの削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,230 +1 @@
|
|
1
|
-
|
2
|
-
こちらのソースコードをcurses化させて動かしたいのですが、どうすればいいんでしょうか?
|
3
|
-
|
4
|
-
|
5
|
-
#include <stdio.h>
|
6
|
-
#include <stdlib.h>
|
7
|
-
#include <string.h>
|
8
|
-
|
9
|
-
typedef struct Card_ {
|
10
|
-
int face;
|
11
|
-
int suit;
|
12
|
-
} Card;
|
13
|
-
|
14
|
-
enum {
|
15
|
-
HIGH_CARDS,
|
16
|
-
ONE_PAIR,
|
17
|
-
TWO_PAIR,
|
18
|
-
THREE_OF_A_KIND,
|
19
|
-
STRAIGHT,
|
20
|
-
FLUSH,
|
21
|
-
FULL_HOUSE,
|
22
|
-
FOUR_OF_A_KIND,
|
23
|
-
STRAIGHT_FLUSH,
|
24
|
-
};
|
25
|
-
|
26
|
-
void initCardDeck(Card *Deck)
|
27
|
-
{
|
28
|
-
int i,j,k =0;
|
29
|
-
|
30
|
-
for(i=0;i<4;i++)
|
31
|
-
{
|
32
|
-
for(j=0;j<13;j++)
|
33
|
-
{
|
34
|
-
Deck[ k ].suit = i;
|
35
|
-
Deck[ k ].face = j;
|
36
|
-
k++;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
void shuffleCardDeck(Card *Deck)
|
42
|
-
{
|
43
|
-
long randNum1,randNum2;
|
44
|
-
Card tmp;
|
45
|
-
int i;
|
46
|
-
|
47
|
-
for(i=0;i<100;i++)
|
48
|
-
{
|
49
|
-
randNum1 = rand() % 52;
|
50
|
-
randNum2 = rand() % 52;
|
51
|
-
|
52
|
-
tmp = Deck[randNum1];
|
53
|
-
Deck[randNum1] = Deck[randNum2];
|
54
|
-
Deck[randNum2] = tmp;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
// 役の取得処理
|
59
|
-
// [戻り値]
|
60
|
-
|
1
|
+
回答者様達の回答によりやるきがなくなってしまったので、元の質問、ソースコードは削除しておきます。
|
61
|
-
// 5:フラッシュ 6:フルハウス 7:フォーカード 8:ストレートフラッシュ
|
62
|
-
int getCategories( Card* hand )
|
63
|
-
{
|
64
|
-
int suit[ 4 ];
|
65
|
-
int face[ 13 + 1 ];
|
66
|
-
int i, j, k, pair;
|
67
|
-
|
68
|
-
// 変数初期化
|
69
|
-
memset( suit, 0x00, sizeof( suit ) );
|
70
|
-
memset( face, 0x00, sizeof( face ) );
|
71
|
-
pair = 0;
|
72
|
-
|
73
|
-
// 手札の内容を分解
|
74
|
-
for( i = 0; i < 5; i++ )
|
75
|
-
{
|
76
|
-
suit[ hand[ i ].suit ]++;
|
77
|
-
face[ hand[ i ].face ]++;
|
78
|
-
}
|
79
|
-
|
80
|
-
// ストレート判定用ワークを作成
|
81
|
-
face[ 13 ] = face[ 0 ];
|
82
|
-
|
83
|
-
// フラッシュ判定
|
84
|
-
for( i = 0; i < 4; i++ )
|
85
|
-
{
|
86
|
-
if( 5 == suit[ i ] )
|
87
|
-
{
|
88
|
-
return FLUSH;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
// ワンペア,ツーペア,スリーカード,フォーカード判定
|
93
|
-
for( i = 0; i < 13; i++ )
|
94
|
-
{
|
95
|
-
if( 2 == face[ i ] )
|
96
|
-
{
|
97
|
-
pair++;
|
98
|
-
}
|
99
|
-
if( 3 == face[ i ] )
|
100
|
-
{
|
101
|
-
return THREE_OF_A_KIND;
|
102
|
-
}
|
103
|
-
if( 4 == face[ i ] )
|
104
|
-
{
|
105
|
-
return FOUR_OF_A_KIND;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
if( 1 == pair )
|
109
|
-
{
|
110
|
-
return ONE_PAIR;
|
111
|
-
}
|
112
|
-
if( 2 == pair )
|
113
|
-
{
|
114
|
-
return TWO_PAIR;
|
115
|
-
}
|
116
|
-
|
117
|
-
// ストレート判定
|
118
|
-
for( i = 0; i < 10; i++ )
|
119
|
-
{
|
120
|
-
k = 0;
|
121
|
-
for( j = 0; j < 5; j++ )
|
122
|
-
{
|
123
|
-
if( 1 == face[ i + j ] )
|
124
|
-
{
|
125
|
-
k++;
|
126
|
-
}
|
127
|
-
else
|
128
|
-
{
|
129
|
-
break;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
if( 5 == k )
|
133
|
-
{
|
134
|
-
return STRAIGHT;
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
// ブタ
|
139
|
-
return HIGH_CARDS;
|
140
|
-
}
|
141
|
-
|
142
|
-
void dispHand( Card* hand )
|
143
|
-
{
|
144
|
-
char *face[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
|
145
|
-
char *suit[4] = {"SPADE","HEART","CLOVER","DIA"};
|
146
|
-
int i;
|
147
|
-
|
148
|
-
for(i=0;i<5;i++)
|
149
|
-
{
|
150
|
-
printf( "%d...%s:%s\n", i, suit[ hand[ i ].suit ], face[ hand[ i ].face ] );
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
|
155
|
-
int main( int argc, char *argv[] )
|
156
|
-
{
|
157
|
-
int start, num1;
|
158
|
-
Card hand[ 5 ];
|
159
|
-
Card deck[ 52 ];
|
160
|
-
int pos;
|
161
|
-
int i, j, k, x, yaku;
|
162
|
-
char *categories [] = { "なし", "ワンペア", "ツーペア",
|
163
|
-
"スリーカード", "ストレート", "フラッシュ",
|
164
|
-
"フルハウス", "フォーカード",
|
165
|
-
"ストレートフラッシュ" };
|
166
|
-
|
167
|
-
printf("ゲームを開始します よろしいですか? YES...0 NO...1\n");
|
168
|
-
scanf("%d",&start);
|
169
|
-
if(start == 1)
|
170
|
-
{
|
171
|
-
return 0;
|
172
|
-
}
|
173
|
-
|
174
|
-
// 乱数初期化
|
175
|
-
srand( ( unsigned )time( NULL ) );
|
176
|
-
|
177
|
-
// 山札の初期化とシャッフル
|
178
|
-
initCardDeck( deck );
|
179
|
-
shuffleCardDeck( deck );
|
180
|
-
pos = 0;
|
181
|
-
|
182
|
-
//手札を配る
|
183
|
-
for( i = 0; i < 5; i++ )
|
184
|
-
{
|
185
|
-
hand[ i ] = deck[ i ];
|
186
|
-
}
|
187
|
-
pos += 5;
|
188
|
-
|
189
|
-
//もとの手札を表示
|
190
|
-
printf("手札\n");
|
191
|
-
dispHand( hand );
|
192
|
-
|
193
|
-
// 役を取得
|
194
|
-
yaku = getCategories( hand );
|
195
|
-
|
196
|
-
// 役を表示
|
197
|
-
printf( "役 : %s\n", categories[ yaku ] );
|
198
|
-
|
199
|
-
//交換
|
200
|
-
for(x=0;x<5;x++)
|
201
|
-
{
|
202
|
-
printf("%d番のカードを交換しますか? YES...0 NO...1 ",x);
|
203
|
-
scanf("%d",&num1);
|
204
|
-
if(num1 == 0)
|
205
|
-
{
|
206
|
-
if( 52 <= pos )
|
207
|
-
{
|
208
|
-
printf( "山札にカードがありません。\n" );
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
else
|
212
|
-
{
|
213
|
-
hand[ x ] = deck[ pos ];
|
214
|
-
pos++;
|
215
|
-
}
|
216
|
-
}
|
217
|
-
}
|
218
|
-
|
219
|
-
//交換後の手札を表示
|
220
|
-
printf("交換後の手札\n");
|
221
|
-
dispHand( hand );
|
222
|
-
|
223
|
-
// 役を取得
|
224
|
-
yaku = getCategories( hand );
|
225
|
-
|
226
|
-
// 役を表示
|
227
|
-
printf( "役 : %s\n", categories[ yaku ] );
|
228
|
-
|
229
|
-
return 0 ;
|
230
|
-
}
|