質問編集履歴

11

誤字

2020/03/22 00:04

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 実現したいこと
2
2
 
3
- JSの勉強でポーカーを作成中です。
3
+ JSの勉強中です。
4
4
 
5
5
  親と子の勝負で出たトランプの役を出し,
6
6
 

10

変更

2020/03/22 00:04

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -8,334 +8,6 @@
8
8
 
9
9
  ご教授していただけると有り難いです。
10
10
 
11
- ### 該当のソースコード
12
-
13
- ```javascript
14
-
15
- var parentcard = [...document.querySelectorAll ("#parent > div")]
16
-
17
- var childcard = [...document.querySelectorAll ("#child > div")]
18
-
19
- var parentchildhand = parentcard.concat (childcard)
20
-
21
- var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
22
-
23
- var total = [];
24
-
25
- for (var i = 0; i < 13; i++) {
26
-
27
- total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
28
-
29
- total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
30
-
31
- total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
32
-
33
- total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
34
-
35
- }
36
-
37
- var start = document.getElementById ("start");
38
-
39
- start.addEventListener ("click", function () {
40
-
41
- total.sort (() => Math.random()-.5);
42
-
43
- var parentcard = total.slice (0,5);
44
-
45
- var childcard = total.slice (-5);
46
-
47
- [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
48
-
49
- var parentscore = 0;
50
-
51
- var childscore = 0;
52
-
53
- isFlash (parentcard);
54
-
55
- var child = isFlash (childcard);
56
-
57
- if (parent) {
58
-
59
- parenthand (parent.yaku);
60
-
61
- parentscore = parent.score;
62
-
63
- } else if (child) {
64
-
65
- childhand (child.yaku);
66
-
67
- childscore = child.score;
68
-
69
- }
70
-
71
- var cutparentcardnum = parentcard.map (c => c[2]);
72
-
73
- var cutchildcardnum = childcard.map (c => c[2]);
74
-
75
- var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
76
-
77
- var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
78
-
79
- var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
80
-
81
- for( var i = 0; i < 5; i++ ){
82
-
83
- parentnumbers[cutparentcardnum[i]]++;
84
-
85
- childnumbers[cutchildcardnum[i]]++;
86
-
87
- }
88
-
89
- function judgment(numbers, score, sameCount) {
90
-
91
- if(high_card(numbers, score)){
92
-
93
- return "ハイカード";
94
-
95
- }else if(is_one(numbers, score)){
96
-
97
- return "ワンペア";
98
-
99
- }else if(two_pare(sameCount, score)){
100
-
101
- return "ツーペア";
102
-
103
- }else if(three_pare(numbers, score)){
104
-
105
- return "スリーオブアカインド";
106
-
107
- }else if(straight(numbers, score)){
108
-
109
- return "ストレート";
110
-
111
- }else if(isFlash(numbers, score)){
112
-
113
- return "フラッシュ";
114
-
115
- }else if(full_house(sameCount, score)){
116
-
117
- return "フルハウス";
118
-
119
- }else if(four_card(numbers, score)){
120
-
121
- return "フォーカード";
122
-
123
- }else if(straight_flash(numbers, score)){
124
-
125
- return "ストレートフラッシュ";
126
-
127
- }else if(royal_flash(numbers, score)){
128
-
129
- return "ロイヤルフラッシュ";
130
-
131
- }
132
-
133
- }
134
-
135
- var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
136
-
137
- var koResult = judgment(childnumbers, childscore, childsameCount);
138
-
139
- console.log(judgment(oyaResult));
140
-
141
- console.log(judgment(koResult));
142
-
143
- function high_card(numbers, score) {
144
-
145
- if (numbers === 0) {
146
-
147
- return score = 1000
148
-
149
- }
150
-
151
- }
152
-
153
- function is_one(numbers, score) {
154
-
155
- for (var i = 0; i < 13; i++) {
156
-
157
- if (numbers === 2) {
158
-
159
- return score = 2000;
160
-
161
- }
162
-
163
- }
164
-
165
- }
166
-
167
- function four_card(numbers, score) {
168
-
169
- for (var i = 0; i < 13; i++) {
170
-
171
- if (numbers === 4) {
172
-
173
- return score = 8000;
174
-
175
- }
176
-
177
- }
178
-
179
- }
180
-
181
- function three_pare(numbers, score) {
182
-
183
- for (var i = 0; i < 13; i++) {
184
-
185
- if (numbers === 3) {
186
-
187
- return score = 4000;
188
-
189
- }
190
-
191
- }
192
-
193
- }
194
-
195
- var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
196
-
197
- var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
198
-
199
- function two_pare(sameCount, score) {
200
-
201
- if(sameCount === 2 ){
202
-
203
- return score = 3000;
204
-
205
- }
206
-
207
- }
208
-
209
- var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
210
-
211
- function straight(numbers, score) {
212
-
213
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
214
-
215
- return score = 5000;
216
-
217
- }
218
-
219
- }
220
-
221
- function full_house(sameCount, score) {
222
-
223
- if(sameCount[3] == 1 && sameCount[2] == 1){
224
-
225
- return score = 7000;
226
-
227
- }
228
-
229
- }
230
-
231
- function straight_flash(numbers, score) {
232
-
233
- for(var i = 1; i <= 9; i++ ){
234
-
235
- if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
236
-
237
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
238
-
239
- return score = 9000;
240
-
241
- }
242
-
243
- }
244
-
245
- }
246
-
247
- }
248
-
249
- function royal_flash(numbers, score) {
250
-
251
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
252
-
253
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
254
-
255
- return score = 10000;
256
-
257
- } else {
258
-
259
- return score = 5000;
260
-
261
- }
262
-
263
- }
264
-
265
- }
266
-
267
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
268
-
269
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
270
-
271
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
272
-
273
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
274
-
275
- if (parentlow === 1) {
276
-
277
- var parenthigh = 20
278
-
279
- } else if (parentscore === 0) {
280
-
281
- parentscore = parenthigh
282
-
283
- }
284
-
285
- if (childlow === 1) {
286
-
287
- var childhigh = 20
288
-
289
- } else if (childscore === 0) {
290
-
291
- childscore = childhigh
292
-
293
- }
294
-
295
- result (parentscore, childscore);
296
-
297
- },false)
298
-
299
- function isFlash (cards) {
300
-
301
- var [first, other] = cards;
302
-
303
- return other.every (c => first[0] == c[0])
304
-
305
- ? {yaku: "フラッシュ", score: 6000 }
306
-
307
- : null;
308
-
309
- }
310
-
311
- function childhand (mess) {
312
-
313
- document.getElementById("childhand").innerHTML = mess;
314
-
315
- }
316
-
317
- function parenthand (mess) {
318
-
319
- document.getElementById("parenthand").innerHTML = mess;
320
-
321
- }
322
-
323
- function result (parentscore, childscore) {
324
-
325
- var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
326
-
327
- if (parentscore !== childscore)
328
-
329
- (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
330
-
331
- document.getElementById("parentbattle").innerHTML = mess[parent];
332
-
333
- document.getElementById("childbattle").innerHTML = mess[child];
334
-
335
- }
336
-
337
- ```
338
-
339
11
  ### 補足情報
340
12
 
341
- 上記のコード変更いたしました。
13
+ 変更いたしました。

9

削除された内容の復元を行いました。

2020/03/18 09:18

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,335 @@
7
7
  役によって点を持ち、親子比較して勝敗を出したいです。
8
8
 
9
9
  ご教授していただけると有り難いです。
