回答編集履歴
6
クラス名を英語オセロルールの用語に変更
test
CHANGED
@@ -6,19 +6,21 @@
|
|
6
6
|
|
7
7
|
```java
|
8
8
|
|
9
|
+
import java.util.*;
|
10
|
+
|
11
|
+
import java.util.stream.*;
|
12
|
+
|
9
13
|
import java.awt.*;
|
10
14
|
|
15
|
+
import java.awt.Point;
|
16
|
+
|
17
|
+
import java.awt.event.*;
|
18
|
+
|
11
19
|
import javax.swing.*;
|
12
20
|
|
13
|
-
|
21
|
+
|
14
|
-
|
15
|
-
|
22
|
+
|
16
|
-
|
17
|
-
import java.util.stream.*;
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
interface
|
23
|
+
interface Disk {
|
22
24
|
|
23
25
|
public void paint(Graphics g, Point p, int size);
|
24
26
|
|
@@ -28,15 +30,15 @@
|
|
28
30
|
|
29
31
|
|
30
32
|
|
31
|
-
class
|
33
|
+
class Disks {
|
32
|
-
|
34
|
+
|
33
|
-
static final
|
35
|
+
static final Disk NONE, BLACK, WHITE;
|
34
36
|
|
35
37
|
|
36
38
|
|
37
39
|
static {
|
38
40
|
|
39
|
-
NONE = new
|
41
|
+
NONE = new Disk() {
|
40
42
|
|
41
43
|
public void paint(Graphics g, Point p, int size) {
|
42
44
|
|
@@ -54,7 +56,7 @@
|
|
54
56
|
|
55
57
|
|
56
58
|
|
57
|
-
BLACK = new
|
59
|
+
BLACK = new Disk() {
|
58
60
|
|
59
61
|
public void paint(Graphics g, Point p, int size) {
|
60
62
|
|
@@ -78,7 +80,7 @@
|
|
78
80
|
|
79
81
|
|
80
82
|
|
81
|
-
WHITE = new
|
83
|
+
WHITE = new Disk() {
|
82
84
|
|
83
85
|
public void paint(Graphics g, Point p, int size) {
|
84
86
|
|
@@ -104,7 +106,7 @@
|
|
104
106
|
|
105
107
|
|
106
108
|
|
107
|
-
private static final Map<
|
109
|
+
private static final Map<Disk, Disk> OPPOSITE = new HashMap<Disk, Disk>() {
|
108
110
|
|
109
111
|
{
|
110
112
|
|
@@ -120,9 +122,9 @@
|
|
120
122
|
|
121
123
|
|
122
124
|
|
123
|
-
static
|
125
|
+
static Disk opposite(Disk disk) {
|
124
|
-
|
126
|
+
|
125
|
-
return OPPOSITE.get(s
|
127
|
+
return OPPOSITE.get(disk);
|
126
128
|
|
127
129
|
}
|
128
130
|
|
@@ -130,47 +132,39 @@
|
|
130
132
|
|
131
133
|
|
132
134
|
|
133
|
-
class
|
135
|
+
class Square {
|
134
|
-
|
136
|
+
|
135
|
-
private
|
137
|
+
private Disk disk;
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
|
139
|
+
|
140
|
+
|
139
|
-
|
141
|
+
Square() {
|
140
|
-
|
142
|
+
|
141
|
-
this.s
|
143
|
+
this.disk = Disks.NONE;
|
142
|
-
|
144
|
+
|
143
|
-
}
|
145
|
+
}
|
144
|
-
|
145
|
-
|
146
|
-
|
146
|
+
|
147
|
+
|
148
|
+
|
147
|
-
boolean is_e
|
149
|
+
boolean is_used() {
|
148
|
-
|
150
|
+
|
149
|
-
return this.s
|
151
|
+
return this.disk != Disks.NONE;
|
150
|
-
|
152
|
+
|
151
|
-
}
|
153
|
+
}
|
152
|
-
|
153
|
-
|
154
|
-
|
154
|
+
|
155
|
+
|
156
|
+
|
155
|
-
boolean is(
|
157
|
+
boolean is(Disk disk) {
|
156
|
-
|
158
|
+
|
157
|
-
return this.s
|
159
|
+
return this.disk == disk;
|
158
|
-
|
160
|
+
|
159
|
-
}
|
161
|
+
}
|
160
|
-
|
161
|
-
|
162
|
-
|
162
|
+
|
163
|
+
|
164
|
+
|
163
|
-
void put(
|
165
|
+
void put(Disk disk) {
|
164
|
-
|
166
|
+
|
165
|
-
this.s
|
167
|
+
this.disk = disk;
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
Stone get() {
|
172
|
-
|
173
|
-
return this.stone;
|
174
168
|
|
175
169
|
}
|
176
170
|
|
@@ -178,7 +172,7 @@
|
|
178
172
|
|
179
173
|
void reverse() {
|
180
174
|
|
181
|
-
this.s
|
175
|
+
this.disk = Disks.opposite(this.disk);
|
182
176
|
|
183
177
|
}
|
184
178
|
|
@@ -186,7 +180,15 @@
|
|
186
180
|
|
187
181
|
void paint(Graphics g, Point p, int size) {
|
188
182
|
|
189
|
-
|
183
|
+
disk.paint(g, p, size);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
public String toString() {
|
190
|
+
|
191
|
+
return disk.toString();
|
190
192
|
|
191
193
|
}
|
192
194
|
|
@@ -196,7 +198,7 @@
|
|
196
198
|
|
197
199
|
class Board {
|
198
200
|
|
199
|
-
final
|
201
|
+
final Square[][] squares = new Square[8][8];
|
200
202
|
|
201
203
|
final int[][] eval_black = new int[8][8];
|
202
204
|
|
@@ -204,23 +206,25 @@
|
|
204
206
|
|
205
207
|
|
206
208
|
|
209
|
+
private static final Color COLOR = new Color(0, 85, 0);
|
210
|
+
|
207
211
|
private static final Point[] DIRECTION = {
|
208
212
|
|
209
|
-
new Point(1, 0),
|
210
|
-
|
211
|
-
new Point(1, 1),
|
212
|
-
|
213
|
-
new Point(0, 1),
|
214
|
-
|
215
|
-
new Point(-1, 1),
|
216
|
-
|
217
|
-
new Point(-1, 0),
|
218
|
-
|
219
213
|
new Point(-1, -1),
|
220
214
|
|
221
|
-
new Point(0, -1),
|
215
|
+
new Point( 0, -1),
|
222
|
-
|
216
|
+
|
223
|
-
new Point(1, -1),
|
217
|
+
new Point( 1, -1),
|
218
|
+
|
219
|
+
new Point(-1, 0),
|
220
|
+
|
221
|
+
new Point( 1, 0),
|
222
|
+
|
223
|
+
new Point(-1, 1),
|
224
|
+
|
225
|
+
new Point( 0, 1),
|
226
|
+
|
227
|
+
new Point( 1, 1),
|
224
228
|
|
225
229
|
};
|
226
230
|
|
@@ -232,19 +236,19 @@
|
|
232
236
|
|
233
237
|
for (int y = 0; y < 8; y++) {
|
234
238
|
|
235
|
-
|
239
|
+
squares[x][y] = new Square();
|
236
|
-
|
240
|
+
|
237
|
-
}
|
241
|
+
}
|
238
|
-
|
242
|
+
|
239
|
-
}
|
243
|
+
}
|
244
|
+
|
240
|
-
|
245
|
+
squares[3][3].put(Disks.WHITE);
|
246
|
+
|
241
|
-
|
247
|
+
squares[4][3].put(Disks.BLACK);
|
248
|
+
|
242
|
-
|
249
|
+
squares[3][4].put(Disks.BLACK);
|
250
|
+
|
243
|
-
|
251
|
+
squares[4][4].put(Disks.WHITE);
|
244
|
-
|
245
|
-
mass[4][3].put(Stones.WHITE);
|
246
|
-
|
247
|
-
mass[4][4].put(Stones.BLACK);
|
248
252
|
|
249
253
|
}
|
250
254
|
|
@@ -258,15 +262,15 @@
|
|
258
262
|
|
259
263
|
|
260
264
|
|
261
|
-
long count(
|
265
|
+
long count(Disk disk) {
|
262
|
-
|
266
|
+
|
263
|
-
return Arrays.stream(
|
267
|
+
return Arrays.stream(squares)
|
264
|
-
|
268
|
+
|
265
|
-
|
269
|
+
.flatMap(Stream::of)
|
266
|
-
|
270
|
+
|
267
|
-
|
271
|
+
.filter(m -> m.is(disk))
|
268
|
-
|
272
|
+
|
269
|
-
|
273
|
+
.count();
|
270
274
|
|
271
275
|
}
|
272
276
|
|
@@ -306,29 +310,27 @@
|
|
306
310
|
|
307
311
|
for (Point p: points) {
|
308
312
|
|
309
|
-
|
313
|
+
squares[p.x][p.y].reverse();
|
310
|
-
|
314
|
+
|
311
|
-
}
|
315
|
+
}
|
312
|
-
|
316
|
+
|
313
|
-
}
|
317
|
+
}
|
314
|
-
|
318
|
+
|
315
|
-
}
|
319
|
+
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
+
|
320
|
-
|
321
|
+
|
322
|
+
|
321
|
-
Reversible getReversible(int x, int y, Point d,
|
323
|
+
Reversible getReversible(int x, int y, Point d, Disk s) {
|
324
|
+
|
325
|
+
Reversible reversible = new Reversible();
|
326
|
+
|
327
|
+
Disk opposite = Disks.opposite(s);
|
322
328
|
|
323
329
|
x += d.x;
|
324
330
|
|
325
331
|
y += d.y;
|
326
332
|
|
327
|
-
Reversible reversible = new Reversible();
|
328
|
-
|
329
|
-
Stone opposite = Stones.opposite(s);
|
330
|
-
|
331
|
-
while (isOnBoard(x, y) &&
|
333
|
+
while (isOnBoard(x, y) && squares[x][y].is(opposite)) {
|
332
334
|
|
333
335
|
reversible.add(new Point(x, y));
|
334
336
|
|
@@ -338,7 +340,7 @@
|
|
338
340
|
|
339
341
|
}
|
340
342
|
|
341
|
-
if (!(isOnBoard(x, y) &&
|
343
|
+
if (!(isOnBoard(x, y) && squares[x][y].is(s)))
|
342
344
|
|
343
345
|
reversible.removeAll();
|
344
346
|
|
@@ -348,65 +350,51 @@
|
|
348
350
|
|
349
351
|
|
350
352
|
|
351
|
-
// 盤面(x,y)に石sを置いた場合に反転できる石の数を数える
|
352
|
-
|
353
|
-
int countReverse
|
353
|
+
int countReversible(int x, int y, Disk s) {
|
354
|
-
|
355
|
-
|
354
|
+
|
356
|
-
|
357
|
-
if (
|
355
|
+
if (squares[x][y].is_used())
|
358
356
|
|
359
357
|
return -1;
|
360
358
|
|
361
|
-
|
359
|
+
|
362
|
-
|
363
|
-
|
360
|
+
|
364
|
-
|
365
|
-
|
361
|
+
return Arrays.stream(DIRECTION)
|
366
|
-
|
362
|
+
|
367
|
-
|
363
|
+
.mapToInt(d -> getReversible(x, y, d, s).count())
|
368
|
-
|
364
|
+
|
369
|
-
|
365
|
+
.sum();
|
370
|
-
|
366
|
+
|
371
|
-
}
|
367
|
+
}
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
368
|
+
|
376
|
-
|
369
|
+
|
370
|
+
|
377
|
-
void putAndReverse(int x, int y,
|
371
|
+
void putAndReverse(int x, int y, Disk s) {
|
378
|
-
|
372
|
+
|
379
|
-
|
373
|
+
squares[x][y].put(s);
|
380
|
-
|
381
|
-
|
374
|
+
|
382
|
-
|
383
|
-
|
375
|
+
Arrays.stream(DIRECTION).forEach(d -> getReversible(x, y, d, s).reverse());
|
384
|
-
|
376
|
+
|
385
|
-
}
|
377
|
+
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
378
|
+
|
390
|
-
|
379
|
+
|
380
|
+
|
391
|
-
void evaluate
|
381
|
+
void evaluate() {
|
392
382
|
|
393
383
|
for (int x = 0; x < 8; x++) {
|
394
384
|
|
395
385
|
for (int y = 0; y < 8; y++) {
|
396
386
|
|
397
|
-
eval_black[x][y] = countReverse
|
387
|
+
eval_black[x][y] = countReversible(x, y, Disks.BLACK);
|
398
|
-
|
388
|
+
|
399
|
-
eval_white[x][y] = countReverse
|
389
|
+
eval_white[x][y] = countReversible(x, y, Disks.WHITE);
|
400
|
-
|
390
|
+
|
401
|
-
}
|
391
|
+
}
|
402
|
-
|
392
|
+
|
403
|
-
}
|
393
|
+
}
|
404
|
-
|
394
|
+
|
405
|
-
}
|
395
|
+
}
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
396
|
+
|
397
|
+
|
410
398
|
|
411
399
|
void printBoard() {
|
412
400
|
|
@@ -414,7 +402,7 @@
|
|
414
402
|
|
415
403
|
for (int x = 0; x < 8; x++) {
|
416
404
|
|
417
|
-
System.out.printf("%s ",
|
405
|
+
System.out.printf("%s ", squares[x][y]);
|
418
406
|
|
419
407
|
}
|
420
408
|
|
@@ -426,11 +414,9 @@
|
|
426
414
|
|
427
415
|
|
428
416
|
|
429
|
-
// 盤面の評価結果をコンソールに表示する
|
430
|
-
|
431
|
-
void printEval() {
|
417
|
+
void printEvaluation() {
|
432
|
-
|
418
|
+
|
433
|
-
System.out.println("Black(" +
|
419
|
+
System.out.println("Black(" + Disks.BLACK + "):");
|
434
420
|
|
435
421
|
for (int y = 0; y < 8; y++) {
|
436
422
|
|
@@ -444,7 +430,7 @@
|
|
444
430
|
|
445
431
|
}
|
446
432
|
|
447
|
-
System.out.println("White(" +
|
433
|
+
System.out.println("White(" + Disks.WHITE + "):");
|
448
434
|
|
449
435
|
for (int y = 0; y < 8; y++) {
|
450
436
|
|
@@ -462,69 +448,71 @@
|
|
462
448
|
|
463
449
|
|
464
450
|
|
465
|
-
// 画面描画
|
466
|
-
|
467
|
-
void paint(Graphics g, int u
|
451
|
+
void paint(Graphics g, int square_size) {
|
468
|
-
|
469
|
-
|
470
|
-
|
452
|
+
|
453
|
+
|
454
|
+
|
471
|
-
//
|
455
|
+
// Background
|
472
456
|
|
473
457
|
g.setColor(Color.black);
|
474
458
|
|
475
|
-
g.fillRect(0, 0, u
|
459
|
+
g.fillRect(0, 0, square_size * 10, square_size * 10);
|
476
|
-
|
477
|
-
|
478
|
-
|
460
|
+
|
461
|
+
|
462
|
+
|
479
|
-
//
|
463
|
+
// Board
|
480
|
-
|
464
|
+
|
481
|
-
g.setColor(
|
465
|
+
g.setColor(Board.COLOR);
|
482
|
-
|
466
|
+
|
483
|
-
g.fillRect(u
|
467
|
+
g.fillRect(square_size, square_size, square_size * 8, square_size * 8);
|
484
|
-
|
485
|
-
|
486
|
-
|
468
|
+
|
469
|
+
|
470
|
+
|
487
|
-
//
|
471
|
+
// Horizontal Line
|
488
472
|
|
489
473
|
g.setColor(Color.black);
|
490
474
|
|
491
475
|
for (int x = 0; x < 9; x++) {
|
492
476
|
|
493
|
-
g.drawLine(u
|
477
|
+
g.drawLine(square_size * (x + 1), square_size, square_size * (x + 1), square_size * 9);
|
494
|
-
|
478
|
+
|
495
|
-
}
|
479
|
+
}
|
496
|
-
|
497
|
-
|
498
|
-
|
480
|
+
|
481
|
+
|
482
|
+
|
499
|
-
//
|
483
|
+
// Vertical Line
|
500
484
|
|
501
485
|
g.setColor(Color.black);
|
502
486
|
|
503
487
|
for (int y = 0; y < 9; y++) {
|
504
488
|
|
505
|
-
g.drawLine(u
|
489
|
+
g.drawLine(square_size, square_size * (y + 1), square_size * 9, square_size * (y + 1));
|
506
|
-
|
490
|
+
|
507
|
-
}
|
491
|
+
}
|
508
|
-
|
509
|
-
|
510
|
-
|
492
|
+
|
493
|
+
|
494
|
+
|
511
|
-
//
|
495
|
+
// Dots
|
512
496
|
|
513
497
|
for (int x = 0; x < 2; x++) {
|
514
498
|
|
515
499
|
for (int y = 0; y < 2; y++) {
|
516
500
|
|
517
|
-
g.fillRect(u
|
501
|
+
g.fillRect(square_size * (3 + 4 * x) - (square_size / 16),
|
518
|
-
|
502
|
+
|
519
|
-
|
503
|
+
square_size * (3 + 4 * y) - (square_size / 16),
|
504
|
+
|
520
|
-
|
505
|
+
square_size / 8,
|
506
|
+
|
507
|
+
square_size / 8);
|
508
|
+
|
521
|
-
}
|
509
|
+
}
|
522
|
-
|
510
|
+
|
523
|
-
}
|
511
|
+
}
|
524
|
-
|
525
|
-
|
526
|
-
|
512
|
+
|
513
|
+
|
514
|
+
|
527
|
-
//
|
515
|
+
// Disk
|
528
516
|
|
529
517
|
Point p = new Point();
|
530
518
|
|
@@ -532,11 +520,11 @@
|
|
532
520
|
|
533
521
|
for (int y = 0; y < 8; y++) {
|
534
522
|
|
535
|
-
p.x = u
|
523
|
+
p.x = square_size * (x + 1) + square_size / 2;
|
536
|
-
|
524
|
+
|
537
|
-
p.y = u
|
525
|
+
p.y = square_size * (y + 1) + square_size / 2;
|
538
|
-
|
526
|
+
|
539
|
-
|
527
|
+
squares[x][y].paint(g, p, square_size);
|
540
528
|
|
541
529
|
}
|
542
530
|
|
@@ -552,17 +540,17 @@
|
|
552
540
|
|
553
541
|
private final String name;
|
554
542
|
|
555
|
-
private final
|
543
|
+
private final Disk disk;
|
556
544
|
|
557
545
|
private final int[][] reversible;
|
558
546
|
|
559
547
|
|
560
548
|
|
561
|
-
Player(String name,
|
549
|
+
Player(String name, Disk disk, int[][] reversible) {
|
562
550
|
|
563
551
|
this.name = name;
|
564
552
|
|
565
|
-
this.s
|
553
|
+
this.disk = disk;
|
566
554
|
|
567
555
|
this.reversible = reversible;
|
568
556
|
|
@@ -588,7 +576,7 @@
|
|
588
576
|
|
589
577
|
void putAndReverse(Board board, int x, int y) {
|
590
578
|
|
591
|
-
board.putAndReverse(x, y, s
|
579
|
+
board.putAndReverse(x, y, disk);
|
592
580
|
|
593
581
|
}
|
594
582
|
|
@@ -596,7 +584,7 @@
|
|
596
584
|
|
597
585
|
long count(Board board) {
|
598
586
|
|
599
|
-
return board.count(s
|
587
|
+
return board.count(disk);
|
600
588
|
|
601
589
|
}
|
602
590
|
|
@@ -626,13 +614,13 @@
|
|
626
614
|
|
627
615
|
public class Reversi extends JPanel {
|
628
616
|
|
629
|
-
private
|
617
|
+
private static final int SQUARE_SIZE = 80;
|
630
618
|
|
631
619
|
private final Board board = new Board();
|
632
620
|
|
633
|
-
private final Player player1 = new Player("黒",
|
621
|
+
private final Player player1 = new Player("黒", Disks.BLACK, board.eval_black);
|
634
|
-
|
622
|
+
|
635
|
-
private final Player player2 = new Player("白",
|
623
|
+
private final Player player2 = new Player("白", Disks.WHITE, board.eval_white);
|
636
624
|
|
637
625
|
private Player player = player1;
|
638
626
|
|
@@ -642,7 +630,15 @@
|
|
642
630
|
|
643
631
|
setPreferredSize(new Dimension(800, 800));
|
644
632
|
|
645
|
-
addMouseListener(new Mouse
|
633
|
+
addMouseListener(new MouseHandler());
|
634
|
+
|
635
|
+
}
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
void turnPlayer() {
|
640
|
+
|
641
|
+
player = player == player1 ? player2 : player1;
|
646
642
|
|
647
643
|
}
|
648
644
|
|
@@ -650,15 +646,15 @@
|
|
650
646
|
|
651
647
|
public void paintComponent(Graphics g) {
|
652
648
|
|
653
|
-
board.paint(g, U
|
649
|
+
board.paint(g, SQUARE_SIZE);
|
654
|
-
|
650
|
+
|
655
|
-
}
|
651
|
+
}
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
652
|
+
|
660
|
-
|
653
|
+
|
654
|
+
|
661
|
-
|
655
|
+
void showMessage(String message, String title) {
|
656
|
+
|
657
|
+
JOptionPane.showMessageDialog(this, message, title, JOptionPane.INFORMATION_MESSAGE);
|
662
658
|
|
663
659
|
}
|
664
660
|
|
@@ -666,25 +662,23 @@
|
|
666
662
|
|
667
663
|
void showMessage(String message) {
|
668
664
|
|
669
|
-
|
665
|
+
showMessage(message, "情報");
|
670
|
-
|
666
|
+
|
671
|
-
}
|
667
|
+
}
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
668
|
+
|
676
|
-
|
669
|
+
|
670
|
+
|
677
|
-
void endGame() {
|
671
|
+
void endGameAndExit() {
|
678
672
|
|
679
673
|
long num_player1 = player1.count(board);
|
680
674
|
|
681
675
|
long num_player2 = player2.count(board);
|
682
676
|
|
683
|
-
String message = "["
|
677
|
+
String message = "["
|
684
|
-
|
678
|
+
|
685
|
-
|
679
|
+
+ player1 + ":" + num_player1 + ","
|
686
|
-
|
680
|
+
|
687
|
-
|
681
|
+
+ player2 + ":" + num_player2 + "]で";
|
688
682
|
|
689
683
|
if (num_player1 > num_player2) {
|
690
684
|
|
@@ -700,7 +694,7 @@
|
|
700
694
|
|
701
695
|
}
|
702
696
|
|
703
|
-
|
697
|
+
showMessage(message, "ゲーム終了");
|
704
698
|
|
705
699
|
|
706
700
|
|
@@ -710,9 +704,7 @@
|
|
710
704
|
|
711
705
|
|
712
706
|
|
713
|
-
// クリックされた時の処理用クラス
|
714
|
-
|
715
|
-
class Mouse
|
707
|
+
class MouseHandler extends MouseAdapter {
|
716
708
|
|
717
709
|
public void mouseClicked(MouseEvent me) {
|
718
710
|
|
@@ -722,71 +714,75 @@
|
|
722
714
|
|
723
715
|
System.out.println("(" + point.x + "," + point.y + ")");
|
724
716
|
|
725
|
-
int x = point.x / U
|
717
|
+
int x = point.x / SQUARE_SIZE - 1;
|
726
|
-
|
718
|
+
|
727
|
-
int y = point.y / U
|
719
|
+
int y = point.y / SQUARE_SIZE - 1;
|
728
720
|
|
729
721
|
if (!(0 <= x && x < 8 && 0 <= y && y < 8)) return;
|
730
722
|
|
731
723
|
System.out.println("[" + x + "]" + "[" + y + "]");
|
732
724
|
|
733
|
-
board.evaluateBoard();
|
734
|
-
|
735
725
|
int btn = me.getButton();
|
736
726
|
|
737
|
-
if (
|
727
|
+
if (player == player1 && btn == MouseEvent.BUTTON1 ||
|
738
|
-
|
728
|
+
|
739
|
-
|
729
|
+
player == player2 && btn == MouseEvent.BUTTON3) {
|
730
|
+
|
740
|
-
|
731
|
+
put(x, y);
|
732
|
+
|
733
|
+
}
|
734
|
+
|
735
|
+
}
|
736
|
+
|
737
|
+
}
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
void put(int x, int y) {
|
742
|
+
|
743
|
+
board.evaluate();
|
744
|
+
|
745
|
+
if (!player.putable(board, x, y)) {
|
746
|
+
|
747
|
+
System.out.println("そこに石を置けません");
|
748
|
+
|
741
|
-
|
749
|
+
return;
|
742
|
-
|
750
|
+
|
743
|
-
|
751
|
+
}
|
744
|
-
|
752
|
+
|
745
|
-
|
753
|
+
player.putAndReverse(board, x, y);
|
746
|
-
|
747
|
-
|
754
|
+
|
748
|
-
|
749
|
-
|
755
|
+
repaint();
|
756
|
+
|
750
|
-
|
757
|
+
board.printBoard();
|
758
|
+
|
759
|
+
board.evaluate();
|
760
|
+
|
761
|
+
board.printEvaluation();
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
if (player1.pass() && player2.pass()) {
|
766
|
+
|
767
|
+
endGameAndExit();
|
768
|
+
|
751
|
-
|
769
|
+
}
|
752
|
-
|
753
|
-
|
770
|
+
|
754
|
-
|
755
|
-
repaint();
|
756
|
-
|
757
|
-
board.printBoard();
|
758
|
-
|
759
|
-
board.evaluateBoard();
|
760
|
-
|
761
|
-
board.printEval();
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
if (player1.pass() && player2.pass()) {
|
766
|
-
|
767
|
-
|
771
|
+
turnPlayer();
|
768
|
-
|
772
|
+
|
769
|
-
|
773
|
+
if (player.pass()) {
|
774
|
+
|
775
|
+
showMessage(player + "はパスです");
|
770
776
|
|
771
777
|
turnPlayer();
|
772
778
|
|
773
|
-
if (player.pass()) {
|
774
|
-
|
775
|
-
showMessage(player + "はパスです");
|
776
|
-
|
777
|
-
turnPlayer();
|
778
|
-
|
779
|
-
|
779
|
+
}
|
780
|
-
|
780
|
+
|
781
|
-
|
781
|
+
showMessage(player + "の番です");
|
782
|
-
|
782
|
+
|
783
|
-
|
783
|
+
}
|
784
|
-
|
785
|
-
|
784
|
+
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
785
|
+
|
790
786
|
|
791
787
|
public static void main(String[] args) {
|
792
788
|
|
5
変数 i, j を x, y または y, x に変更
test
CHANGED
@@ -390,13 +390,13 @@
|
|
390
390
|
|
391
391
|
void evaluateBoard() {
|
392
392
|
|
393
|
-
for (int
|
393
|
+
for (int x = 0; x < 8; x++) {
|
394
|
-
|
394
|
+
|
395
|
-
for (int
|
395
|
+
for (int y = 0; y < 8; y++) {
|
396
|
-
|
396
|
+
|
397
|
-
eval_black[
|
397
|
+
eval_black[x][y] = countReverseStone(x, y, Stones.BLACK);
|
398
|
-
|
398
|
+
|
399
|
-
eval_white[
|
399
|
+
eval_white[x][y] = countReverseStone(x, y, Stones.WHITE);
|
400
400
|
|
401
401
|
}
|
402
402
|
|
@@ -432,11 +432,11 @@
|
|
432
432
|
|
433
433
|
System.out.println("Black(" + Stones.BLACK + "):");
|
434
434
|
|
435
|
-
for (int
|
435
|
+
for (int y = 0; y < 8; y++) {
|
436
|
-
|
436
|
+
|
437
|
-
for (int
|
437
|
+
for (int x = 0; x < 8; x++) {
|
438
|
-
|
438
|
+
|
439
|
-
System.out.printf("%2d ", eval_black[
|
439
|
+
System.out.printf("%2d ", eval_black[x][y]);
|
440
440
|
|
441
441
|
}
|
442
442
|
|
@@ -446,11 +446,11 @@
|
|
446
446
|
|
447
447
|
System.out.println("White(" + Stones.WHITE + "):");
|
448
448
|
|
449
|
-
for (int
|
449
|
+
for (int y = 0; y < 8; y++) {
|
450
|
-
|
450
|
+
|
451
|
-
for (int
|
451
|
+
for (int x = 0; x < 8; x++) {
|
452
|
-
|
452
|
+
|
453
|
-
System.out.printf("%2d ", eval_white[
|
453
|
+
System.out.printf("%2d ", eval_white[x][y]);
|
454
454
|
|
455
455
|
}
|
456
456
|
|
@@ -488,9 +488,9 @@
|
|
488
488
|
|
489
489
|
g.setColor(Color.black);
|
490
490
|
|
491
|
-
for (int
|
491
|
+
for (int x = 0; x < 9; x++) {
|
492
|
-
|
492
|
+
|
493
|
-
g.drawLine(unit_size * (
|
493
|
+
g.drawLine(unit_size * (x + 1), unit_size, unit_size * (x + 1), unit_size * 9);
|
494
494
|
|
495
495
|
}
|
496
496
|
|
@@ -500,9 +500,9 @@
|
|
500
500
|
|
501
501
|
g.setColor(Color.black);
|
502
502
|
|
503
|
-
for (int
|
503
|
+
for (int y = 0; y < 9; y++) {
|
504
|
-
|
504
|
+
|
505
|
-
g.drawLine(unit_size, unit_size * (
|
505
|
+
g.drawLine(unit_size, unit_size * (y + 1), unit_size * 9, unit_size * (y + 1));
|
506
506
|
|
507
507
|
}
|
508
508
|
|
@@ -510,11 +510,11 @@
|
|
510
510
|
|
511
511
|
// 目印
|
512
512
|
|
513
|
-
for (int
|
513
|
+
for (int x = 0; x < 2; x++) {
|
514
|
-
|
514
|
+
|
515
|
-
for (int
|
515
|
+
for (int y = 0; y < 2; y++) {
|
516
|
-
|
516
|
+
|
517
|
-
g.fillRect(unit_size * (3 + 4 *
|
517
|
+
g.fillRect(unit_size * (3 + 4 * x) - (unit_size / 16), unit_size * (3 + 4 * y) - (unit_size / 16),
|
518
518
|
|
519
519
|
(unit_size / 8), (unit_size / 8));
|
520
520
|
|
4
大文字開始メソッド名を小文字メソッド名に変更
test
CHANGED
@@ -578,17 +578,17 @@
|
|
578
578
|
|
579
579
|
|
580
580
|
|
581
|
-
|
581
|
+
boolean putable(Board board, int x, int y) {
|
582
582
|
|
583
583
|
return reversible[x][y] >= 1;
|
584
584
|
|
585
|
-
|
585
|
+
}
|
586
586
|
|
587
587
|
|
588
588
|
|
589
589
|
void putAndReverse(Board board, int x, int y) {
|
590
590
|
|
591
|
-
|
591
|
+
board.putAndReverse(x, y, stone);
|
592
592
|
|
593
593
|
}
|
594
594
|
|
@@ -664,9 +664,9 @@
|
|
664
664
|
|
665
665
|
|
666
666
|
|
667
|
-
void Message
|
667
|
+
void showMessage(String message) {
|
668
|
-
|
668
|
+
|
669
|
-
JOptionPane.showMessageDialog(this, s
|
669
|
+
JOptionPane.showMessageDialog(this, message, "情報", JOptionPane.INFORMATION_MESSAGE);
|
670
670
|
|
671
671
|
}
|
672
672
|
|
@@ -674,7 +674,7 @@
|
|
674
674
|
|
675
675
|
// 黒石と白石の数を比較し終了
|
676
676
|
|
677
|
-
void
|
677
|
+
void endGame() {
|
678
678
|
|
679
679
|
long num_player1 = player1.count(board);
|
680
680
|
|
@@ -738,7 +738,7 @@
|
|
738
738
|
|
739
739
|
player == player2 && btn == MouseEvent.BUTTON3)) {
|
740
740
|
|
741
|
-
|
741
|
+
return;
|
742
742
|
|
743
743
|
}
|
744
744
|
|
@@ -764,7 +764,7 @@
|
|
764
764
|
|
765
765
|
if (player1.pass() && player2.pass()) {
|
766
766
|
|
767
|
-
|
767
|
+
endGame();
|
768
768
|
|
769
769
|
}
|
770
770
|
|
@@ -772,13 +772,13 @@
|
|
772
772
|
|
773
773
|
if (player.pass()) {
|
774
774
|
|
775
|
-
Message
|
775
|
+
showMessage(player + "はパスです");
|
776
776
|
|
777
777
|
turnPlayer();
|
778
778
|
|
779
779
|
}
|
780
780
|
|
781
|
-
Message
|
781
|
+
showMessage(player + "の番です");
|
782
782
|
|
783
783
|
}
|
784
784
|
|
3
player.putを処理分轄
test
CHANGED
@@ -578,240 +578,234 @@
|
|
578
578
|
|
579
579
|
|
580
580
|
|
581
|
-
|
581
|
+
boolean putable(Board board, int x, int y) {
|
582
|
-
|
582
|
+
|
583
|
-
|
583
|
+
return reversible[x][y] >= 1;
|
584
|
+
|
584
|
-
|
585
|
+
}
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
void putAndReverse(Board board, int x, int y) {
|
590
|
+
|
585
|
-
|
591
|
+
board.putAndReverse(x, y, stone);
|
592
|
+
|
586
|
-
|
593
|
+
}
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
long count(Board board) {
|
598
|
+
|
599
|
+
return board.count(stone);
|
600
|
+
|
601
|
+
}
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
boolean pass() {
|
606
|
+
|
607
|
+
for (int[] row: reversible) {
|
608
|
+
|
609
|
+
for (int n: row) {
|
610
|
+
|
611
|
+
if (n >= 1)
|
612
|
+
|
613
|
+
return false;
|
614
|
+
|
615
|
+
}
|
616
|
+
|
617
|
+
}
|
618
|
+
|
587
|
-
|
619
|
+
return true;
|
620
|
+
|
621
|
+
}
|
622
|
+
|
623
|
+
}
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
public class Reversi extends JPanel {
|
628
|
+
|
629
|
+
private final static int UNIT_SIZE = 80;
|
630
|
+
|
631
|
+
private final Board board = new Board();
|
632
|
+
|
633
|
+
private final Player player1 = new Player("黒", Stones.BLACK, board.eval_black);
|
634
|
+
|
635
|
+
private final Player player2 = new Player("白", Stones.WHITE, board.eval_white);
|
636
|
+
|
637
|
+
private Player player = player1;
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
public Reversi() {
|
642
|
+
|
643
|
+
setPreferredSize(new Dimension(800, 800));
|
644
|
+
|
645
|
+
addMouseListener(new MouseProc());
|
646
|
+
|
647
|
+
}
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
public void paintComponent(Graphics g) {
|
652
|
+
|
653
|
+
board.paint(g, UNIT_SIZE);
|
654
|
+
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
void turnPlayer() {
|
660
|
+
|
661
|
+
player = player == player1 ? player2 : player1;
|
662
|
+
|
663
|
+
}
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
void MessageDialog(String str) {
|
668
|
+
|
669
|
+
JOptionPane.showMessageDialog(this, str, "情報", JOptionPane.INFORMATION_MESSAGE);
|
670
|
+
|
671
|
+
}
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
// 黒石と白石の数を比較し終了
|
676
|
+
|
677
|
+
void EndMessageDialog() {
|
678
|
+
|
679
|
+
long num_player1 = player1.count(board);
|
680
|
+
|
681
|
+
long num_player2 = player2.count(board);
|
682
|
+
|
683
|
+
String message = "[";
|
684
|
+
|
685
|
+
message += player1 + ":" + num_player1 + ",";
|
686
|
+
|
687
|
+
message += player2 + ":" + num_player2 + "]で";
|
688
|
+
|
689
|
+
if (num_player1 > num_player2) {
|
690
|
+
|
691
|
+
message += player1 + "の勝ち";
|
692
|
+
|
693
|
+
} else if (num_player1 <= num_player2) {
|
694
|
+
|
695
|
+
message += player2 + "の勝ち";
|
588
696
|
|
589
697
|
} else {
|
590
698
|
|
591
|
-
|
592
|
-
|
593
|
-
}
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
return
|
699
|
+
message += "引き分け";
|
700
|
+
|
701
|
+
}
|
702
|
+
|
703
|
+
JOptionPane.showMessageDialog(this, message, "ゲーム終了", JOptionPane.INFORMATION_MESSAGE);
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
System.exit(0);
|
708
|
+
|
709
|
+
}
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
// クリックされた時の処理用クラス
|
714
|
+
|
715
|
+
class MouseProc extends MouseAdapter {
|
716
|
+
|
717
|
+
public void mouseClicked(MouseEvent me) {
|
718
|
+
|
719
|
+
board.printBoard();
|
720
|
+
|
721
|
+
Point point = me.getPoint();
|
722
|
+
|
723
|
+
System.out.println("(" + point.x + "," + point.y + ")");
|
724
|
+
|
725
|
+
int x = point.x / UNIT_SIZE - 1;
|
726
|
+
|
727
|
+
int y = point.y / UNIT_SIZE - 1;
|
728
|
+
|
729
|
+
if (!(0 <= x && x < 8 && 0 <= y && y < 8)) return;
|
730
|
+
|
731
|
+
System.out.println("[" + x + "]" + "[" + y + "]");
|
732
|
+
|
733
|
+
board.evaluateBoard();
|
734
|
+
|
735
|
+
int btn = me.getButton();
|
736
|
+
|
737
|
+
if (!(player == player1 && btn == MouseEvent.BUTTON1 ||
|
738
|
+
|
739
|
+
player == player2 && btn == MouseEvent.BUTTON3)) {
|
740
|
+
|
741
|
+
return;
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
if (!player.putable(board, x, y)) {
|
746
|
+
|
747
|
+
System.out.println("そこに石を置けません");
|
748
|
+
|
749
|
+
return;
|
750
|
+
|
751
|
+
}
|
752
|
+
|
753
|
+
player.putAndReverse(board, x, y);
|
754
|
+
|
755
|
+
repaint();
|
756
|
+
|
757
|
+
board.printBoard();
|
758
|
+
|
759
|
+
board.evaluateBoard();
|
760
|
+
|
761
|
+
board.printEval();
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
if (player1.pass() && player2.pass()) {
|
766
|
+
|
767
|
+
EndMessageDialog();
|
768
|
+
|
769
|
+
}
|
770
|
+
|
771
|
+
turnPlayer();
|
772
|
+
|
773
|
+
if (player.pass()) {
|
774
|
+
|
775
|
+
MessageDialog(player + "はパスです");
|
776
|
+
|
777
|
+
turnPlayer();
|
778
|
+
|
779
|
+
}
|
780
|
+
|
781
|
+
MessageDialog(player + "の番です");
|
782
|
+
|
783
|
+
}
|
784
|
+
|
785
|
+
}
|
786
|
+
|
787
|
+
|
788
|
+
|
789
|
+
// 起動
|
790
|
+
|
791
|
+
public static void main(String[] args) {
|
792
|
+
|
793
|
+
JFrame f = new JFrame();
|
794
|
+
|
795
|
+
f.getContentPane().setLayout(new FlowLayout());
|
796
|
+
|
797
|
+
f.getContentPane().add(new Reversi());
|
798
|
+
|
799
|
+
f.pack();
|
800
|
+
|
801
|
+
f.setResizable(false);
|
802
|
+
|
803
|
+
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
804
|
+
|
805
|
+
f.setVisible(true);
|
622
806
|
|
623
807
|
}
|
624
808
|
|
625
809
|
}
|
626
810
|
|
627
|
-
|
628
|
-
|
629
|
-
public class Reversi extends JPanel {
|
630
|
-
|
631
|
-
private final static int UNIT_SIZE = 80;
|
632
|
-
|
633
|
-
private final Board board = new Board();
|
634
|
-
|
635
|
-
private final Player player1 = new Player("黒", Stones.BLACK, board.eval_black);
|
636
|
-
|
637
|
-
private final Player player2 = new Player("白", Stones.WHITE, board.eval_white);
|
638
|
-
|
639
|
-
private Player player = player1;
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
public Reversi() {
|
644
|
-
|
645
|
-
setPreferredSize(new Dimension(800, 800));
|
646
|
-
|
647
|
-
addMouseListener(new MouseProc());
|
648
|
-
|
649
|
-
}
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
public void paintComponent(Graphics g) {
|
654
|
-
|
655
|
-
board.paint(g, UNIT_SIZE);
|
656
|
-
|
657
|
-
}
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
void turnPlayer() {
|
662
|
-
|
663
|
-
player = player == player1 ? player2 : player1;
|
664
|
-
|
665
|
-
}
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
void MessageDialog(String str) {
|
670
|
-
|
671
|
-
JOptionPane.showMessageDialog(this, str, "情報", JOptionPane.INFORMATION_MESSAGE);
|
672
|
-
|
673
|
-
}
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
// 黒石と白石の数を比較し終了
|
678
|
-
|
679
|
-
void EndMessageDialog() {
|
680
|
-
|
681
|
-
long num_player1 = player1.count(board);
|
682
|
-
|
683
|
-
long num_player2 = player2.count(board);
|
684
|
-
|
685
|
-
String message = "[";
|
686
|
-
|
687
|
-
message += player1 + ":" + num_player1 + ",";
|
688
|
-
|
689
|
-
message += player2 + ":" + num_player2 + "]で";
|
690
|
-
|
691
|
-
if (num_player1 > num_player2) {
|
692
|
-
|
693
|
-
message += player1 + "の勝ち";
|
694
|
-
|
695
|
-
} else if (num_player1 <= num_player2) {
|
696
|
-
|
697
|
-
message += player2 + "の勝ち";
|
698
|
-
|
699
|
-
} else {
|
700
|
-
|
701
|
-
message += "引き分け";
|
702
|
-
|
703
|
-
}
|
704
|
-
|
705
|
-
JOptionPane.showMessageDialog(this, message, "ゲーム終了", JOptionPane.INFORMATION_MESSAGE);
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
System.exit(0);
|
710
|
-
|
711
|
-
}
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
// クリックされた時の処理用クラス
|
716
|
-
|
717
|
-
class MouseProc extends MouseAdapter {
|
718
|
-
|
719
|
-
public void mouseClicked(MouseEvent me) {
|
720
|
-
|
721
|
-
board.printBoard();
|
722
|
-
|
723
|
-
Point point = me.getPoint();
|
724
|
-
|
725
|
-
System.out.println("(" + point.x + "," + point.y + ")");
|
726
|
-
|
727
|
-
int x = point.x / UNIT_SIZE - 1;
|
728
|
-
|
729
|
-
int y = point.y / UNIT_SIZE - 1;
|
730
|
-
|
731
|
-
if (!(0 <= x && x < 8 && 0 <= y && y < 8)) return;
|
732
|
-
|
733
|
-
System.out.println("[" + x + "]" + "[" + y + "]");
|
734
|
-
|
735
|
-
board.evaluateBoard();
|
736
|
-
|
737
|
-
int btn = me.getButton();
|
738
|
-
|
739
|
-
if (player == player1) {
|
740
|
-
|
741
|
-
if (btn != MouseEvent.BUTTON1)
|
742
|
-
|
743
|
-
return;
|
744
|
-
|
745
|
-
} else {
|
746
|
-
|
747
|
-
if (btn != MouseEvent.BUTTON3)
|
748
|
-
|
749
|
-
return;
|
750
|
-
|
751
|
-
}
|
752
|
-
|
753
|
-
if (!player.put(board, x, y)) {
|
754
|
-
|
755
|
-
System.out.println("そこに石を置けません");
|
756
|
-
|
757
|
-
return;
|
758
|
-
|
759
|
-
}
|
760
|
-
|
761
|
-
repaint();
|
762
|
-
|
763
|
-
board.printBoard();
|
764
|
-
|
765
|
-
board.evaluateBoard();
|
766
|
-
|
767
|
-
board.printEval();
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
if (player1.pass() && player2.pass()) {
|
772
|
-
|
773
|
-
EndMessageDialog();
|
774
|
-
|
775
|
-
}
|
776
|
-
|
777
|
-
turnPlayer();
|
778
|
-
|
779
|
-
if (player.pass()) {
|
780
|
-
|
781
|
-
MessageDialog(player + "はパスです");
|
782
|
-
|
783
|
-
turnPlayer();
|
784
|
-
|
785
|
-
}
|
786
|
-
|
787
|
-
MessageDialog(player + "の番です");
|
788
|
-
|
789
|
-
}
|
790
|
-
|
791
|
-
}
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
// 起動
|
796
|
-
|
797
|
-
public static void main(String[] args) {
|
798
|
-
|
799
|
-
JFrame f = new JFrame();
|
800
|
-
|
801
|
-
f.getContentPane().setLayout(new FlowLayout());
|
802
|
-
|
803
|
-
f.getContentPane().add(new Reversi());
|
804
|
-
|
805
|
-
f.pack();
|
806
|
-
|
807
|
-
f.setResizable(false);
|
808
|
-
|
809
|
-
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
810
|
-
|
811
|
-
f.setVisible(true);
|
812
|
-
|
813
|
-
}
|
814
|
-
|
815
|
-
}
|
816
|
-
|
817
811
|
```
|
2
盤面表示文字変更
test
CHANGED
@@ -70,36 +70,36 @@
|
|
70
70
|
|
71
71
|
public String toString() {
|
72
72
|
|
73
|
+
return "×";
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
};
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
WHITE = new Stone() {
|
82
|
+
|
83
|
+
public void paint(Graphics g, Point p, int size) {
|
84
|
+
|
85
|
+
int r = (size / 2) * 4 / 5;
|
86
|
+
|
87
|
+
g.setColor(Color.white);
|
88
|
+
|
89
|
+
g.fillOval(p.x - r, p.y - r, r * 2, r * 2);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public String toString() {
|
96
|
+
|
73
97
|
return "●";
|
74
98
|
|
75
99
|
}
|
76
100
|
|
77
101
|
};
|
78
102
|
|
79
|
-
|
80
|
-
|
81
|
-
WHITE = new Stone() {
|
82
|
-
|
83
|
-
public void paint(Graphics g, Point p, int size) {
|
84
|
-
|
85
|
-
int r = (size / 2) * 4 / 5;
|
86
|
-
|
87
|
-
g.setColor(Color.white);
|
88
|
-
|
89
|
-
g.fillOval(p.x - r, p.y - r, r * 2, r * 2);
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
public String toString() {
|
96
|
-
|
97
|
-
return "○";
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
};
|
102
|
-
|
103
103
|
}
|
104
104
|
|
105
105
|
|
@@ -430,7 +430,7 @@
|
|
430
430
|
|
431
431
|
void printEval() {
|
432
432
|
|
433
|
-
System.out.println("Black(
|
433
|
+
System.out.println("Black(" + Stones.BLACK + "):");
|
434
434
|
|
435
435
|
for (int i = 0; i < 8; i++) {
|
436
436
|
|
@@ -444,7 +444,7 @@
|
|
444
444
|
|
445
445
|
}
|
446
446
|
|
447
|
-
System.out.println("White(
|
447
|
+
System.out.println("White(" + Stones.WHITE + "):");
|
448
448
|
|
449
449
|
for (int i = 0; i < 8; i++) {
|
450
450
|
|
@@ -632,8 +632,6 @@
|
|
632
632
|
|
633
633
|
private final Board board = new Board();
|
634
634
|
|
635
|
-
|
636
|
-
|
637
635
|
private final Player player1 = new Player("黒", Stones.BLACK, board.eval_black);
|
638
636
|
|
639
637
|
private final Player player2 = new Player("白", Stones.WHITE, board.eval_white);
|
@@ -800,8 +798,6 @@
|
|
800
798
|
|
801
799
|
JFrame f = new JFrame();
|
802
800
|
|
803
|
-
|
804
|
-
|
805
801
|
f.getContentPane().setLayout(new FlowLayout());
|
806
802
|
|
807
803
|
f.getContentPane().add(new Reversi());
|
1
Reversi2 を Reversi に修正
test
CHANGED
@@ -626,7 +626,7 @@
|
|
626
626
|
|
627
627
|
|
628
628
|
|
629
|
-
public class Reversi
|
629
|
+
public class Reversi extends JPanel {
|
630
630
|
|
631
631
|
private final static int UNIT_SIZE = 80;
|
632
632
|
|
@@ -642,7 +642,7 @@
|
|
642
642
|
|
643
643
|
|
644
644
|
|
645
|
-
public Reversi
|
645
|
+
public Reversi() {
|
646
646
|
|
647
647
|
setPreferredSize(new Dimension(800, 800));
|
648
648
|
|
@@ -804,7 +804,7 @@
|
|
804
804
|
|
805
805
|
f.getContentPane().setLayout(new FlowLayout());
|
806
806
|
|
807
|
-
f.getContentPane().add(new Reversi
|
807
|
+
f.getContentPane().add(new Reversi());
|
808
808
|
|
809
809
|
f.pack();
|
810
810
|
|