1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
|
package jrummikub.control;
import static jrummikub.model.StoneColor.*;
import static org.junit.Assert.*;
import java.awt.Color;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import jrummikub.control.turn.TurnMode;
import jrummikub.model.GameSettings;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
import jrummikub.model.MockRoundState;
import jrummikub.model.MockTable;
import jrummikub.model.PlayerSettings;
import jrummikub.model.Position;
import jrummikub.model.RoundState;
import jrummikub.model.Score;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.model.Table;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for {@link RoundControl}
*/
public class RoundControlTest {
private MockView view;
private MockRoundState testRoundState;
private RoundControl testRound;
private MockTable testTable;
private GameSettings gameSettings;
private IRoundState roundState;
private RoundControl roundControl;
private boolean roundEnded;
private Score roundScore;
protected boolean roundRestarted;
/**
* For each test create a round control initialized by a mock model and view
*/
@Before
public void setup() {
view = new MockView();
testRoundState = new MockRoundState();
testRound = new RoundControl(testRoundState, view);
Stone stone = testRoundState.getGameHeap().drawStone();
testRoundState.table.drop(new StoneSet(stone), new Position(5, 0));
testTable = new MockTable();
testTable.sets.add(testRoundState.table.sets.get(0));
testRoundState.table.clonedTable = testTable;
roundEnded = false;
gameSettings = new GameSettings();
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW));
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
roundState = new RoundState(gameSettings);
roundControl = new RoundControl(roundState, view);
}
private void checkCorrectlyDealt() {
GameSettings settings = testRoundState.getGameSettings();
int totalStones = settings.getHighestValue() * settings.getStoneSetNumber()
* settings.getStoneColors().size() + settings.getJokerNumber();
assertEquals(
totalStones - testRoundState.getPlayerCount()
* settings.getNumberOfStonesDealt()
- testRoundState.table.getSize(), testRoundState.getGameHeap()
.getSize());
for (int i = 0; i < testRoundState.getPlayerCount(); i++) {
assertEquals(settings.getNumberOfStonesDealt(), testRoundState
.getNthNextPlayer(i).getHand().getSize());
}
}
private void checkTurnStartSetUp() {
assertNotNull(view.currentPlayerName);
// TODO Check player list in view
assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType);
assertFalse(view.startTurnEvent.listeners.isEmpty());
checkTableDisplay();
}
private void checkTableDisplay() {
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
.iterator();
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testRoundState.table
.clone().sets.iterator();
while (stoneSetsView.hasNext()) {
assertTrue(stoneSetsModel.hasNext());
assertSame(stoneSetsView.next(), stoneSetsModel.next());
}
assertFalse(stoneSetsModel.hasNext());
}
private void resetTurnStart() {
view.currentPlayerName = null;
// TODO reset player list
view.bottomPanelType = null;
}
/**
* Check correctly dealt with more than 14 stones/ different than default
* stones
*/
@Test
public void checkCorrectlyDealtMoreStones() {
testRoundState.getGameSettings().setNumberOfStonesDealt(15);
testRound.deal();
checkCorrectlyDealt();
}
// laidOut test cases
/** Threshold=30 */
@Test
public void laidOutValidTooFew() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
assertFalse(roundState.getActivePlayer().getLaidOut());
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 6, hand.getSize());
}
/** */
@Test
public void laidOutValidUnchanged() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
IHand hand = roundState.getActivePlayer().getHand();
assertFalse(roundState.getActivePlayer().getLaidOut());
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 1, hand.getSize());
}
/** Threshold=30 */
@Test
public void laidOutInvalidEnough() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
Stone blueTen = new Stone(10, BLUE);
Stone redTen = new Stone(10, RED);
Stone blueEleven = new Stone(11, BLUE);
assertFalse(roundState.getActivePlayer().getLaidOut());
hand.drop(blueTen, new Position(0, 0));
hand.drop(redTen, new Position(0, 0));
hand.drop(blueEleven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueTen, false);
view.handPanel.stoneClickEvent.emit(redTen, true);
view.handPanel.stoneClickEvent.emit(blueEleven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 9, hand.getSize());
}
/** Threshold=30 */
@Test
public void laidOutTooFewChangedTable() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE);
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
hand.drop(redSeven, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0));
hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertEquals(2, roundState.getTable().getSize());
view.startTurnEvent.emit();
Stone redEight = new Stone(8, RED);
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
hand = roundState.getActivePlayer().getHand();
hand.drop(redEight, new Position(0, 0));
hand.drop(redNine, new Position(0, 0));
hand.drop(redTen, new Position(0, 0));
view.tablePanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(redEight, true);
view.handPanel.stoneClickEvent.emit(redNine, true);
view.handPanel.stoneClickEvent.emit(redTen, true);
assertFalse(roundState.getActivePlayer().getLaidOut());
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 6, hand.getSize());
}
/** Threshold=30 */
@Test
public void laidOutEnoughChangedTable() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE);
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
hand.drop(redSeven, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0));
hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertEquals(2, roundState.getTable().getSize());
view.startTurnEvent.emit();
Stone redEight = new Stone(8, RED);
Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
Stone redEleven = new Stone(11, RED);
hand = roundState.getActivePlayer().getHand();
hand.drop(redEight, new Position(0, 0));
hand.drop(redNine, new Position(0, 0));
hand.drop(redTen, new Position(0, 0));
hand.drop(redEleven, new Position(0, 0));
view.tablePanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(redEight, true);
view.handPanel.stoneClickEvent.emit(redNine, true);
view.handPanel.stoneClickEvent.emit(redTen, true);
view.handPanel.stoneClickEvent.emit(redEleven, true);
assertFalse(roundState.getActivePlayer().getLaidOut());
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 7, hand.getSize());
}
/** */
@Test
public void laidOutJustChangedTable() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone blueFour = new Stone(4, BLUE);
Stone blackFour = new Stone(4, BLACK);
Stone redFour = new Stone(4, RED);
Stone orangeFour = new Stone(4, ORANGE);
Stone blueFive = new Stone(5, BLUE);
Stone blueSix = new Stone(6, BLUE);
Stone blueSeven = new Stone(7, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueFive, new Position(0, 0));
hand.drop(blueSix, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0));
hand.drop(redFour, new Position(0, 0));
hand.drop(blueFour, new Position(0, 0));
hand.drop(blackFour, new Position(0, 0));
hand.drop(orangeFour, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redFour, false);
view.handPanel.stoneClickEvent.emit(blueFour, true);
view.handPanel.stoneClickEvent.emit(blackFour, true);
view.handPanel.stoneClickEvent.emit(orangeFour, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueFive, false);
view.handPanel.stoneClickEvent.emit(blueSix, true);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertEquals(2, roundState.getTable().getSize());
view.startTurnEvent.emit();
hand = roundState.getActivePlayer().getHand();
view.tablePanel.stoneClickEvent.emit(blueFour, false);
view.tablePanel.stoneClickEvent.emit(blueFive, true);
view.tablePanel.stoneClickEvent.emit(blueSix, true);
view.tablePanel.stoneClickEvent.emit(blueSeven, true);
assertFalse(roundState.getActivePlayer().getLaidOut());
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 3, hand.getSize());
}
/** Threshold=30 */
@Test
public void laidOutValid() {
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
view.startTurnEvent.emit();
// Fake Turn to put stones on the table
Stone blueSeven = new Stone(7, BLUE);
Stone blackSeven = new Stone(7, BLACK);
Stone redSeven = new Stone(7, RED);
Stone orangeSeven = new Stone(7, ORANGE);
Stone blueOne = new Stone(1, BLUE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
IHand hand = roundState.getActivePlayer().getHand();
hand.drop(blueOne, new Position(0, 0));
hand.drop(blueTwo, new Position(0, 0));
hand.drop(blueThree, new Position(0, 0));
hand.drop(redSeven, new Position(0, 0));
hand.drop(blueSeven, new Position(0, 0));
hand.drop(blackSeven, new Position(0, 0));
hand.drop(orangeSeven, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redSeven, false);
view.handPanel.stoneClickEvent.emit(blueSeven, true);
view.handPanel.stoneClickEvent.emit(blackSeven, true);
view.handPanel.stoneClickEvent.emit(orangeSeven, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.handPanel.stoneClickEvent.emit(blueOne, false);
view.handPanel.stoneClickEvent.emit(blueTwo, true);
view.handPanel.stoneClickEvent.emit(blueThree, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
.getLaidOut());
assertEquals(2, roundState.getTable().getSize());
assertEquals(14, hand.getSize());
}
/** */
@Test
public void testDealStones() {
testRound.deal();
checkCorrectlyDealt();
for (int i = 0; i < 14; i++) {
testRound.dealStones(2);
}
assertEquals(2 * 14 + 14, testRoundState.getActivePlayer().getHand()
.getSize());
}
/** */
@Test
public void testDeal() {
testRound.deal();
checkCorrectlyDealt();
}
/** */
@Test
public void testStartRound() {
testRound.startRound();
checkCorrectlyDealt();
checkTurnStartSetUp();
}
/** */
@Test
public void testTableDisplay() {
testRound.startRound();
checkCorrectlyDealt();
view.startTurnEvent.emit();
checkTableDisplay();
view.getPlayerPanel().endTurnEvent.emit();
}
/** */
@Test
public void testTableValidHandChanged() {
testRoundState.players.get(0).setLaidOut(true);
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
MockTable oldTable = testRoundState.table;
testTable.valid = true;
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand;
hand.pickUp(hand.iterator().next().getFirst());
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
assertSame(testTable, testRoundState.setTable);
assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
/** */
@Test
public void testTableInvalidHandChanged() {
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
MockTable oldTable = testRoundState.table;
testTable.valid = false;
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand;
Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone);
testTable.drop(new StoneSet(stone), new Position(0, 0));
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
assertNull(testRoundState.setTable);
assertEquals(1, testRoundState.activePlayer);
assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize());
checkTurnStartSetUp();
}
/** */
@Test
public void testTableValidHandUnchanged() {
testRoundState.players.get(0).setLaidOut(true);
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
MockTable oldTable = testRoundState.table;
testTable.valid = true;
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
assertSame(testTable, testRoundState.setTable);
assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
/** */
@Test
public void testTableInvalidHandUnchanged() {
testRoundState.players.get(1).setLaidOut(true);
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
MockTable oldTable = testRoundState.table;
testTable.valid = false;
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
assertNull(testRoundState.setTable);
assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize());
assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
/** */
@Test
public void testWinning() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score roundScore) {
roundEnded = true;
}
});
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
MockTable oldTable = testRoundState.table;
testTable.valid = true;
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand;
Stone blueEight = new Stone(8, BLUE);
Stone blackEight = new Stone(8, BLACK);
Stone redEight = new Stone(8, RED);
Stone orangeEight = new Stone(8, ORANGE);
hand.drop(redEight, new Position(0, 0));
hand.drop(blueEight, new Position(0, 0));
hand.drop(blackEight, new Position(0, 0));
hand.drop(orangeEight, new Position(0, 0));
view.handPanel.stoneClickEvent.emit(redEight, false);
view.handPanel.stoneClickEvent.emit(blueEight, true);
view.handPanel.stoneClickEvent.emit(blackEight, true);
view.handPanel.stoneClickEvent.emit(orangeEight, true);
view.tablePanel.clickEvent.emit(new Position(0, 0));
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand();
}
resetTurnStart();
assertFalse(roundEnded);
view.playerPanel.endTurnEvent.emit();
assertTrue(roundEnded);
}
/** */
@Test
public void testTableDifference() {
MockTable oldTable = new MockTable();
MockTable newTable = new MockTable();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne));
StoneSet oldSet2 = new StoneSet(blueTwo);
oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0));
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour));
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree));
newTable.drop(newSet1, new Position(0, 0));
newTable.drop(newSet2, new Position(0, 0));
Set<Stone> expectedStones = new HashSet<Stone>();
expectedStones.add(blueThree);
expectedStones.add(blueFour);
Set<Stone> stones = RoundControl.tableDifference(oldTable, newTable);
assertTrue(expectedStones.containsAll(stones));
assertTrue(stones.containsAll(expectedStones));
}
/** */
@Test
public void testTableSetDifference() {
ITable oldTable = new Table(gameSettings);
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
Stone orangeOne = new Stone(1, ORANGE);
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
orangeOne));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour));
oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0));
ITable newTable = (Table) oldTable.clone();
List<StoneSet> newSets = RoundControl
.tableSetDifference(oldTable, newTable);
List<StoneSet> vanishedSets = RoundControl.tableSetDifference(newTable,
oldTable);
assertTrue(newSets.isEmpty());
assertTrue(vanishedSets.isEmpty());
newTable.pickUp(oldSet2);
newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position(
0, 0));
newSets = RoundControl.tableSetDifference(oldTable, newTable);
vanishedSets = RoundControl.tableSetDifference(newTable, oldTable);
assertFalse(newSets.isEmpty());
assertFalse(vanishedSets.isEmpty());
assertEquals(1, newSets.size());
assertEquals(1, vanishedSets.size());
Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED);
StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour));
ITable newTable2 = (Table) oldTable.clone();
newTable2.drop(oldSet3, new Position(0, 0));
newSets = RoundControl.tableSetDifference(oldTable, newTable2);
vanishedSets = RoundControl.tableSetDifference(newTable2, oldTable);
assertFalse(newSets.isEmpty());
assertTrue(vanishedSets.isEmpty());
assertEquals(1, newSets.size());
}
/** */
@Test
public void heapIsEmpty() {
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score roundScore) {
roundEnded = true;
}
});
roundState.getGameHeap().drawStones(106 - 14 * 4 - 1);
roundControl.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
IPlayer player1 = roundState.getActivePlayer();
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit(); // player 1 draws a card here
assertSame(player1, roundState.getNthNextPlayer(-1));
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit();
}
assertTrue(roundEnded);
}
/** */
@Test
public void testScore() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score score) {
roundEnded = true;
roundScore = score;
}
});
testRound.startRound();
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand();
}
testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0,
0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0,
0));
testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0, 0));
testRoundState.players.get(2).laidOut = false;
testRoundState.players.get(2).hand.drop(new Stone(9, RED), new Position(0,
0));
testRoundState.players.get(2).hand.drop(new Stone(10, RED), new Position(0,
0));
testRoundState.players.get(2).hand.drop(new Stone(11, RED), new Position(0,
0));
testRoundState.players.get(3).laidOut = true;
testRound.endOfRound();
assertTrue(roundEnded);
for (int i = 0; i < 4; i++) {
assertTrue(roundScore.getWinners().get(i) == (i == 3));
}
assertEquals(-3, (int) roundScore.getPoints().get(0));
assertEquals(-50, (int) roundScore.getPoints().get(1));
assertEquals(-200, (int) roundScore.getPoints().get(2));
assertEquals(253, (int) roundScore.getPoints().get(3));
}
/** */
@Test
public void testScoreWhenHeapEmpty() {
testRound.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score score) {
roundEnded = true;
roundScore = score;
}
});
testRound.startRound();
for (int i = 0; i < 4; i++) {
testRoundState.players.get(i).hand = new Hand();
}
testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0,
0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0,
0));
testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(3, RED), new Position(0,
0));
testRoundState.players.get(2).laidOut = true;
testRoundState.players.get(2).hand.drop(new Stone(3, BLUE), new Position(0,
0));
testRoundState.players.get(3).laidOut = false;
testRoundState.players.get(3).hand.drop(new Stone(13, RED), new Position(0,
0));
testRound.endOfRound();
assertTrue(roundEnded);
assertFalse(roundScore.getWinners().get(0));
assertTrue(roundScore.getWinners().get(1));
assertTrue(roundScore.getWinners().get(2));
assertFalse(roundScore.getWinners().get(3));
assertEquals(-3, (int) roundScore.getPoints().get(0));
assertEquals(-3, (int) roundScore.getPoints().get(1));
assertEquals(-3, (int) roundScore.getPoints().get(2));
assertEquals(-100, (int) roundScore.getPoints().get(3));
}
/** */
@Test
public void testInspectOnly() {
testRound.startRound();
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
assertTrue(view.tablePanel.clickEvent.listeners.isEmpty());
view.playerPanel.endTurnEvent.emit();
assertEquals(14, testRoundState.players.get(i).hand.getSize());
}
for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit();
assertFalse(view.tablePanel.clickEvent.listeners.isEmpty());
view.playerPanel.endTurnEvent.emit();
assertFalse(14 == testRoundState.players.get(i).hand.getSize());
}
}
/** */
@Test
public void testRedeal() {
testRound.getRestartRoundEvent().add(new IListener() {
@Override
public void handle() {
roundRestarted = true;
}
});
testRound.startRound();
view.startTurnEvent.emit();
view.playerPanel.redealEvent.emit();
assertTrue(roundRestarted);
}
/** */
@Test
public void testRedealDisallowed() {
testRound.startRound();
Hand hand = new Hand();
hand.drop(new Stone(1, RED), new Position(0, 0));
hand.drop(new Stone(1, BLACK), new Position(0, 0));
hand.drop(new Stone(1, BLUE), new Position(0, 0));
testRoundState.players.get(0).hand = hand;
view.startTurnEvent.emit();
assertEquals(view.playerPanel.turnMode, TurnMode.INSPECT_ONLY);
for (int i = 0; i < 4; i++) {
view.playerPanel.endTurnEvent.emit();
view.startTurnEvent.emit();
}
assertEquals(view.playerPanel.turnMode, TurnMode.NORMAL_TURN);
}
/** */
@Test
public void testRedealAllowed() {
testRound.startRound();
Hand hand = new Hand();
for (int i = 0; i < 6; i++) {
hand.drop(new Stone(i / 2, RED), new Position(0, 0));
}
testRoundState.players.get(0).hand = hand;
view.startTurnEvent.emit();
assertEquals(view.playerPanel.turnMode, TurnMode.MAY_REDEAL);
for (int i = 0; i < 4; i++) {
view.playerPanel.endTurnEvent.emit();
view.startTurnEvent.emit();
}
assertEquals(view.playerPanel.turnMode, TurnMode.NORMAL_TURN);
}
}
|