10
+
11
+ ### 該当のソースコード
12
+
13
+ ```javascript
14
+
15
+ var parentcard = [...document.querySelectorAll ("#parent > div")]
16
+
17
+ var childcard = [...document.querySelectorAll ("#child > div")]
18
+
19
+ var parentchildhand = parentcard.concat (childcard)
20
+
21
+ var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
22
+
23
+ var total = [];
24
+
25
+ for (var i = 0; i < 13; i++) {
26
+
27
+ total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
28
+
29
+ total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
30
+
31
+ total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
32
+
33
+ total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
34
+
35
+ }
36
+
37
+ var start = document.getElementById ("start");
38
+
39
+ start.addEventListener ("click", function () {
40
+
41
+ total.sort (() => Math.random()-.5);
42
+
43
+ var parentcard = total.slice (0,5);
44
+
45
+ var childcard = total.slice (-5);
46
+
47
+ [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
48
+
49
+ var parentscore = 0;
50
+
51
+ var childscore = 0;
52
+
53
+ isFlash (parentcard);
54
+
55
+ var child = isFlash (childcard);
56
+
57
+ if (parent) {
58
+
59
+ parenthand (parent.yaku);
60
+
61
+ parentscore = parent.score;
62
+
63
+ } else if (child) {
64
+
65
+ childhand (child.yaku);
66
+
67
+ childscore = child.score;
68
+
69
+ }
70
+
71
+ var cutparentcardnum = parentcard.map (c => c[2]);
72
+
73
+ var cutchildcardnum = childcard.map (c => c[2]);
74
+
75
+ var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
76
+
77
+ var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
78
+
79
+ var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
80
+
81
+ for( var i = 0; i < 5; i++ ){
82
+
83
+ parentnumbers[cutparentcardnum[i]]++;
84
+
85
+ childnumbers[cutchildcardnum[i]]++;
86
+
87
+ }
88
+
89
+ function judgment(numbers, score, sameCount) {
90
+
91
+ if(high_card(numbers, score)){
92
+
93
+ return "ハイカード";
94
+
95
+ }else if(is_one(numbers, score)){
96
+
97
+ return "ワンペア";
98
+
99
+ }else if(two_pare(sameCount, score)){
100
+
101
+ return "ツーペア";
102
+
103
+ }else if(three_pare(numbers, score)){
104
+
105
+ return "スリーオブアカインド";
106
+
107
+ }else if(straight(numbers, score)){
108
+
109
+ return "ストレート";
110
+
111
+ }else if(isFlash(numbers, score)){
112
+
113
+ return "フラッシュ";
114
+
115
+ }else if(full_house(sameCount, score)){
116
+
117
+ return "フルハウス";
118
+
119
+ }else if(four_card(numbers, score)){
120
+
121
+ return "フォーカード";
122
+
123
+ }else if(straight_flash(numbers, score)){
124
+
125
+ return "ストレートフラッシュ";
126
+
127
+ }else if(royal_flash(numbers, score)){
128
+
129
+ return "ロイヤルフラッシュ";
130
+
131
+ }
132
+
133
+ }
134
+
135
+ var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
136
+
137
+ var koResult = judgment(childnumbers, childscore, childsameCount);
138
+
139
+ console.log(judgment(oyaResult));
140
+
141
+ console.log(judgment(koResult));
142
+
143
+ function high_card(numbers, score) {
144
+
145
+ if (numbers === 0) {
146
+
147
+ return score = 1000
148
+
149
+ }
150
+
151
+ }
152
+
153
+ function is_one(numbers, score) {
154
+
155
+ for (var i = 0; i < 13; i++) {
156
+
157
+ if (numbers === 2) {
158
+
159
+ return score = 2000;
160
+
161
+ }
162
+
163
+ }
164
+
165
+ }
166
+
167
+ function four_card(numbers, score) {
168
+
169
+ for (var i = 0; i < 13; i++) {
170
+
171
+ if (numbers === 4) {
172
+
173
+ return score = 8000;
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ function three_pare(numbers, score) {
182
+
183
+ for (var i = 0; i < 13; i++) {
184
+
185
+ if (numbers === 3) {
186
+
187
+ return score = 4000;
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
196
+
197
+ var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
198
+
199
+ function two_pare(sameCount, score) {
200
+
201
+ if(sameCount === 2 ){
202
+
203
+ return score = 3000;
204
+
205
+ }
206
+
207
+ }
208
+
209
+ var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
210
+
211
+ function straight(numbers, score) {
212
+
213
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
214
+
215
+ return score = 5000;
216
+
217
+ }
218
+
219
+ }
220
+
221
+ function full_house(sameCount, score) {
222
+
223
+ if(sameCount[3] == 1 && sameCount[2] == 1){
224
+
225
+ return score = 7000;
226
+
227
+ }
228
+
229
+ }
230
+
231
+ function straight_flash(numbers, score) {
232
+
233
+ for(var i = 1; i <= 9; i++ ){
234
+
235
+ if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
236
+
237
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
238
+
239
+ return score = 9000;
240
+
241
+ }
242
+
243
+ }
244
+
245
+ }
246
+
247
+ }
248
+
249
+ function royal_flash(numbers, score) {
250
+
251
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
252
+
253
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
254
+
255
+ return score = 10000;
256
+
257
+ } else {
258
+
259
+ return score = 5000;
260
+
261
+ }
262
+
263
+ }
264
+
265
+ }
266
+
267
+ var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
268
+
269
+ var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
270
+
271
+ var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
272
+
273
+ var childlow = Math.min.apply(null, cutchildcardnum) + 1;
274
+
275
+ if (parentlow === 1) {
276
+
277
+ var parenthigh = 20
278
+
279
+ } else if (parentscore === 0) {
280
+
281
+ parentscore = parenthigh
282
+
283
+ }
284
+
285
+ if (childlow === 1) {
286
+
287
+ var childhigh = 20
288
+
289
+ } else if (childscore === 0) {
290
+
291
+ childscore = childhigh
292
+
293
+ }
294
+
295
+ result (parentscore, childscore);
296
+
297
+ },false)
298
+
299
+ function isFlash (cards) {
300
+
301
+ var [first, other] = cards;
302
+
303
+ return other.every (c => first[0] == c[0])
304
+
305
+ ? {yaku: "フラッシュ", score: 6000 }
306
+
307
+ : null;
308
+
309
+ }
310
+
311
+ function childhand (mess) {
312
+
313
+ document.getElementById("childhand").innerHTML = mess;
314
+
315
+ }
316
+
317
+ function parenthand (mess) {
318
+
319
+ document.getElementById("parenthand").innerHTML = mess;
320
+
321
+ }
322
+
323
+ function result (parentscore, childscore) {
324
+
325
+ var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
326
+
327
+ if (parentscore !== childscore)
328
+
329
+ (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
330
+
331
+ document.getElementById("parentbattle").innerHTML = mess[parent];
332
+
333
+ document.getElementById("childbattle").innerHTML = mess[child];
334
+
335
+ }
336
+
337
+ ```
338
+
339
+ ### 補足情報
340
+
341
+ 上記のコード変更いたしました。

8

ok

2020/03/18 07:28

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -7,339 +7,3 @@
7
7
  役によって点を持ち、親子比較して勝敗を出したいです。
8
8
 
9
9
  ご教授していただけると有り難いです。
10
-
11
- ### 該当のソースコード
12
-
13
- ```javascript
14
-
15
- var parentcard = [...document.querySelectorAll ("#parent > div")]
16
-
17
- var childcard = [...document.querySelectorAll ("#child > div")]
18
-
19
- var parentchildhand = parentcard.concat (childcard)
20
-
21
- var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
22
-
23
- var total = [];
24
-
25
- for (var i = 0; i < 13; i++) {
26
-
27
- total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
28
-
29
- total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
30
-
31
- total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
32
-
33
- total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
34
-
35
- }
36
-
37
- var start = document.getElementById ("start");
38
-
39
- start.addEventListener ("click", function () {
40
-
41
- total.sort (() => Math.random()-.5);
42
-
43
- var parentcard = total.slice (0,5);
44
-
45
- var childcard = total.slice (-5);
46
-
47
- [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
48
-
49
- var parentscore = 0;
50
-
51
- var childscore = 0;
52
-
53
- isFlash (parentcard);
54
-
55
- var child = isFlash (childcard);
56
-
57
- if (parent) {
58
-
59
- parenthand (parent.yaku);
60
-
61
- parentscore = parent.score;
62
-
63
- } else if (child) {
64
-
65
- childhand (child.yaku);
66
-
67
- childscore = child.score;
68
-
69
- }
70
-
71
- var cutparentcardnum = parentcard.map (c => c[2]);
72
-
73
- var cutchildcardnum = childcard.map (c => c[2]);
74
-
75
- var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
76
-
77
- var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
78
-
79
- var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
80
-
81
- for( var i = 0; i < 5; i++ ){
82
-
83
- parentnumbers[cutparentcardnum[i]]++;
84
-
85
- childnumbers[cutchildcardnum[i]]++;
86
-
87
- }
88
-
89
- function judgment(numbers, score, sameCount) {
90
-
91
- if(high_card(numbers, score)){
92
-
93
- return "ハイカード";
94
-
95
- }else if(is_one(numbers, score)){
96
-
97
- return "ワンペア";
98
-
99
- }else if(two_pare(sameCount, score)){
100
-
101
- return "ツーペア";
102
-
103
- }else if(three_pare(numbers, score)){
104
-
105
- return "スリーオブアカインド";
106
-
107
- }else if(straight(numbers, score)){
108
-
109
- return "ストレート";
110
-
111
- }else if(isFlash(numbers, score)){
112
-
113
- return "フラッシュ";
114
-
115
- }else if(full_house(sameCount, score)){
116
-
117
- return "フルハウス";
118
-
119
- }else if(four_card(numbers, score)){
120
-
121
- return "フォーカード";
122
-
123
- }else if(straight_flash(numbers, score)){
124
-
125
- return "ストレートフラッシュ";
126
-
127
- }else if(royal_flash(numbers, score)){
128
-
129
- return "ロイヤルフラッシュ";
130
-
131
- }
132
-
133
- }
134
-
135
- var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
136
-
137
- var koResult = judgment(childnumbers, childscore, childsameCount);
138
-
139
- console.log(judgment(oyaResult));
140
-
141
- console.log(judgment(koResult));
142
-
143
- function high_card(numbers, score) {
144
-
145
- if (numbers === 0) {
146
-
147
- return score = 1000
148
-
149
- }
150
-
151
- }
152
-
153
- function is_one(numbers, score) {
154
-
155
- for (var i = 0; i < 13; i++) {
156
-
157
- if (numbers === 2) {
158
-
159
- return score = 2000;
160
-
161
- }
162
-
163
- }
164
-
165
- }
166
-
167
- function four_card(numbers, score) {
168
-
169
- for (var i = 0; i < 13; i++) {
170
-
171
- if (numbers === 4) {
172
-
173
- return score = 8000;
174
-
175
- }
176
-
177
- }
178
-
179
- }
180
-
181
- function three_pare(numbers, score) {
182
-
183
- for (var i = 0; i < 13; i++) {
184
-
185
- if (numbers === 3) {
186
-
187
- return score = 4000;
188
-
189
- }
190
-
191
- }
192
-
193
- }
194
-
195
- var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
196
-
197
- var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
198
-
199
- function two_pare(sameCount, score) {
200
-
201
- if(sameCount === 2 ){
202
-
203
- return score = 3000;
204
-
205
- }
206
-
207
- }
208
-
209
- var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
210
-
211
- function straight(numbers, score) {
212
-
213
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
214
-
215
- return score = 5000;
216
-
217
- }
218
-
219
- }
220
-
221
- function full_house(sameCount, score) {
222
-
223
- if(sameCount[3] == 1 && sameCount[2] == 1){
224
-
225
- return score = 7000;
226
-
227
- }
228
-
229
- }
230
-
231
- function straight_flash(numbers, score) {
232
-
233
- for(var i = 1; i <= 9; i++ ){
234
-
235
- if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
236
-
237
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
238
-
239
- return score = 9000;
240
-
241
- }
242
-
243
- }
244
-
245
- }
246
-
247
- }
248
-
249
- function royal_flash(numbers, score) {
250
-
251
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
252
-
253
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
254
-
255
- return score = 10000;
256
-
257
- } else {
258
-
259
- return score = 5000;
260
-
261
- }
262
-
263
- }
264
-
265
- }
266
-
267
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
268
-
269
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
270
-
271
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
272
-
273
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
274
-
275
- if (parentlow === 1) {
276
-
277
- var parenthigh = 20
278
-
279
- } else if (parentscore === 0) {
280
-
281
- parentscore = parenthigh
282
-
283
- }
284
-
285
- if (childlow === 1) {
286
-
287
- var childhigh = 20
288
-
289
- } else if (childscore === 0) {
290
-
291
- childscore = childhigh
292
-
293
- }
294
-
295
- result (parentscore, childscore);
296
-
297
- },false)
298
-
299
- function isFlash (cards) {
300
-
301
- var [first, other] = cards;
302
-
303
- return other.every (c => first[0] == c[0])
304
-
305
- ? {yaku: "フラッシュ", score: 6000 }
306
-
307
- : null;
308
-
309
- }
310
-
311
- function childhand (mess) {
312
-
313
- document.getElementById("childhand").innerHTML = mess;
314
-
315
- }
316
-
317
- function parenthand (mess) {
318
-
319
- document.getElementById("parenthand").innerHTML = mess;
320
-
321
- }
322
-
323
- function result (parentscore, childscore) {
324
-
325
- var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
326
-
327
- if (parentscore !== childscore)
328
-
329
- (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
330
-
331
-
332
-
333
-
334
-
335
- document.getElementById("parentbattle").innerHTML = mess[parent];
336
-
337
- document.getElementById("childbattle").innerHTML = mess[child];
338
-
339
- }
340
-
341
- ```
342
-
343
- ### 補足情報
344
-
345
- 上記のコード変更いたしました。

7

削除された内容の復元を行いました

2020/03/17 14:11

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,13 +1,345 @@
1
1
  ### 実現したいこと
2
2
 
3
- JSの勉強中です。
3
+ JSの勉強でポーカーを作成中です。
4
-
5
-
6
4
 
7
5
  親と子の勝負で出たトランプの役を出し,
8
6
 
9
7
  役によって点を持ち、親子比較して勝敗を出したいです。
10
8
 
11
-
12
-
13
9
  ご教授していただけると有り難いです。
10
+
11
+ ### 該当のソースコード
12
+
13
+ ```javascript
14
+
15
+ var parentcard = [...document.querySelectorAll ("#parent > div")]
16
+
17
+ var childcard = [...document.querySelectorAll ("#child > div")]
18
+
19
+ var parentchildhand = parentcard.concat (childcard)
20
+
21
+ var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
22
+
23
+ var total = [];
24
+
25
+ for (var i = 0; i < 13; i++) {
26
+
27
+ total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
28
+
29
+ total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
30
+
31
+ total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
32
+
33
+ total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
34
+
35
+ }
36
+
37
+ var start = document.getElementById ("start");
38
+
39
+ start.addEventListener ("click", function () {
40
+
41
+ total.sort (() => Math.random()-.5);
42
+
43
+ var parentcard = total.slice (0,5);
44
+
45
+ var childcard = total.slice (-5);
46
+
47
+ [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
48
+
49
+ var parentscore = 0;
50
+
51
+ var childscore = 0;
52
+
53
+ isFlash (parentcard);
54
+
55
+ var child = isFlash (childcard);
56
+
57
+ if (parent) {
58
+
59
+ parenthand (parent.yaku);
60
+
61
+ parentscore = parent.score;
62
+
63
+ } else if (child) {
64
+
65
+ childhand (child.yaku);
66
+
67
+ childscore = child.score;
68
+
69
+ }
70
+
71
+ var cutparentcardnum = parentcard.map (c => c[2]);
72
+
73
+ var cutchildcardnum = childcard.map (c => c[2]);
74
+
75
+ var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
76
+
77
+ var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
78
+
79
+ var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
80
+
81
+ for( var i = 0; i < 5; i++ ){
82
+
83
+ parentnumbers[cutparentcardnum[i]]++;
84
+
85
+ childnumbers[cutchildcardnum[i]]++;
86
+
87
+ }
88
+
89
+ function judgment(numbers, score, sameCount) {
90
+
91
+ if(high_card(numbers, score)){
92
+
93
+ return "ハイカード";
94
+
95
+ }else if(is_one(numbers, score)){
96
+
97
+ return "ワンペア";
98
+
99
+ }else if(two_pare(sameCount, score)){
100
+
101
+ return "ツーペア";
102
+
103
+ }else if(three_pare(numbers, score)){
104
+
105
+ return "スリーオブアカインド";
106
+
107
+ }else if(straight(numbers, score)){
108
+
109
+ return "ストレート";
110
+
111
+ }else if(isFlash(numbers, score)){
112
+
113
+ return "フラッシュ";
114
+
115
+ }else if(full_house(sameCount, score)){
116
+
117
+ return "フルハウス";
118
+
119
+ }else if(four_card(numbers, score)){
120
+
121
+ return "フォーカード";
122
+
123
+ }else if(straight_flash(numbers, score)){
124
+
125
+ return "ストレートフラッシュ";
126
+
127
+ }else if(royal_flash(numbers, score)){
128
+
129
+ return "ロイヤルフラッシュ";
130
+
131
+ }
132
+
133
+ }
134
+
135
+ var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
136
+
137
+ var koResult = judgment(childnumbers, childscore, childsameCount);
138
+
139
+ console.log(judgment(oyaResult));
140
+
141
+ console.log(judgment(koResult));
142
+
143
+ function high_card(numbers, score) {
144
+
145
+ if (numbers === 0) {
146
+
147
+ return score = 1000
148
+
149
+ }
150
+
151
+ }
152
+
153
+ function is_one(numbers, score) {
154
+
155
+ for (var i = 0; i < 13; i++) {
156
+
157
+ if (numbers === 2) {
158
+
159
+ return score = 2000;
160
+
161
+ }
162
+
163
+ }
164
+
165
+ }
166
+
167
+ function four_card(numbers, score) {
168
+
169
+ for (var i = 0; i < 13; i++) {
170
+
171
+ if (numbers === 4) {
172
+
173
+ return score = 8000;
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ function three_pare(numbers, score) {
182
+
183
+ for (var i = 0; i < 13; i++) {
184
+
185
+ if (numbers === 3) {
186
+
187
+ return score = 4000;
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
196
+
197
+ var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
198
+
199
+ function two_pare(sameCount, score) {
200
+
201
+ if(sameCount === 2 ){
202
+
203
+ return score = 3000;
204
+
205
+ }
206
+
207
+ }
208
+
209
+ var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
210
+
211
+ function straight(numbers, score) {
212
+
213
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
214
+
215
+ return score = 5000;
216
+
217
+ }
218
+
219
+ }
220
+
221
+ function full_house(sameCount, score) {
222
+
223
+ if(sameCount[3] == 1 && sameCount[2] == 1){
224
+
225
+ return score = 7000;
226
+
227
+ }
228
+
229
+ }
230
+
231
+ function straight_flash(numbers, score) {
232
+
233
+ for(var i = 1; i <= 9; i++ ){
234
+
235
+ if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
236
+
237
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
238
+
239
+ return score = 9000;
240
+
241
+ }
242
+
243
+ }
244
+
245
+ }
246
+
247
+ }
248
+
249
+ function royal_flash(numbers, score) {
250
+
251
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
252
+
253
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
254
+
255
+ return score = 10000;
256
+
257
+ } else {
258
+
259
+ return score = 5000;
260
+
261
+ }
262
+
263
+ }
264
+
265
+ }
266
+
267
+ var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
268
+
269
+ var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
270
+
271
+ var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
272
+
273
+ var childlow = Math.min.apply(null, cutchildcardnum) + 1;
274
+
275
+ if (parentlow === 1) {
276
+
277
+ var parenthigh = 20
278
+
279
+ } else if (parentscore === 0) {
280
+
281
+ parentscore = parenthigh
282
+
283
+ }
284
+
285
+ if (childlow === 1) {
286
+
287
+ var childhigh = 20
288
+
289
+ } else if (childscore === 0) {
290
+
291
+ childscore = childhigh
292
+
293
+ }
294
+
295
+ result (parentscore, childscore);
296
+
297
+ },false)
298
+
299
+ function isFlash (cards) {
300
+
301
+ var [first, other] = cards;
302
+
303
+ return other.every (c => first[0] == c[0])
304
+
305
+ ? {yaku: "フラッシュ", score: 6000 }
306
+
307
+ : null;
308
+
309
+ }
310
+
311
+ function childhand (mess) {
312
+
313
+ document.getElementById("childhand").innerHTML = mess;
314
+
315
+ }
316
+
317
+ function parenthand (mess) {
318
+
319
+ document.getElementById("parenthand").innerHTML = mess;
320
+
321
+ }
322
+
323
+ function result (parentscore, childscore) {
324
+
325
+ var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
326
+
327
+ if (parentscore !== childscore)
328
+
329
+ (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
330
+
331
+
332
+
333
+
334
+
335
+ document.getElementById("parentbattle").innerHTML = mess[parent];
336
+
337
+ document.getElementById("childbattle").innerHTML = mess[child];
338
+
339
+ }
340
+
341
+ ```
342
+
343
+ ### 補足情報
344
+
345
+ 上記のコード変更いたしました。

6

マークダウン

2020/03/17 07:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 実現したいこと
2
2
 
3
- JSの勉強でポーカーを作成中です。
3
+ JSの勉強中です。
4
4
 
5
5
 
6
6
 
@@ -11,427 +11,3 @@
11
11
 
12
12
 
13
13
  ご教授していただけると有り難いです。
14
-
15
-
16
-
17
- ### 該当のソースコード
18
-
19
-
20
-
21
- ```javascript
22
-
23
- var parentcard = [...document.querySelectorAll ("#parent > div")]
24
-
25
- var childcard = [...document.querySelectorAll ("#child > div")]
26
-
27
- var parentchildhand = parentcard.concat (childcard)
28
-
29
- var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
30
-
31
- var total = [];
32
-
33
-
34
-
35
- for (var i = 0; i < 13; i++) {
36
-
37
- total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
38
-
39
- total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
40
-
41
- total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
42
-
43
- total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
44
-
45
- }
46
-
47
-
48
-
49
- var start = document.getElementById ("start");
50
-
51
-
52
-
53
- start.addEventListener ("click", function () {
54
-
55
- total.sort (() => Math.random()-.5);
56
-
57
- var parentcard = total.slice (0,5);
58
-
59
- var childcard = total.slice (-5);
60
-
61
-
62
-
63
- [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
64
-
65
-
66
-
67
- var parentscore = 0;
68
-
69
- var childscore = 0;
70
-
71
-
72
-
73
-
74
-
75
- isFlash (parentcard);
76
-
77
- var child = isFlash (childcard);
78
-
79
- if (parent) {
80
-
81
- parenthand (parent.yaku);
82
-
83
- parentscore = parent.score;
84
-
85
- } else if (child) {
86
-
87
- childhand (child.yaku);
88
-
89
- childscore = child.score;
90
-
91
- }
92
-
93
-
94
-
95
- var cutparentcardnum = parentcard.map (c => c[2]);
96
-
97
- var cutchildcardnum = childcard.map (c => c[2]);
98
-
99
-
100
-
101
- var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
102
-
103
-
104
-
105
- var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
106
-
107
- var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
108
-
109
-
110
-
111
- for( var i = 0; i < 5; i++ ){
112
-
113
- parentnumbers[cutparentcardnum[i]]++;
114
-
115
- childnumbers[cutchildcardnum[i]]++;
116
-
117
- }
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
- function judgment(numbers, score, sameCount) {
126
-
127
- if(high_card(numbers, score)){
128
-
129
- return "ハイカード";
130
-
131
- }else if(is_one(numbers, score)){
132
-
133
- return "ワンペア";
134
-
135
- }else if(two_pare(sameCount, score)){
136
-
137
- return "ツーペア";
138
-
139
- }else if(three_pare(numbers, score)){
140
-
141
- return "スリーオブアカインド";
142
-
143
- }else if(straight(numbers, score)){
144
-
145
- return "ストレート";
146
-
147
- }else if(isFlash(numbers, score)){
148
-
149
- return "フラッシュ";
150
-
151
- }else if(full_house(sameCount, score)){
152
-
153
- return "フルハウス";
154
-
155
- }else if(four_card(numbers, score)){
156
-
157
- return "フォーカード";
158
-
159
- }else if(straight_flash(numbers, score)){
160
-
161
- return "ストレートフラッシュ";
162
-
163
- }else if(royal_flash(numbers, score)){
164
-
165
- return "ロイヤルフラッシュ";
166
-
167
- }
168
-
169
- }
170
-
171
- var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
172
-
173
- var koResult = judgment(childnumbers, childscore, childsameCount);
174
-
175
-
176
-
177
-
178
-
179
- console.log(judgment(oyaResult));
180
-
181
- console.log(judgment(koResult));
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
- function high_card(numbers, score) {
190
-
191
- if (numbers === 0) {
192
-
193
- return score = 1000
194
-
195
- }
196
-
197
- }
198
-
199
-
200
-
201
- function is_one(numbers, score) {
202
-
203
- for (var i = 0; i < 13; i++) {
204
-
205
- if (numbers === 2) {
206
-
207
- return score = 2000;
208
-
209
- }
210
-
211
- }
212
-
213
- }
214
-
215
-
216
-
217
- function four_card(numbers, score) {
218
-
219
- for (var i = 0; i < 13; i++) {
220
-
221
- if (numbers === 4) {
222
-
223
- return score = 8000;
224
-
225
- }
226
-
227
- }
228
-
229
- }
230
-
231
-
232
-
233
- function three_pare(numbers, score) {
234
-
235
- for (var i = 0; i < 13; i++) {
236
-
237
- if (numbers === 3) {
238
-
239
- return score = 4000;
240
-
241
- }
242
-
243
- }
244
-
245
- }
246
-
247
-
248
-
249
- var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
250
-
251
- var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
252
-
253
-
254
-
255
- function two_pare(sameCount, score) {
256
-
257
- if(sameCount === 2 ){
258
-
259
- return score = 3000;
260
-
261
- }
262
-
263
- }
264
-
265
-
266
-
267
- var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
268
-
269
-
270
-
271
- function straight(numbers, score) {
272
-
273
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
274
-
275
- return score = 5000;
276
-
277
- }
278
-
279
- }
280
-
281
-
282
-
283
- function full_house(sameCount, score) {
284
-
285
- if(sameCount[3] == 1 && sameCount[2] == 1){
286
-
287
- return score = 7000;
288
-
289
- }
290
-
291
- }
292
-
293
-
294
-
295
- function straight_flash(numbers, score) {
296
-
297
- for(var i = 1; i <= 9; i++ ){
298
-
299
- if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
300
-
301
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
302
-
303
- return score = 9000;
304
-
305
- }
306
-
307
- }
308
-
309
- }
310
-
311
- }
312
-
313
-
314
-
315
- function royal_flash(numbers, score) {
316
-
317
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
318
-
319
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
320
-
321
- return score = 10000;
322
-
323
- } else {
324
-
325
- return score = 5000;
326
-
327
- }
328
-
329
- }
330
-
331
- }
332
-
333
-
334
-
335
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
336
-
337
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
338
-
339
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
340
-
341
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
342
-
343
-
344
-
345
-
346
-
347
- if (parentlow === 1) {
348
-
349
- var parenthigh = 20
350
-
351
- } else if (parentscore === 0) {
352
-
353
- parentscore = parenthigh
354
-
355
- }
356
-
357
-
358
-
359
- if (childlow === 1) {
360
-
361
- var childhigh = 20
362
-
363
- } else if (childscore === 0) {
364
-
365
- childscore = childhigh
366
-
367
- }
368
-
369
-
370
-
371
- result (parentscore, childscore);
372
-
373
- },false)
374
-
375
-
376
-
377
-
378
-
379
- function isFlash (cards) {
380
-
381
- var [first, other] = cards;
382
-
383
- return other.every (c => first[0] == c[0])
384
-
385
- ? {yaku: "フラッシュ", score: 6000 }
386
-
387
- : null;
388
-
389
- }
390
-
391
-
392
-
393
-
394
-
395
- function childhand (mess) {
396
-
397
- document.getElementById("childhand").innerHTML = mess;
398
-
399
- }
400
-
401
-
402
-
403
- function parenthand (mess) {
404
-
405
- document.getElementById("parenthand").innerHTML = mess;
406
-
407
- }
408
-
409
-
410
-
411
- function result (parentscore, childscore) {
412
-
413
- var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
414
-
415
-
416
-
417
- if (parentscore !== childscore)
418
-
419
- (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
420
-
421
-
422
-
423
-
424
-
425
- document.getElementById("parentbattle").innerHTML = mess[parent];
426
-
427
- document.getElementById("childbattle").innerHTML = mess[child];
428
-
429
- }
430
-
431
- ```
432
-
433
-
434
-
435
- ### 補足情報
436
-
437
- 上記のコード変更いたしました。

5

文法

2020/03/17 01:30

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -16,510 +16,422 @@
16
16
 
17
17
  ### 該当のソースコード
18
18
 
19
- ```html
20
-
21
- <body>
22
-
23
- <div class="wrapper">
24
-
25
- <div class="box1">
26
-
27
- <div class="result1">
28
-
29
- <p id=parentbattle></p>
30
-
31
- </div>
32
-
33
- <div class="parent">
34
-
35
- <p>親</p>
36
-
37
- </div>
38
-
39
- </div>
40
-
41
- <div class="rolename1 role">
42
-
43
- <p id=parenthand></p>
44
-
45
- </div>
46
-
47
- <div class="box2" id="parent">
48
-
49
- <div class="cards"></div>
50
-
51
- <div class="cards"></div>
52
-
53
- <div class="cards"></div>
54
-
55
- <div class="cards"></div>
56
-
57
- <div class="cards"></div>
58
-
59
- </div>
60
-
61
- <div class="start" id=start>ゲームスタート</div>
62
-
63
- <div class="rolename2 role">
64
-
65
- <p id=childhand></p>
66
-
67
- </div>
68
-
69
- <div class="box2" id="child">
70
-
71
- <div class="cards"></div>
72
-
73
- <div class="cards"></div>
74
-
75
- <div class="cards"></div>
76
-
77
- <div class="cards"></div>
78
-
79
- <div class="cards"></div>
80
-
81
- </div>
82
-
83
- <div class="wrapper3">
84
-
85
- <div class="child">
86
-
87
- <p>子</p>
88
-
89
- </div>
90
-
91
- <div class="result2">
92
-
93
- <p id=childbattle></p>
94
-
95
- </div>
96
-
97
- </div>
98
-
99
- </div>
19
+
20
+
21
+ ```javascript
22
+
23
+ var parentcard = [...document.querySelectorAll ("#parent > div")]
24
+
25
+ var childcard = [...document.querySelectorAll ("#child > div")]
26
+
27
+ var parentchildhand = parentcard.concat (childcard)
28
+
29
+ var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
30
+
31
+ var total = [];
32
+
33
+
34
+
35
+ for (var i = 0; i < 13; i++) {
36
+
37
+ total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
38
+
39
+ total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
40
+
41
+ total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
42
+
43
+ total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
44
+
45
+ }
46
+
47
+
48
+
49
+ var start = document.getElementById ("start");
50
+
51
+
52
+
53
+ start.addEventListener ("click", function () {
54
+
55
+ total.sort (() => Math.random()-.5);
56
+
57
+ var parentcard = total.slice (0,5);
58
+
59
+ var childcard = total.slice (-5);
60
+
61
+
62
+
63
+ [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
64
+
65
+
66
+
67
+ var parentscore = 0;
68
+
69
+ var childscore = 0;
70
+
71
+
72
+
73
+
74
+
75
+ isFlash (parentcard);
76
+
77
+ var child = isFlash (childcard);
78
+
79
+ if (parent) {
80
+
81
+ parenthand (parent.yaku);
82
+
83
+ parentscore = parent.score;
84
+
85
+ } else if (child) {
86
+
87
+ childhand (child.yaku);
88
+
89
+ childscore = child.score;
90
+
91
+ }
92
+
93
+
94
+
95
+ var cutparentcardnum = parentcard.map (c => c[2]);
96
+
97
+ var cutchildcardnum = childcard.map (c => c[2]);
98
+
99
+
100
+
101
+ var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
102
+
103
+
104
+
105
+ var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
106
+
107
+ var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
108
+
109
+
110
+
111
+ for( var i = 0; i < 5; i++ ){
112
+
113
+ parentnumbers[cutparentcardnum[i]]++;
114
+
115
+ childnumbers[cutchildcardnum[i]]++;
116
+
117
+ }
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ function judgment(numbers, score, sameCount) {
126
+
127
+ if(high_card(numbers, score)){
128
+
129
+ return "ハイカード";
130
+
131
+ }else if(is_one(numbers, score)){
132
+
133
+ return "ワンペア";
134
+
135
+ }else if(two_pare(sameCount, score)){
136
+
137
+ return "ツーペア";
138
+
139
+ }else if(three_pare(numbers, score)){
140
+
141
+ return "スリーオブアカインド";
142
+
143
+ }else if(straight(numbers, score)){
144
+
145
+ return "ストレート";
146
+
147
+ }else if(isFlash(numbers, score)){
148
+
149
+ return "フラッシュ";
150
+
151
+ }else if(full_house(sameCount, score)){
152
+
153
+ return "フルハウス";
154
+
155
+ }else if(four_card(numbers, score)){
156
+
157
+ return "フォーカード";
158
+
159
+ }else if(straight_flash(numbers, score)){
160
+
161
+ return "ストレートフラッシュ";
162
+
163
+ }else if(royal_flash(numbers, score)){
164
+
165
+ return "ロイヤルフラッシュ";
166
+
167
+ }
168
+
169
+ }
170
+
171
+ var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
172
+
173
+ var koResult = judgment(childnumbers, childscore, childsameCount);
174
+
175
+
176
+
177
+
178
+
179
+ console.log(judgment(oyaResult));
180
+
181
+ console.log(judgment(koResult));
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+ function high_card(numbers, score) {
190
+
191
+ if (numbers === 0) {
192
+
193
+ return score = 1000
194
+
195
+ }
196
+
197
+ }
198
+
199
+
200
+
201
+ function is_one(numbers, score) {
202
+
203
+ for (var i = 0; i < 13; i++) {
204
+
205
+ if (numbers === 2) {
206
+
207
+ return score = 2000;
208
+
209
+ }
210
+
211
+ }
212
+
213
+ }
214
+
215
+
216
+
217
+ function four_card(numbers, score) {
218
+
219
+ for (var i = 0; i < 13; i++) {
220
+
221
+ if (numbers === 4) {
222
+
223
+ return score = 8000;
224
+
225
+ }
226
+
227
+ }
228
+
229
+ }
230
+
231
+
232
+
233
+ function three_pare(numbers, score) {
234
+
235
+ for (var i = 0; i < 13; i++) {
236
+
237
+ if (numbers === 3) {
238
+
239
+ return score = 4000;
240
+
241
+ }
242
+
243
+ }
244
+
245
+ }
246
+
247
+
248
+
249
+ var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
250
+
251
+ var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
252
+
253
+
254
+
255
+ function two_pare(sameCount, score) {
256
+
257
+ if(sameCount === 2 ){
258
+
259
+ return score = 3000;
260
+
261
+ }
262
+
263
+ }
264
+
265
+
266
+
267
+ var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
268
+
269
+
270
+
271
+ function straight(numbers, score) {
272
+
273
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
274
+
275
+ return score = 5000;
276
+
277
+ }
278
+
279
+ }
280
+
281
+
282
+
283
+ function full_house(sameCount, score) {
284
+
285
+ if(sameCount[3] == 1 && sameCount[2] == 1){
286
+
287
+ return score = 7000;
288
+
289
+ }
290
+
291
+ }
292
+
293
+
294
+
295
+ function straight_flash(numbers, score) {
296
+
297
+ for(var i = 1; i <= 9; i++ ){
298
+
299
+ if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
300
+
301
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
302
+
303
+ return score = 9000;
304
+
305
+ }
306
+
307
+ }
308
+
309
+ }
310
+
311
+ }
312
+
313
+
314
+
315
+ function royal_flash(numbers, score) {
316
+
317
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
318
+
319
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
320
+
321
+ return score = 10000;
322
+
323
+ } else {
324
+
325
+ return score = 5000;
326
+
327
+ }
328
+
329
+ }
330
+
331
+ }
332
+
333
+
334
+
335
+ var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
336
+
337
+ var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
338
+
339
+ var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
340
+
341
+ var childlow = Math.min.apply(null, cutchildcardnum) + 1;
342
+
343
+
344
+
345
+
346
+
347
+ if (parentlow === 1) {
348
+
349
+ var parenthigh = 20
350
+
351
+ } else if (parentscore === 0) {
352
+
353
+ parentscore = parenthigh
354
+
355
+ }
356
+
357
+
358
+
359
+ if (childlow === 1) {
360
+
361
+ var childhigh = 20
362
+
363
+ } else if (childscore === 0) {
364
+
365
+ childscore = childhigh
366
+
367
+ }
368
+
369
+
370
+
371
+ result (parentscore, childscore);
372
+
373
+ },false)
374
+
375
+
376
+
377
+
378
+
379
+ function isFlash (cards) {
380
+
381
+ var [first, other] = cards;
382
+
383
+ return other.every (c => first[0] == c[0])
384
+
385
+ ? {yaku: "フラッシュ", score: 6000 }
386
+
387
+ : null;
388
+
389
+ }
390
+
391
+
392
+
393
+
394
+
395
+ function childhand (mess) {
396
+
397
+ document.getElementById("childhand").innerHTML = mess;
398
+
399
+ }
400
+
401
+
402
+
403
+ function parenthand (mess) {
404
+
405
+ document.getElementById("parenthand").innerHTML = mess;
406
+
407
+ }
408
+
409
+
410
+
411
+ function result (parentscore, childscore) {
412
+
413
+ var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
414
+
415
+
416
+
417
+ if (parentscore !== childscore)
418
+
419
+ (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
420
+
421
+
422
+
423
+
424
+
425
+ document.getElementById("parentbattle").innerHTML = mess[parent];
426
+
427
+ document.getElementById("childbattle").innerHTML = mess[child];
428
+
429
+ }
100
430
 
101
431
  ```
102
432
 
103
433
 
104
434
 
105
- ```javascript
106
-
107
- var parentcard = [...document.querySelectorAll ("#parent > div")]
108
-
109
- var childcard = [...document.querySelectorAll ("#child > div")]
110
-
111
- var parentchildhand = parentcard.concat (childcard)
112
-
113
- var no = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
114
-
115
- var total = [];
116
-
117
-
118
-
119
- for (var i = 0; i < 13; i++) {
120
-
121
- total.push (["Spade", "<img src=images/" + no[i] + ".clover.png width=140px height=250px>", i]);
122
-
123
- total.push (["Heart", "<img src=images/" + no[i] + ".spade.png width=140px height=250px>", i]);
124
-
125
- total.push (["Daiya", "<img src=images/" + no[i] + ".daiya.png width=140px height=250px>", i]);
126
-
127
- total.push (["Clover", "<img src=images/" + no[i] + ".heart.png width=140px height=250px>", i]);
128
-
129
- }
130
-
131
-
132
-
133
- var start = document.getElementById ("start");
134
-
135
-
136
-
137
- start.addEventListener ("click", function () {
138
-
139
- total.sort (() => Math.random()-.5);
140
-
141
- var parentcard = total.slice (0,5);
142
-
143
- var childcard = total.slice (-5);
144
-
145
-
146
-
147
- [...parentcard, ...childcard].forEach ((n, i) => parentchildhand[i].innerHTML = n[1]);
148
-
149
-
150
-
151
- var parentscore = 0;
152
-
153
- var childscore = 0;
154
-
155
-
156
-
157
-
158
-
159
- isFlash (parentcard);
160
-
161
- var child = isFlash (childcard);
162
-
163
- if (parent) {
164
-
165
- parenthand (parent.yaku);
166
-
167
- parentscore = parent.score;
168
-
169
- } else if (child) {
170
-
171
- childhand (child.yaku);
172
-
173
- childscore = child.score;
174
-
175
- }
176
-
177
-
178
-
179
- var cutparentcardnum = parentcard.map (c => c[2]);
180
-
181
- var cutchildcardnum = childcard.map (c => c[2]);
182
-
183
-
184
-
185
- var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
186
-
187
-
188
-
189
- var parentnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
190
-
191
- var childnumbers = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0 };
192
-
193
-
194
-
195
- for( var i = 0; i < 5; i++ ){
196
-
197
- parentnumbers[cutparentcardnum[i]]++;
198
-
199
- childnumbers[cutchildcardnum[i]]++;
200
-
201
- }
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
- function judgment(numbers, score, sameCount) {
210
-
211
- if(high_card(numbers, score)){
212
-
213
- return "ハイカード";
214
-
215
- }else if(is_one(numbers, score)){
216
-
217
- return "ワンペア";
218
-
219
- }else if(two_pare(sameCount, score)){
220
-
221
- return "ツーペア";
222
-
223
- }else if(three_pare(numbers, score)){
224
-
225
- return "スリーオブアカインド";
226
-
227
- }else if(straight(numbers, score)){
228
-
229
- return "ストレート";
230
-
231
- }else if(isFlash(numbers, score)){
232
-
233
- return "フラッシュ";
234
-
235
- }else if(full_house(sameCount, score)){
236
-
237
- return "フルハウス";
238
-
239
- }else if(four_card(numbers, score)){
240
-
241
- return "フォーカード";
242
-
243
- }else if(straight_flash(numbers, score)){
244
-
245
- return "ストレートフラッシュ";
246
-
247
- }else if(royal_flash(numbers, score)){
248
-
249
- return "ロイヤルフラッシュ";
250
-
251
- }
252
-
253
- }
254
-
255
- var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
256
-
257
- var koResult = judgment(childnumbers, childscore, childsameCount);
258
-
259
-
260
-
261
-
262
-
263
- console.log(judgment(oyaResult));
264
-
265
- console.log(judgment(koResult));
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
- function high_card(numbers, score) {
274
-
275
- if (numbers === 0) {
276
-
277
- return score = 1000
278
-
279
- }
280
-
281
- }
282
-
283
-
284
-
285
- function is_one(numbers, score) {
286
-
287
- for (var i = 0; i < 13; i++) {
288
-
289
- if (numbers === 2) {
290
-
291
- return score = 2000;
292
-
293
- }
294
-
295
- }
296
-
297
- }
298
-
299
-
300
-
301
- function four_card(numbers, score) {
302
-
303
- for (var i = 0; i < 13; i++) {
304
-
305
- if (numbers === 4) {
306
-
307
- return score = 8000;
308
-
309
- }
310
-
311
- }
312
-
313
- }
314
-
315
-
316
-
317
- function three_pare(numbers, score) {
318
-
319
- for (var i = 0; i < 13; i++) {
320
-
321
- if (numbers === 3) {
322
-
323
- return score = 4000;
324
-
325
- }
326
-
327
- }
328
-
329
- }
330
-
331
-
332
-
333
- var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
334
-
335
- var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
336
-
337
-
338
-
339
- function two_pare(sameCount, score) {
340
-
341
- if(sameCount === 2 ){
342
-
343
- return score = 3000;
344
-
345
- }
346
-
347
- }
348
-
349
-
350
-
351
- var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
352
-
353
-
354
-
355
- function straight(numbers, score) {
356
-
357
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
358
-
359
- return score = 5000;
360
-
361
- }
362
-
363
- }
364
-
365
-
366
-
367
- function full_house(sameCount, score) {
368
-
369
- if(sameCount[3] == 1 && sameCount[2] == 1){
370
-
371
- return score = 7000;
372
-
373
- }
374
-
375
- }
376
-
377
-
378
-
379
- function straight_flash(numbers, score) {
380
-
381
- for(var i = 1; i <= 9; i++ ){
382
-
383
- if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
384
-
385
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
386
-
387
- return score = 9000;
388
-
389
- }
390
-
391
- }
392
-
393
- }
394
-
395
- }
396
-
397
-
398
-
399
- function royal_flash(numbers, score) {
400
-
401
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
402
-
403
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
404
-
405
- return score = 10000;
406
-
407
- } else {
408
-
409
- return score = 5000;
410
-
411
- }
412
-
413
- }
414
-
415
- }
416
-
417
-
418
-
419
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
420
-
421
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
422
-
423
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
424
-
425
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
426
-
427
-
428
-
429
-
430
-
431
- if (parentlow === 1) {
432
-
433
- var parenthigh = 20
434
-
435
- } else if (parentscore === 0) {
436
-
437
- parentscore = parenthigh
438
-
439
- }
440
-
441
-
442
-
443
- if (childlow === 1) {
444
-
445
- var childhigh = 20
446
-
447
- } else if (childscore === 0) {
448
-
449
- childscore = childhigh
450
-
451
- }
452
-
453
-
454
-
455
- result (parentscore, childscore);
456
-
457
- },false)
458
-
459
-
460
-
461
-
462
-
463
- function isFlash (cards) {
464
-
465
- var [first, other] = cards;
466
-
467
- return other.every (c => first[0] == c[0])
468
-
469
- ? {yaku: "フラッシュ", score: 6000 }
470
-
471
- : null;
472
-
473
- }
474
-
475
-
476
-
477
-
478
-
479
- function childhand (mess) {
480
-
481
- document.getElementById("childhand").innerHTML = mess;
482
-
483
- }
484
-
485
-
486
-
487
- function parenthand (mess) {
488
-
489
- document.getElementById("parenthand").innerHTML = mess;
490
-
491
- }
492
-
493
-
494
-
495
- function result (parentscore, childscore) {
496
-
497
- var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
498
-
499
-
500
-
501
- if (parentscore !== childscore)
502
-
503
- (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
504
-
505
-
506
-
507
-
508
-
509
- document.getElementById("parentbattle").innerHTML = mess[parent];
510
-
511
- document.getElementById("childbattle").innerHTML = mess[child];
512
-
513
- }
514
-
515
-
516
-
517
-
518
-
519
- ```
520
-
521
-
522
-
523
435
  ### 補足情報
524
436
 
525
437
  上記のコード変更いたしました。

4

コード編集

2020/03/16 09:50

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -154,7 +154,9 @@
154
154
 
155
155
 
156
156
 
157
+
158
+
157
- var parent = isFlash (parentcard);
159
+ isFlash (parentcard);
158
160
 
159
161
  var child = isFlash (childcard);
160
162
 
@@ -202,103 +204,67 @@
202
204
 
203
205
 
204
206
 
205
- function poker() {
206
-
207
- switch(judgment()){
208
-
209
- case 1:
210
-
211
- return "ハイカード";
212
-
213
- case 2:
214
-
215
- return "ワンペア";
216
-
217
- case 3:
218
-
219
- return "ツーペア";
220
-
221
- case 4:
222
-
223
- return "スリーオブアカインド";
224
-
225
- case 5:
226
-
227
- return "ストレート";
228
-
229
- case 6:
230
-
231
- return "フラッシュ";
232
-
233
- case 7:
234
-
235
- return "フルハウス";
236
-
237
- case 8:
238
-
239
- return "フォーカード";
240
-
241
- case 9:
242
-
243
- return "ストレートフラッシュ";
244
-
245
- case 10:
246
-
247
- return "ロイヤルフラッシュ";
248
-
249
- }
250
-
251
- }
252
-
253
- poker();
254
-
255
-
256
-
257
- function judgment() {
258
-
259
- if(high_card()){
260
-
261
- return 1;
262
-
263
- }else if(is_one()){
264
-
265
- return 2;
266
-
267
- }else if(two_pare()){
268
-
269
- return 3;
270
-
271
- }else if(three_pare()){
272
-
273
- return 4;
274
-
275
- }else if(straight()){
276
-
277
- return 5;
278
-
279
- }else if(isFlash()){
280
-
281
- return 6;
282
-
283
- }else if(full_house()){
284
-
285
- return 7;
286
-
287
- }else if(four_card()){
288
-
289
- return 8;
290
-
291
- }else if(straight_flash()){
292
-
293
- return 9;
294
-
295
- }else if(royal_flash()){
296
-
297
- return 10;
298
-
299
- }
300
-
301
- }
207
+
208
+
209
+ function judgment(numbers, score, sameCount) {
210
+
211
+ if(high_card(numbers, score)){
212
+
213
+ return "ハイカード";
214
+
215
+ }else if(is_one(numbers, score)){
216
+
217
+ return "ワンペア";
218
+
219
+ }else if(two_pare(sameCount, score)){
220
+
221
+ return "ツーペア";
222
+
223
+ }else if(three_pare(numbers, score)){
224
+
225
+ return "スリーオブアカインド";
226
+
227
+ }else if(straight(numbers, score)){
228
+
229
+ return "ストレート";
230
+
231
+ }else if(isFlash(numbers, score)){
232
+
233
+ return "フラッシュ";
234
+
235
+ }else if(full_house(sameCount, score)){
236
+
237
+ return "フルハウス";
238
+
239
+ }else if(four_card(numbers, score)){
240
+
241
+ return "フォーカード";
242
+
243
+ }else if(straight_flash(numbers, score)){
244
+
245
+ return "ストレートフラッシュ";
246
+
247
+ }else if(royal_flash(numbers, score)){
248
+
249
+ return "ロイヤルフラッシュ";
250
+
251
+ }
252
+
253
+ }
254
+
255
+ var oyaResult = judgment(parentnumbers, parentscore, parentsameCount);
256
+
257
+ var koResult = judgment(childnumbers, childscore, childsameCount);
258
+
259
+
260
+
261
+
262
+
263
+ console.log(judgment(oyaResult));
264
+
265
+ console.log(judgment(koResult));
266
+
267
+
302
268
 
303
269
 
304
270
 
@@ -308,27 +274,21 @@
308
274
 
309
275
  if (numbers === 0) {
310
276
 
311
- score = 1000
277
+ return score = 1000
312
278
 
313
279
  }
314
280
 
315
281
  }
316
282
 
317
- var parent = high_card(parentnumbers, parentscore);
318
-
319
- var child = high_card(childnumbers, childscore);
320
-
321
-
322
-
323
283
 
324
284
 
325
285
  function is_one(numbers, score) {
326
286
 
327
287
  for (var i = 0; i < 13; i++) {
328
288
 
329
- if (numbers[i] === 2) {
289
+ if (numbers === 2) {
330
-
290
+
331
- score = 2000;
291
+ return score = 2000;
332
292
 
333
293
  }
334
294
 
@@ -336,21 +296,15 @@
336
296
 
337
297
  }
338
298
 
339
- var parent = is_one(parentnumbers, parentscore);
340
-
341
- var child = is_one(childnumbers, childscore);
342
-
343
-
344
-
345
299
 
346
300
 
347
301
  function four_card(numbers, score) {
348
302
 
349
303
  for (var i = 0; i < 13; i++) {
350
304
 
351
- if (numbers[i] === 4) {
305
+ if (numbers === 4) {
352
-
306
+
353
- score = 8000;
307
+ return score = 8000;
354
308
 
355
309
  }
356
310
 
@@ -358,23 +312,15 @@
358
312
 
359
313
  }
360
314
 
361
- var parent = four_card(parentnumbers, parentscore);
362
-
363
- var child = four_card(childnumbers, childscore);
364
-
365
-
366
-
367
-
368
-
369
315
 
370
316
 
371
317
  function three_pare(numbers, score) {
372
318
 
373
319
  for (var i = 0; i < 13; i++) {
374
320
 
375
- if (numbers[i] === 3) {
321
+ if (numbers === 3) {
376
-
322
+
377
- score = 4000;
323
+ return score = 4000;
378
324
 
379
325
  }
380
326
 
@@ -384,233 +330,181 @@
384
330
 
385
331
 
386
332
 
387
- var parent = three_pare(parentnumbers, parentscore);
388
-
389
- var child = three_pare(childnumbers, childscore);
390
-
391
-
392
-
393
-
394
-
395
333
  var parentsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
396
334
 
397
335
  var childsameCount = { 0:0, 1:0, 2:0, 3:0, 4:0 };
398
336
 
399
337
 
400
338
 
401
- for(var i = 1; i <= 13; i++){
402
-
403
- parentsameCount[parentnumbers[i]]++;
339
+ function two_pare(sameCount, score) {
404
-
340
+
405
- childsameCount[childnumbers[i]]++;
341
+ if(sameCount === 2 ){
342
+
406
-
343
+ return score = 3000;
344
+
407
- }
345
+ }
346
+
347
+ }
348
+
349
+
350
+
351
+ var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
352
+
353
+
354
+
355
+ function straight(numbers, score) {
356
+
357
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
358
+
359
+ return score = 5000;
360
+
361
+ }
362
+
363
+ }
364
+
365
+
366
+
367
+ function full_house(sameCount, score) {
368
+
369
+ if(sameCount[3] == 1 && sameCount[2] == 1){
370
+
371
+ return score = 7000;
372
+
373
+ }
374
+
375
+ }
376
+
377
+
378
+
379
+ function straight_flash(numbers, score) {
380
+
381
+ for(var i = 1; i <= 9; i++ ){
382
+
383
+ if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
384
+
385
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
386
+
387
+ return score = 9000;
388
+
389
+ }
390
+
391
+ }
392
+
393
+ }
394
+
395
+ }
396
+
397
+
398
+
399
+ function royal_flash(numbers, score) {
400
+
401
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
402
+
403
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
404
+
405
+ return score = 10000;
406
+
407
+ } else {
408
+
409
+ return score = 5000;
410
+
411
+ }
412
+
413
+ }
414
+
415
+ }
416
+
417
+
418
+
419
+ var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
420
+
421
+ var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
422
+
423
+ var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
424
+
425
+ var childlow = Math.min.apply(null, cutchildcardnum) + 1;
426
+
427
+
428
+
429
+
430
+
431
+ if (parentlow === 1) {
432
+
433
+ var parenthigh = 20
434
+
435
+ } else if (parentscore === 0) {
436
+
437
+ parentscore = parenthigh
438
+
439
+ }
440
+
441
+
442
+
443
+ if (childlow === 1) {
444
+
445
+ var childhigh = 20
446
+
447
+ } else if (childscore === 0) {
448
+
449
+ childscore = childhigh
450
+
451
+ }
452
+
453
+
454
+
455
+ result (parentscore, childscore);
456
+
457
+ },false)
458
+
459
+
460
+
461
+
462
+
463
+ function isFlash (cards) {
464
+
465
+ var [first, other] = cards;
466
+
467
+ return other.every (c => first[0] == c[0])
468
+
469
+ ? {yaku: "フラッシュ", score: 6000 }
470
+
471
+ : null;
472
+
473
+ }
474
+
475
+
476
+
477
+
478
+
479
+ function childhand (mess) {
480
+
481
+ document.getElementById("childhand").innerHTML = mess;
482
+
483
+ }
484
+
485
+
486
+
487
+ function parenthand (mess) {
488
+
489
+ document.getElementById("parenthand").innerHTML = mess;
490
+
491
+ }
492
+
493
+
494
+
495
+ function result (parentscore, childscore) {
496
+
497
+ var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
498
+
499
+
500
+
501
+ if (parentscore !== childscore)
502
+
503
+ (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
408
504
 
409
505
 
410
506
 
411
-
412
-
413
- function two_pare(sameCount, score) {
507
+
414
-
415
- if(sameCount[2] === 2 ){
416
-
417
- score = 3000;
418
-
419
- }
420
-
421
- }
422
-
423
- var parent = two_pare(parentsameCount, parentscore);
424
-
425
- var child = two_pare(childsameCount, childscore);
426
-
427
-
428
-
429
-
430
-
431
- function straight(numbers, score) {
432
-
433
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
434
-
435
- score = 5000;
436
-
437
- }
438
-
439
- }
440
-
441
- var parent = two_pare(parentsameCount, parentscore);
442
-
443
- var child = two_pare(childsameCount, childscore);
444
-
445
-
446
-
447
-
448
-
449
- function full_house(sameCount, score) {
450
-
451
- if(sameCount[3] == 1 && sameCount[2] == 1){
452
-
453
- score = 7000;
454
-
455
- }
456
-
457
- }
458
-
459
- var parent = two_pare(parentsameCount, parentscore);
460
-
461
- var child = two_pare(childsameCount, childscore);
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
- function straight_flash(numbers, score) {
470
-
471
- for(var i = 1; i <= 9; i++ ){
472
-
473
- if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
474
-
475
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
476
-
477
- score = 9000;
478
-
479
- }
480
-
481
- }
482
-
483
- }
484
-
485
- }
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
- var parent = four_card(parentnumbers, parentscore);
494
-
495
- var child = four_card(childnumbers, childscore);
496
-
497
-
498
-
499
- function royal_flash(numbers, score) {
500
-
501
- if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
502
-
503
- if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
504
-
505
- score = 10000;
506
-
507
- } else {
508
-
509
- score = 5000;
510
-
511
- }
512
-
513
- }
514
-
515
- }
516
-
517
-
518
-
519
- var parent = four_card(parentnumbers, parentscore);
520
-
521
- var child = four_card(childnumbers, childscore);
522
-
523
-
524
-
525
-
526
-
527
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
528
-
529
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
530
-
531
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
532
-
533
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
534
-
535
-
536
-
537
-
538
-
539
- if (parentlow === 1) {
540
-
541
- var parenthigh = 20
542
-
543
- } else if (parentscore === 0) {
544
-
545
- parentscore = parenthigh
546
-
547
- }
548
-
549
-
550
-
551
- if (childlow === 1) {
552
-
553
- var childhigh = 20
554
-
555
- } else if (childscore === 0) {
556
-
557
- childscore = childhigh
558
-
559
- }
560
-
561
-
562
-
563
- result (parentscore, childscore);
564
-
565
- },false)
566
-
567
-
568
-
569
-
570
-
571
- function isFlash (cards) {
572
-
573
- var [first, other] = cards;
574
-
575
- return other.every (c => first[0] == c[0])
576
-
577
- ? {yaku: "フラッシュ", score: 6000 }
578
-
579
- : null;
580
-
581
- }
582
-
583
-
584
-
585
-
586
-
587
- function childhand (mess) {
588
-
589
- document.getElementById("childhand").innerHTML = mess;
590
-
591
- }
592
-
593
-
594
-
595
- function parenthand (mess) {
596
-
597
- document.getElementById("parenthand").innerHTML = mess;
598
-
599
- }
600
-
601
-
602
-
603
- function result (parentscore, childscore) {
604
-
605
- var mess = ["DRAW", "LOSE", "WIN"], parent = 0, child = 0;
606
-
607
-
608
-
609
- if (parentscore !== childscore)
610
-
611
- (parentscore > childscore) ? (parent = 2, child = 1): (parent = 1, child = 2);
612
-
613
-
614
508
 
615
509
  document.getElementById("parentbattle").innerHTML = mess[parent];
616
510
 
@@ -618,14 +512,14 @@
618
512
 
619
513
  }
620
514
 
515
+
516
+
517
+
518
+
621
519
  ```
622
520
 
623
521
 
624
522
 
625
523
  ### 補足情報
626
524
 
627
-
628
-
629
- judgment()でワンペアの関数などの場合はreturnで数値を渡し、
630
-
631
- 上のpoker()とう関数で役名を出したいです
525
+ コード変更ました。

3

文法

2020/03/16 06:24

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -250,6 +250,10 @@
250
250
 
251
251
  }
252
252
 
253
+ poker();
254
+
255
+
256
+
253
257
  function judgment() {
254
258
 
255
259
  if(high_card()){

2

コード修正

2020/03/16 01:28

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -102,7 +102,7 @@
102
102
 
103
103
 
104
104
 
105
- ```Javascript
105
+ ```javascript
106
106
 
107
107
  var parentcard = [...document.querySelectorAll ("#parent > div")]
108
108
 
@@ -158,8 +158,6 @@
158
158
 
159
159
  var child = isFlash (childcard);
160
160
 
161
-
162
-
163
161
  if (parent) {
164
162
 
165
163
  parenthand (parent.yaku);
@@ -182,9 +180,7 @@
182
180
 
183
181
 
184
182
 
185
- var parentmsuits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
186
-
187
- var childmsuits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
183
+ var suits = { "Spade":0, "Heart":0, "Daiya":0, "Clover":0 };
188
184
 
189
185
 
190
186
 
@@ -204,63 +200,191 @@
204
200
 
205
201
 
206
202
 
207
- for (var i = 0; i < 13; i++) {
208
-
209
- if (parentnumbers[i] === 4) {
210
-
211
- parenthand("フォーカード");
212
-
213
- var parentscore = 8000
214
-
215
- } else if (childnumbers[i] === 4) {
216
-
217
- childhand ("フォーカード");
218
-
219
- var childscore = 8000
220
-
221
- }
222
-
223
- }
224
-
225
-
226
-
227
- for (var i = 0; i < 13; i++) {
228
-
229
- if (parentnumbers[i] === 3) {
230
-
231
- parenthand("スオブアカインド");
232
-
233
- var parentscore = 4000
234
-
235
- } else if (childnumbers[i] === 3) {
236
-
237
- childhand("スリーオブアカインド");
238
-
239
- var childscore = 4000
240
-
241
- }
242
-
243
- }
244
-
245
-
246
-
247
- for (var i = 0; i < 13; i++) {
248
-
249
- if (parentnumbers[i] === 2) {
250
-
251
- parenthand("ワンペア");
252
-
253
- var parentscore = 2000
254
-
255
- } else if (childnumbers[i] === 2) {
256
-
257
- childhand("ワンペア");
258
-
259
- var childscore = 2000
260
-
261
- }
262
-
263
- }
203
+
204
+
205
+ function poker() {
206
+
207
+ switch(judgment()){
208
+
209
+ case 1:
210
+
211
+ return "ハイカード";
212
+
213
+ case 2:
214
+
215
+ return "ワンペア";
216
+
217
+ case 3:
218
+
219
+ return "ツーペア";
220
+
221
+ case 4:
222
+
223
+ return "スリーオブアカインド";
224
+
225
+ case 5:
226
+
227
+ return "ストレ";
228
+
229
+ case 6:
230
+
231
+ return "フラッシュ";
232
+
233
+ case 7:
234
+
235
+ return "フルハウス";
236
+
237
+ case 8:
238
+
239
+ return "フォーカード";
240
+
241
+ case 9:
242
+
243
+ return "ストレートフラッシュ";
244
+
245
+ case 10:
246
+
247
+ return "ロイヤルフラッシュ";
248
+
249
+ }
250
+
251
+ }
252
+
253
+ function judgment() {
254
+
255
+ if(high_card()){
256
+
257
+ return 1;
258
+
259
+ }else if(is_one()){
260
+
261
+ return 2;
262
+
263
+ }else if(two_pare()){
264
+
265
+ return 3;
266
+
267
+ }else if(three_pare()){
268
+
269
+ return 4;
270
+
271
+ }else if(straight()){
272
+
273
+ return 5;
274
+
275
+ }else if(isFlash()){
276
+
277
+ return 6;
278
+
279
+ }else if(full_house()){
280
+
281
+ return 7;
282
+
283
+ }else if(four_card()){
284
+
285
+ return 8;
286
+
287
+ }else if(straight_flash()){
288
+
289
+ return 9;
290
+
291
+ }else if(royal_flash()){
292
+
293
+ return 10;
294
+
295
+ }
296
+
297
+ }
298
+
299
+
300
+
301
+
302
+
303
+ function high_card(numbers, score) {
304
+
305
+ if (numbers === 0) {
306
+
307
+ score = 1000
308
+
309
+ }
310
+
311
+ }
312
+
313
+ var parent = high_card(parentnumbers, parentscore);
314
+
315
+ var child = high_card(childnumbers, childscore);
316
+
317
+
318
+
319
+
320
+
321
+ function is_one(numbers, score) {
322
+
323
+ for (var i = 0; i < 13; i++) {
324
+
325
+ if (numbers[i] === 2) {
326
+
327
+ score = 2000;
328
+
329
+ }
330
+
331
+ }
332
+
333
+ }
334
+
335
+ var parent = is_one(parentnumbers, parentscore);
336
+
337
+ var child = is_one(childnumbers, childscore);
338
+
339
+
340
+
341
+
342
+
343
+ function four_card(numbers, score) {
344
+
345
+ for (var i = 0; i < 13; i++) {
346
+
347
+ if (numbers[i] === 4) {
348
+
349
+ score = 8000;
350
+
351
+ }
352
+
353
+ }
354
+
355
+ }
356
+
357
+ var parent = four_card(parentnumbers, parentscore);
358
+
359
+ var child = four_card(childnumbers, childscore);
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+ function three_pare(numbers, score) {
368
+
369
+ for (var i = 0; i < 13; i++) {
370
+
371
+ if (numbers[i] === 3) {
372
+
373
+ score = 4000;
374
+
375
+ }
376
+
377
+ }
378
+
379
+ }
380
+
381
+
382
+
383
+ var parent = three_pare(parentnumbers, parentscore);
384
+
385
+ var child = three_pare(childnumbers, childscore);
386
+
387
+
264
388
 
265
389
 
266
390
 
@@ -280,164 +404,152 @@
280
404
 
281
405
 
282
406
 
283
- if(parentsameCount[2] === 2 ){
284
-
285
- parenthand("ツーペア");
286
-
287
- var parentscore = 3000
288
-
289
- } else if(childsameCount[2] === 2 ){
290
-
291
- childhand("ツーペア");
292
-
293
- var childscore = 3000
294
-
295
- }
296
-
297
-
298
-
299
- if(parentsameCount[3] === 1 && parentsameCount[2] === 1){
300
-
301
- parenthand("フルハウス");
302
-
303
- var parentscore = 7000
304
-
305
- } else if (childsameCount[3] === 1 && childsameCount[2] === 1) {
306
-
307
- childhand("フルハウス");
308
-
309
- var childscore = 7000
310
-
311
- }
312
-
313
-
314
-
315
- for(var i = 1; i <= 9; i++ ){
316
-
317
- if(parentnumbers[i] >= 1 && parentnumbers[i+1] >= 1 && parentnumbers[i+2] >= 1 && parentnumbers[i+3] >= 1 && parentnumbers[i+4] >= 1 ){
318
-
319
- if (parentmsuits["Spade"] === 5 || parentmsuits["Heart"] === 5 || parentmsuits["daiya"] === 5 || parentmsuits["clover"] === 5) {
320
-
321
- parenthand("ストレートフラッシュ");
322
-
323
- var parentscore = 9000
407
+
408
+
409
+ function two_pare(sameCount, score) {
410
+
411
+ if(sameCount[2] === 2 ){
412
+
413
+ score = 3000;
414
+
415
+ }
416
+
417
+ }
418
+
419
+ var parent = two_pare(parentsameCount, parentscore);
420
+
421
+ var child = two_pare(childsameCount, childscore);
422
+
423
+
424
+
425
+
426
+
427
+ function straight(numbers, score) {
428
+
429
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
430
+
431
+ score = 5000;
432
+
433
+ }
434
+
435
+ }
436
+
437
+ var parent = two_pare(parentsameCount, parentscore);
438
+
439
+ var child = two_pare(childsameCount, childscore);
440
+
441
+
442
+
443
+
444
+
445
+ function full_house(sameCount, score) {
446
+
447
+ if(sameCount[3] == 1 && sameCount[2] == 1){
448
+
449
+ score = 7000;
450
+
451
+ }
452
+
453
+ }
454
+
455
+ var parent = two_pare(parentsameCount, parentscore);
456
+
457
+ var child = two_pare(childsameCount, childscore);
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+ function straight_flash(numbers, score) {
466
+
467
+ for(var i = 1; i <= 9; i++ ){
468
+
469
+ if(numbers[i] >= 1 && numbers[i+1] >= 1 && numbers[i+2] >= 1 && numbers[i+3] >= 1 && numbers[i+4] >= 1 ){
470
+
471
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
472
+
473
+ score = 9000;
474
+
475
+ }
476
+
477
+ }
478
+
479
+ }
480
+
481
+ }
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+ var parent = four_card(parentnumbers, parentscore);
490
+
491
+ var child = four_card(childnumbers, childscore);
492
+
493
+
494
+
495
+ function royal_flash(numbers, score) {
496
+
497
+ if(numbers[9] >= 1 && numbers[10] >= 1 && numbers[11] >= 1 && numbers[12] >= 1 && numbers[0] >= 1){
498
+
499
+ if (suits["Spade"] === 5 || suits["Heart"] === 5 || suits["daiya"] === 5 || suits["clover"] === 5) {
500
+
501
+ score = 10000;
324
502
 
325
503
  } else {
326
504
 
327
- parenthand("ストレート");
328
-
329
- var parentscore = 5000
505
+ score = 5000;
330
506
 
331
507
  }
332
508
 
333
509
  }
334
510
 
335
-
336
-
337
- if(childnumbers[i] >= 1 && childnumbers[i+1] >= 1 && childnumbers[i+2] >= 1 && childnumbers[i+3] >= 1 && childnumbers[i+4] >= 1){
338
-
339
- if (childmsuits["Spade"] === 5 || childmsuits["Heart"] === 5 || childmsuits["daiya"] === 5 || childmsuits["clover"] === 5) {
340
-
341
- childhand("ストレートフラッシュ");
342
-
343
- var childscore = 9000
344
-
345
- } else {
346
-
347
- childhand("ストレート");
348
-
349
- var childscore = 5000
350
-
351
- }
352
-
353
- }
354
-
355
- }
356
-
357
-
358
-
359
- if(parentnumbers[9] >= 1 && parentnumbers[10] >= 1 && parentnumbers[11] >= 1 && parentnumbers[12] >= 1 && parentnumbers[0] >= 1){
360
-
361
- if (parentmsuits["Spade"] === 5 || parentmsuits["Heart"] === 5 || parentmsuits["daiya"] === 5 || parentmsuits["clover"] === 5) {
362
-
363
- parenthand("ロイヤルフラッシュ");
364
-
365
- var parentscore = 10000
366
-
367
- } else {
368
-
369
- parenthand("ストレート");
370
-
371
- var parentscore = 5000
372
-
373
- }
374
-
375
- }
376
-
377
-
378
-
379
- if(childnumbers[9] >= 1 && childnumbers[10] >= 1 && childnumbers[11] >= 1 && childnumbers[12] >= 1 && childnumbers[0] >= 1){
380
-
381
- if (childmsuits["Spade"] === 5 || childmsuits["Heart"] === 5 || childmsuits["daiya"] === 5 || childmsuits["clover"] === 5) {
382
-
383
- childhand ("ロイヤルフラッシュ");
384
-
385
- var childscore = 10000
386
-
387
- } else {
388
-
389
- childhand ("ストレート");
390
-
391
- var childscore = 5000
392
-
393
- }
394
-
395
- }
396
-
397
- if (parentscore === 0) {
398
-
399
- parenthand("ハイカード");
400
-
401
- var parentscore = 1000
511
+ }
512
+
513
+
514
+
515
+ var parent = four_card(parentnumbers, parentscore);
516
+
517
+ var child = four_card(childnumbers, childscore);
518
+
519
+
520
+
521
+
522
+
523
+ var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
524
+
525
+ var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
526
+
527
+ var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
528
+
529
+ var childlow = Math.min.apply(null, cutchildcardnum) + 1;
530
+
531
+
532
+
533
+
534
+
535
+ if (parentlow === 1) {
536
+
537
+ var parenthigh = 20
538
+
539
+ } else if (parentscore === 0) {
540
+
541
+ parentscore = parenthigh
542
+
543
+ }
544
+
545
+
546
+
547
+ if (childlow === 1) {
548
+
549
+ var childhigh = 20
402
550
 
403
551
  } else if (childscore === 0) {
404
552
 
405
- childhand("ハイカード");
406
-
407
- var childscore = 1000
408
-
409
- }
410
-
411
-
412
-
413
- var parenthigh = Math.max.apply(null, cutparentcardnum) + 1;
414
-
415
- var childhigh = Math.max.apply(null, cutchildcardnum) + 1;
416
-
417
- var parentlow = Math.min.apply(null, cutparentcardnum) + 1;
418
-
419
- var childlow = Math.min.apply(null, cutchildcardnum) + 1;
420
-
421
-
422
-
423
- if (parentlow === 1) {
424
-
425
- var parenthigh = 20
426
-
427
- } else if (parentscore === 0) {
428
-
429
- parentscore = parenthigh
430
-
431
- }
432
-
433
-
434
-
435
- if (childlow === 1) {
436
-
437
- var childhigh = 20
438
-
439
- } else if (childscore === 0) {
440
-
441
553
  childscore = childhigh
442
554
 
443
555
  }
@@ -466,6 +578,8 @@
466
578
 
467
579
 
468
580
 
581
+
582
+
469
583
  function childhand (mess) {
470
584
 
471
585
  document.getElementById("childhand").innerHTML = mess;
@@ -494,9 +608,9 @@
494
608
 
495
609
 
496
610
 
497
- document.getElementById("parentbattle").innerHTML = mess[parent];
611
+ document.getElementById("parentbattle").innerHTML = mess[parent];
498
-
612
+
499
- document.getElementById("childbattle").innerHTML = mess[child];
613
+ document.getElementById("childbattle").innerHTML = mess[child];
500
614
 
501
615
  }
502
616
 
@@ -504,168 +618,6 @@
504
618
 
505
619
 
506
620
 
507
- ### 試したこと
508
-
509
-
510
-
511
- ```javascript
512
-
513
- function poker() {
514
-
515
- switch(judgment()){
516
-
517
- case 1:
518
-
519
- return "ハイカード";
520
-
521
- case 2:
522
-
523
- return "ワンペア";
524
-
525
- case 3:
526
-
527
- return "ツーペア";
528
-
529
- case 4:
530
-
531
- return "スリーオブアカインド";
532
-
533
- case 5:
534
-
535
- return "ストレート";
536
-
537
- case 6:
538
-
539
- return "フラッシュ";
540
-
541
- case 7:
542
-
543
- return "フルハウス";
544
-
545
- case 8:
546
-
547
- return "フォーカード";
548
-
549
- case 9:
550
-
551
- return "ストレートフラッシュ";
552
-
553
- case 10:
554
-
555
- return "ロイヤルフラッシュ";
556
-
557
- }
558
-
559
- }
560
-
561
- function judgment() {
562
-
563
- if(high_card()){
564
-
565
- return 1;
566
-
567
- }else if(is_one()){
568
-
569
- return 2;
570
-
571
- }else if(two_pare()){
572
-
573
- return 3;
574
-
575
- }else if(three_pare()){
576
-
577
- return 4;
578
-
579
- }else if(straight()){
580
-
581
- return 5;
582
-
583
- }else if(isFlash()){
584
-
585
- return 6;
586
-
587
- }else if(full_house()){
588
-
589
- return 7;
590
-
591
- }else if(four_card()){
592
-
593
- return 8;
594
-
595
- }else if(straight_flash()){
596
-
597
- return 9;
598
-
599
- }else if(royal_flash()){
600
-
601
- return 10;
602
-
603
- }
604
-
605
- }
606
-
607
-
608
-
609
- function high_card(numbers, score) {
610
-
611
- if (numbers === 0) {
612
-
613
- score = 1000
614
-
615
- }
616
-
617
- }
618
-
619
- var oya = high_card(parentnumbers, parentscore);
620
-
621
- var ko = high_card(childnumbers, childscore);
622
-
623
- function is_one(numbers, score) {
624
-
625
- for (var i = 0; i < 13; i++) {
626
-
627
- if (numbers[i] === 2) {
628
-
629
- score = 2000;
630
-
631
- }
632
-
633
- }
634
-
635
- }
636
-
637
- var oya = is_one(parentnumbers, parentscore);
638
-
639
- var ko = is_one(childnumbers, childscore);
640
-
641
- function four_card(numbers, score) {
642
-
643
- for (var i = 0; i < 13; i++) {
644
-
645
- if (numbers[i] === 4) {
646
-
647
- score = 8000;
648
-
649
- }
650
-
651
- }
652
-
653
- }
654
-
655
- var oya = four_card(parentnumbers, parentscore);
656
-
657
- var ko = four_card(childnumbers, childscore);
658
-
659
-
660
-
661
- //こんな感じで全ての役をしています。
662
-
663
- //コードが入らなかったので省略します。
664
-
665
- ```
666
-
667
-
668
-
669
621
  ### 補足情報
670
622
 
671
623
 

1

文法の修正

2020/03/15 23:25

投稿

t_t_t_t_t_t
t_t_t_t_t_t

スコア10

test CHANGED
File without changes
test CHANGED
@@ -666,8 +666,10 @@
666
666
 
667
667
 
668
668
 
669
- ### 補足情報(FW/ツールのバージョンなど)
669
+ ### 補足情報
670
-
671
-
672
-
670
+
671
+
672
+
673
- 関数でまとめたが、役名と勝敗出す記述をどうすれば良いのかご教授お願います。
673
+ judgment()でワンペアの関数などの場合はreturn数値
674
+
675
+ 上のpoker()という関数で役名を出したいです。