-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage01.c
More file actions
executable file
·1422 lines (1289 loc) · 50.6 KB
/
stage01.c
File metadata and controls
executable file
·1422 lines (1289 loc) · 50.6 KB
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
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <assert.h>
#include <nusys.h>
/*includes */
#include "graphic.h"
#include "main.h"
#include "globals.h"
#include "stage01.h"
//atan function
#include "math.c"
/* my models */
#include "pebble_black.h"
#include "pebble_white.h"
#include "cross_by_three.h"
// #include "boardcorners.h"
// #include "boardside.h"
#include "boardsquarealt.h"
#include "boardedge.h"
#include "selectionRing.h"
// #include "boardsquare.h"
#include "table.h"
#include "floor.h"
#include "decal.h"
// borrowed bits
#include "font.h"
#define MAX_DROPS 100
#define MAX_PLAYERS 2
#define MAX_MENU_ITEMS 2
extern NUContData contdata[];
extern u32 nuScRetraceCounter;
Lights1 sun_light = gdSPDefLights1( 200,200,200, /* ambient color red = purple * yellow */
255,0,0,
-80,-80,0);
Lights0 my_ambient_only_light=gdSPDefLights0(200,200,200);
/* camera values ----------------------*/
Vec3d cameraPos = {0.0f, 0.0f, 0.0f}; /*|*/
Vec3d cameraTarget = {0.0f, 0.0f, 0.0f};/*|*/
Vec3d cameraUp = {0.0f, 1.0f, 0.0f}; /*|*/
/*|*/
float cameraDistance; /*|*/
Vec3d cameraRotation; /*|*/
/*-------------------------------------*/
/* ---board structure--- */
typedef struct Pebble{
Vec3d position;
float rotation;
int colour;
} Pebble;
typedef struct boardSquare{
int isEmpty;
Pebble *content; /* set to pointer to pebble in that square*/
} boardSquare;
Pebble pebbles[MAX_DROPS];
int pebbleCount;
int squareCount;
boardSquare board[9][9];
float squareSize;
float boardSize;
/*----------------------*/
/* game values --------------*/
int turnCount;
int2d cursorPos[MAX_PLAYERS];
float xLocation[MAX_PLAYERS];
float zLocation[MAX_PLAYERS];
float xGoal[MAX_PLAYERS];
float zGoal[MAX_PLAYERS];
int blackCaptureScore;
int whiteCaptureScore;
int blackTerritoryScore;
int whiteTerritoryScore;
int bScoreLoc;
int wScoreLoc;
const Vec2d whitePotLocation = {425.0f,0.0f};
const Vec2d blackPotLocation = {-425.0f,0.0f};
int maxTurns;
int gameOver; // BOOL
int gamePause; // BOOL
int lastTurnWasSkipped; // BOOL
int thisTurnWasSkipped; // BOOL
char menuArrow[MAX_MENU_ITEMS];
unsigned int menuSelection; // unsigned because the menu item array is only positive numbers
/*---------------------------*/
/* capture variables --------*/
int currentCaptureGroupColour;
int currentCaptureGroupReachedEmpty;
// if the array size is changed, change the for loop limit in the resetCaptureGroup function too
Vec2d pebblesInCurrentCaptureGroup[100];
int currentCaptureGroupIndex;
/*---------------------------*/
/* territory variables --------*/
int currentTerritoryGroupColour;
int currentTerritoryGroupReachedPebble;
int currentTerritoryGroupReachedWrongPebble;
// if the array size is changed, change the for loop limit in the resetCaptureGroup function too
Vec2d pebblesInCurrentTerritoryGroup[100];
int currentTerritoryGroupIndex;
Vec2d spacesAlreadyCheckedForTerritory[100];
int spacesCheckedForTerritoryIndex;
int sizeOfTerritory;
/*---------------------------*/
/*----- functions -----------*/
int CURRENT_GFX;
// loop values, unfortunately we have a 3 layer deep for loop :(
int i;
int o;
int k;
int timer;
int padNo;
int btn_down;
int padNoThatPaused;
int bannerHeight = (int)(SCREEN_HT/12)-1;
u32 screenWhite = GPACK_RGBA5551(255, 255, 255, 1);
u32 screenBlack = GPACK_RGBA5551(0, 0, 0, 1);
u32 screenRed = GPACK_RGBA5551(255,0,0, 1);
//controller variables
float stickMoveX[MAX_PLAYERS];
float stickMoveY[MAX_PLAYERS];
float moveSpeedSteps[MAX_PLAYERS];
int returnedToCenter[MAX_PLAYERS];
int stickResetFromTimer[MAX_PLAYERS];
/*-----------------------*/
/*--- Debug ----*/
int debugMode;
float debugY;
float debugX;
/*--------------*/
// the 'setup' function
void initStage01() {
// the advantage of initializing these values here, rather than statically, is
// that if you switch stages/levels, and later return to this stage, you can
// call this function to reset these values.
for (i=0; i<MAX_DROPS;i++){
pebbles[i].position.x = NULL;
pebbles[i].position.y = NULL;
pebbles[i].position.z = NULL;
pebbles[i].rotation = 0.0f;
pebbles[i].colour = NULL;
}
pebbleCount = 0;
/*initialise board size and scale*/
squareCount = 9;
for (i=0;i<squareCount;i++){
for (o=0;o<squareCount;o++){
board[i][o].isEmpty = TRUE;
}
}
squareSize = 75.0f; //50.0
boardSize = squareSize*(squareCount-1);
for(padNo=0;padNo<MAX_PLAYERS; padNo++){
//moving values
cursorPos[padNo].x = padNo*(squareCount-1);
cursorPos[padNo].y = (int)squareCount/2;
stickMoveX[padNo] = 0;
stickMoveY[padNo] = 0;
xLocation[padNo] = cursorPos[padNo].x*squareSize - (boardSize/2);
zLocation[padNo] = cursorPos[padNo].y*squareSize - (boardSize/2);
xGoal[padNo] = xLocation[padNo];
zGoal[padNo] = zLocation[padNo];
returnedToCenter[padNo] = TRUE;
moveSpeedSteps[padNo] = 1;
stickResetFromTimer[padNo] = 0;
moveCursor(padNo,0,0);
}
menuArrow[0] = '-';
for(i=1;i<MAX_MENU_ITEMS;i++){
menuArrow[i]= ' ';
}
menuSelection = 0;
setDefaultCamera();
timer = 0;
turnCount = 0;
blackCaptureScore = 0;
whiteCaptureScore = 0;
blackTerritoryScore = 0;
whiteTerritoryScore = 0;
maxTurns = 200;
gameOver = FALSE;
gamePause = FALSE;
btn_down = FALSE;
thisTurnWasSkipped = FALSE;
lastTurnWasSkipped = FALSE;
// debug
debugMode = FALSE;
debugX = 0.0f;
debugY = 0.0f;
//functions
resetCaptureGroup();
nuAuSeqPlayerStop(0);
nuAuSeqPlayerSetNo(0,0);
nuAuSeqPlayerPlay(0);
nuAuSeqPlayerSetVol(0,0x3fff);
}
// the 'update' function
void updateGame01() {
if(gamePause == FALSE){
timer++;
}
// nuContDataGetExAll(contdata);
for(padNo=0;padNo<MAX_PLAYERS;padNo++){
readController(padNo);
if(gamePause == FALSE){
movePebble(padNo);
}
}
moveCamera();
//moving the pebbles
// for(i=0; i<pebbleCount;i++){
// pebbles[i].position.x = pebbles[i].position.x + pebbles[i].velocity*cos(pebbles[i].rotation);
// pebbles[i].position.z = pebbles[i].position.z + pebbles[i].velocity*sin(pebbles[i].rotation);
// }
/* check contact with n64 */
// for( i =0; i< pebbleCount;i++){
// if ( pebbles[i].position.x < 550 + range && pebbles[i].position.x > 550 - range){
// if( pebbles[i].position.z < 550 + range && pebbles[i].position.z > 550 - range){
// if ( isHit == FALSE ) {
// nuAuSndPlayerPlay(5);
// }
// isHit = TRUE;
// }
// }
// }
}
void takeTurn(int padNo){
// osSyncPrintf("Turn taken from player %d", padNo);
placeCounter(padNo);
checkForCaptures(padNo);
calculateTerritories();
checkGameOver();
}
void readController(int padNo){
// read controller input from controllers
// nuContDataGetEx(contdata, padNo);
// We check if the 'A' Button was pressed using a bitwise AND with
// contdata[0].trigger and the A_BUTTON constant.
// The contdata[0].trigger property is set only for the frame that the button is
// initially pressed. The contdata[0].button property is similar, but stays on
// for the duration of the button press.
if( gameOver == FALSE){
if (contdata[padNo].trigger & START_BUTTON){
//start button pressed and not game over'd
if(gamePause == FALSE){
gamePause = TRUE;
padNoThatPaused = padNo;
setDefaultCamera();
nuAuSeqPlayerSetVol(0,0x1fff);
}else if(padNoThatPaused == padNo){
gamePause = FALSE;
nuAuSeqPlayerSetVol(0,0x3fff);
}
} else {
if( gamePause == FALSE){
//game is not paused, and not game over'd
if( turnCount % 2 == padNo){
// stops players placing a piece out of turn
if (contdata[padNo].trigger & A_BUTTON){
takeTurn(padNo);
}else if( contdata[padNo].trigger & B_BUTTON){
passTurn();
}
}
}else{
// game is paused, and not game over
if(padNo == padNoThatPaused){
if (contdata[padNo].trigger & U_JPAD){
menuSelection--;
menuSelection = menuSelection%MAX_MENU_ITEMS;
updateMenuArrow();
}else if (contdata[padNo].trigger & D_JPAD){
menuSelection++;
menuSelection = menuSelection%MAX_MENU_ITEMS;
updateMenuArrow();
}
if(contdata[padNo].trigger & A_BUTTON){
btn_down = TRUE;
}
//selects option when button is released
if(!(contdata[padNo].button & A_BUTTON) && btn_down == TRUE){
//start button pressed then return to title screen
switch (menuSelection){
case 0 : // continue
//this is the same as pressing start
gamePause = FALSE;
btn_down = FALSE;
nuAuSeqPlayerSetVol(0,0x3fff);
break;
case 1 : // quit
quit();
btn_down= FALSE;
break;
}
}
}
}
}
//c buttons to move the camera round please
if (contdata[padNo].button & U_CBUTTONS)
cameraRotation.y -= 0.05;
if(cameraRotation.y <= -(M_PI/2)+0.01f){
cameraRotation.y = -(M_PI/2)+0.01f;
}
if (contdata[padNo].button & D_CBUTTONS)
cameraRotation.y += 0.05;
if(cameraRotation.y >= (M_PI/2)-0.01f){
cameraRotation.y = (M_PI/2)-0.01f;
}
if (contdata[padNo].button & L_CBUTTONS)
cameraRotation.x -= 0.05;
if (contdata[padNo].button & R_CBUTTONS)
cameraRotation.x += 0.05;
if(contdata[padNo].button & Z_TRIG ){
cameraDistance = cameraDistance+2.0f;
}
if(contdata[padNo].button & R_TRIG ){
cameraDistance = cameraDistance-2.0f;
}
}else{
//game is over
if(contdata[padNo].trigger & START_BUTTON){
//start button pressed then return to title screen
quit();
}
}
// debug
if(contdata[padNo].trigger & L_TRIG){
debugMode ^= 1;
nuDebConClear(NU_DEB_CON_WINDOW0);
}
if(debugMode == TRUE){
if(contdata[padNo].trigger & U_JPAD){
debugY += 1.0f;
}else if( contdata[padNo].trigger & D_JPAD){
debugY -= 1.0f;
}
if(contdata[padNo].trigger & R_JPAD){
debugX += 1.0f;
}else if( contdata[padNo].trigger & L_JPAD){
debugX -= 1.0f;
}
}
}
void quit(){
nuGfxFuncRemove();
nuAuSeqPlayerStop(0);
stage = 0;
}
void moveCamera(){
//moving the camera
cameraTarget.x = 0.0f;
cameraTarget.y = 0;
cameraTarget.z = -111.1f*cameraRotation.y + 173.0f;
cameraPos.x = cameraTarget.x + ( cameraDistance * sin(cameraRotation.x) * cos(cameraRotation.y) );
cameraPos.y = cameraTarget.y + ( cameraDistance * sin(cameraRotation.y) );
cameraPos.z = cameraTarget.z + ( cameraDistance * cos(cameraRotation.x) * cos(cameraRotation.y) );
}
void setDefaultCamera(){
cameraPos.x = 0.0f;
cameraPos.y = 0.0f;
cameraPos.z = 0.0f;
cameraDistance = 7.0f*(squareCount*squareCount) + 300.0f;
cameraRotation.x = 0.0f;
cameraRotation.y = 1.0f;
cameraRotation.z = 0.0f;
}
void setTopDownCamera(){
cameraPos.x = 0.0f;
cameraPos.y = 0.0f;
cameraPos.z = 0.0f;
cameraDistance = 7.0f*(squareCount*squareCount) + 200.0f;
cameraRotation.x = 0.0f;
cameraRotation.y = M_PI/2;
cameraRotation.z = 0.0f;
}
void updateMenuArrow(){
for(i=0;i<MAX_MENU_ITEMS;i++){
if(menuSelection == i){
menuArrow[i] = '-';
}else{
menuArrow[i] = ' ';
}
}
}
void movePebble(int padNo){
//setting values for the controller sticks, divided by 80 to reduce the range to be from 0 to 1
stickMoveX[padNo] = contdata[padNo].stick_x/80.0f;
stickMoveY[padNo] = contdata[padNo].stick_y/80.0f;
//moving the object
if((stickMoveX[padNo] != 0 || stickMoveY[padNo] != 0 )&& returnedToCenter[padNo] == TRUE){
returnedToCenter[padNo] = FALSE;
if ( abs(stickMoveX[padNo]*100) > abs(stickMoveY[padNo]*100) ){
//moving left right
if ( stickMoveX[padNo] < 0){
moveCursor(padNo,-1,0);
} else {
moveCursor(padNo,1,0);
}
} else {
//moving up down
if ( stickMoveY[padNo] < 0){
moveCursor(padNo,0,1);
} else {
moveCursor(padNo,0,-1);
}
}
}
if(
returnedToCenter[padNo] == FALSE &&
(stickMoveX[padNo] == 0 && stickMoveY[padNo] == 0 || (timer - stickResetFromTimer[padNo]) % 15 == 0)
){
returnedToCenter[padNo] = TRUE;
}
//moving the cursor
xLocation[padNo] += (xGoal[padNo]-xLocation[padNo])/moveSpeedSteps[padNo];
zLocation[padNo] += (zGoal[padNo]-zLocation[padNo])/moveSpeedSteps[padNo];
// adds a ease-out effect to the movement of the spinning pebble above the cursor
// movespeed steps reaches 1 at which point the calculation above will divide by 1, and reach the x and z goal values
if(moveSpeedSteps[padNo]<1.1){
moveSpeedSteps[padNo]=1;
}else{
moveSpeedSteps[padNo] *= 0.95;
}
}
void moveCursor(int padNo, int xDelta, int yDelta){
//setting position of cursor & setting when the cursor can move again
//stopping border breaks
if( 0 <= (cursorPos[padNo].x + xDelta) && (cursorPos[padNo].x + xDelta) < squareCount &&
0 <= (cursorPos[padNo].y + yDelta) && (cursorPos[padNo].y + yDelta) < squareCount){
// if( isEmpty(cursorPos[padNo].x+xDelta,cursorPos[padNo].y+yDelta) == TRUE){
cursorPos[padNo].x += xDelta;
cursorPos[padNo].y += yDelta;
// }
}
xGoal[padNo] = cursorPos[padNo].x*squareSize - (boardSize/2);
zGoal[padNo] = cursorPos[padNo].y*squareSize - (boardSize/2);
// lower this is the faster the pebble cursor will move
moveSpeedSteps[padNo] = 5;
stickResetFromTimer[padNo] = timer - 1; // -1 to stop it resetting the count immediately
}
void removePebble(int x, int y){
if(board[x][y].isEmpty == FALSE){
board[x][y].isEmpty = TRUE;
movePebbleToDiscardPot(board[x][y].content);
if((*board[x][y].content).colour == WHITE){
blackCaptureScore++;
}else{
whiteCaptureScore++;
}
board[x][y].content = NULL;
}
}
void movePebbleToDiscardPot(Pebble *pebble){
if((*pebble).colour == WHITE){
// move captured white pebbles to the pile
(*pebble).position.x = whitePotLocation.x;
// makes the pebbles rise
(*pebble).position.y = blackCaptureScore * 10;
(*pebble).position.z = whitePotLocation.y;
}else{
// move captured black pebbles to the pile
(*pebble).position.x = blackPotLocation.x;
(*pebble).position.y = whiteCaptureScore * 10;
(*pebble).position.z = blackPotLocation.y;
}
}
void undoPebblePlace(padNo){
board[cursorPos[padNo].x][cursorPos[padNo].y].content = NULL;
board[cursorPos[padNo].x][cursorPos[padNo].y].isEmpty = TRUE;
pebbleCount--;
turnCount--;
thisTurnWasSkipped = FALSE;
}
void passTurn(){
// cant skip on first two turns
if(turnCount > 1){
lastTurnWasSkipped = thisTurnWasSkipped;
thisTurnWasSkipped = TRUE;
turnCount++;
checkGameOver();
}
}
void placeCounter(int padNo) {
if(board[cursorPos[padNo].x][cursorPos[padNo].y].isEmpty == TRUE){
if( pebbleCount <= MAX_DROPS ){
for (i = 0; i < MAX_DROPS; i++) {
//check which number is next to store
if( i == pebbleCount ){
pebbleCount++;
if( pebbleCount >= MAX_DROPS ){
nuAuSndPlayerPlay(1);
}else{
nuAuSndPlayerPlay(4);
}
pebbleCount = pebbleCount % MAX_DROPS;
// pebbles[i].x = ((int)(xLocation[padNo]/150))*150;
pebbles[i].position.x = xGoal[padNo];
pebbles[i].position.y = 10.0f;
// pebbles[i].z = ((int)(zLocation/150))*150;
pebbles[i].position.z = zGoal[padNo];
pebbles[i].rotation = 0.0f;
if(turnCount%2==0){
pebbles[i].colour = BLACK;
}else{
pebbles[i].colour = WHITE;
}
board[cursorPos[padNo].x][cursorPos[padNo].y].content = &pebbles[i];
board[cursorPos[padNo].x][cursorPos[padNo].y].isEmpty = FALSE;
turnCount++;
lastTurnWasSkipped = FALSE;
thisTurnWasSkipped = FALSE;
break;
}
}
}
}else{
// cant place piece because board place is occupied
// BONG noise
nuAuSndPlayerPlay((int)debugX);
}
}
int isOffBoard(int x, int y){
if( 0 <= x && x < squareCount && 0 <= y && y < squareCount ){
return FALSE;
}else{
return TRUE;
}
}
void resetCaptureGroup(){
currentCaptureGroupIndex = 0;
// for (i=0;i<100;i++){
// pebblesInCurrentCaptureGroup[i] = NULL;
// }
}
// returning 0 means self capture avoided
// returning 1 means capture occured
// returning 2 means nothing happened
int checkForCaptures(int padNo){
for(i=0;i<squareCount; ++i){
for(o=0;o<squareCount; ++o){
if(board[i][o].isEmpty == FALSE){
// osSyncPrintf("\n-----A capture chain has begun-----\n");
resetCaptureGroup();
// set values for current check
currentCaptureGroupReachedEmpty = FALSE;
currentCaptureGroupColour = (*board[i][o].content).colour;
// osSyncPrintf("Starting from %d,%d, colour is: %d\n",i,o,currentCaptureGroupColour);
// add current to list of pebbles checked
pebblesInCurrentCaptureGroup[currentCaptureGroupIndex].x = i;
pebblesInCurrentCaptureGroup[currentCaptureGroupIndex].y = o;
currentCaptureGroupIndex++;
startCheckingFromHere(i,o);
// after the checks occured the spaces put into the array should be the current territory to capture,
// if the checks never reached an empty space then capture the pieces
if(currentCaptureGroupReachedEmpty == FALSE){
// osSyncPrintf("-------The capture group found an enclosed section!-----\n");
// before capturing the pieces we need to check if its a self capture
if(currentCaptureGroupColour == (*board[cursorPos[padNo].x][cursorPos[padNo].y].content).colour){
// is a self capture, so capture will not take place, and pebble will be 'un placed'
undoPebblePlace(padNo);
// BONG noise
nuAuSndPlayerPlay(1);
return 0;
}else{
// capture pieces
for(k=0;k<currentCaptureGroupIndex;++k){
removePebble(pebblesInCurrentCaptureGroup[k].x,pebblesInCurrentCaptureGroup[k].y);
}
//pling noise
nuAuSndPlayerPlay(6);
return 1;
}
}
}
}
}
return 2;
}
void startCheckingFromHere(int x, int y){
// osSyncPrintf("expanding checking from %d,%d\n",x,y);
checkCapturesContinues(x+1,y);
checkCapturesContinues(x ,y+1);
checkCapturesContinues(x-1,y );
checkCapturesContinues(x ,y-1 );
}
void checkCapturesContinues(int x, int y){
// osSyncPrintf("continue checking %d,%d\n",x,y);
if(isOffBoard(x,y) == FALSE){
if(board[x][y].isEmpty == TRUE){
// Found an empty space in the capture, so stop altogether
// osSyncPrintf("%d,%d reached empty\n",x,y);
currentCaptureGroupReachedEmpty = TRUE;
// only continue if the space is on the board, same colour as the current group, and other checks haven't found empty space.
}else if(currentCaptureGroupReachedEmpty == FALSE && isInCurrentCaptureGroup(x,y) == FALSE){
if(currentCaptureGroupColour == (*board[x][y].content).colour){
pebblesInCurrentCaptureGroup[currentCaptureGroupIndex].x = x;
pebblesInCurrentCaptureGroup[currentCaptureGroupIndex].y = y;
currentCaptureGroupIndex++;
// osSyncPrintf("%d,%d was correct and the search continues\n",x,y);
startCheckingFromHere(x,y);
}
}
}
}
int isInCurrentCaptureGroup(int x, int y){
// osSyncPrintf("/\\/\\ welcome to the isInCUrrentCaptureGroup function! /\\/\\\n");
for(k=0;k<currentCaptureGroupIndex;k++){
// osSyncPrintf("comparing at index: %d",k);
// osSyncPrintf("x: %d, y: %d",pebblesInCurrentCaptureGroup[k].x,pebblesInCurrentCaptureGroup[k].y);
if(pebblesInCurrentCaptureGroup[k].x == x && pebblesInCurrentCaptureGroup[k].y == y){
return TRUE;
}
}
return FALSE;
}
void calculateTerritories(){
whiteTerritoryScore = 0;
blackTerritoryScore = 0;
// spacesCheckedForTerritoryIndex = 0;
resetTerritoryGroup();
sizeOfTerritory = 0;
if( turnCount > 1 ){
for(i=0;i<squareCount; ++i){
for(o=0;o<squareCount; ++o){
//calculate the territories, very similar to capture checking except no capturing takes place
if(board[i][o].isEmpty == TRUE && isInCurrentTerritoryGroup(i,o) == FALSE){
// osSyncPrintf("\n-----A capture chain has begun-----\n");
// set values for current check
sizeOfTerritory = 0;
currentTerritoryGroupReachedWrongPebble = FALSE;
currentTerritoryGroupReachedPebble = FALSE;
// currentTerritoryGroupColour = (*board[i][o].content).colour;
// osSyncPrintf("Starting from %d,%d, colour is: %d\n",i,o,currentCaptureGroupColour);
// add current to list of pebbles checked
// addToTerritoryPlacesChecked(i,o);
pebblesInCurrentTerritoryGroup[currentTerritoryGroupIndex].x = i;
pebblesInCurrentTerritoryGroup[currentTerritoryGroupIndex].y = o;
currentTerritoryGroupIndex++;
sizeOfTerritory++;
// spacesAlreadyCheckedForTerritory[spacesCheckedForTerritoryIndex].x = i;
// spacesAlreadyCheckedForTerritory[spacesCheckedForTerritoryIndex].y = o;
// spacesCheckedForTerritoryIndex++;
startCheckingTerritoriesFromHere(i,o);
// after the checks occured the spaces put into the array should be the current territory to capture,
// if the checks never reached an empty space then capture the pieces
if(currentTerritoryGroupReachedWrongPebble == FALSE){
// osSyncPrintf("-------The capture group found an enclosed section!-----\n");
if(currentTerritoryGroupColour == WHITE){
// whiteTerritoryScore += currentTerritoryGroupIndex;
whiteTerritoryScore += sizeOfTerritory;
sizeOfTerritory = 0;
}else{
// blackTerritoryScore += currentTerritoryGroupIndex;
blackTerritoryScore += sizeOfTerritory;
sizeOfTerritory = 0;
}
}
}
}
}
}
}
void resetTerritoryGroup(){
currentTerritoryGroupIndex = 0;
// for (i=0;i<100;i++){
// pebblesInCurrentCaptureGroup[i] = NULL;
// }
}
void startCheckingTerritoriesFromHere(int x, int y){
// osSyncPrintf("expanding checking from %d,%d\n",x,y);
checkTerritoryContinues(x+1,y );
checkTerritoryContinues(x ,y+1);
checkTerritoryContinues(x-1,y );
checkTerritoryContinues(x ,y-1);
}
void checkTerritoryContinues(int x, int y){
// osSyncPrintf("continue checking %d,%d\n",x,y);
if(isOffBoard(x,y) == FALSE ){
if(board[x][y].isEmpty == TRUE /*&& isAlreadyCheckedForTerritory(x,y) == FALSE*/){
if(isInCurrentTerritoryGroup(x,y) == FALSE){
// Found an empty space in the capture, so stop altogether
// osSyncPrintf("%d,%d reached empty\n",x,y);
pebblesInCurrentTerritoryGroup[currentTerritoryGroupIndex].x = x;
pebblesInCurrentTerritoryGroup[currentTerritoryGroupIndex].y = y;
currentTerritoryGroupIndex++;
sizeOfTerritory++;
// spacesAlreadyCheckedForTerritory[spacesCheckedForTerritoryIndex].x = x;
// spacesAlreadyCheckedForTerritory[spacesCheckedForTerritoryIndex].y = y;
// spacesCheckedForTerritoryIndex++;
// osSyncPrintf("%d,%d was correct and the search continues\n",x,y);
startCheckingTerritoriesFromHere(x,y);
}
// only continue if the space is on the board, same colour as the current group, and other checks haven't found empty space.
}else if(currentTerritoryGroupReachedPebble == FALSE){
currentTerritoryGroupColour = (*board[x][y].content).colour;
currentTerritoryGroupReachedPebble = TRUE;
}else if(currentTerritoryGroupReachedPebble == TRUE){
//second time reaching a pebble, best be the same colour as before or we are stopping
if(currentTerritoryGroupColour != (*board[x][y].content).colour){
currentTerritoryGroupReachedWrongPebble = TRUE;
}
}
}
}
int isInCurrentTerritoryGroup(int x, int y){
// osSyncPrintf("/\\/\\ welcome to the isInCUrrentCaptureGroup function! /\\/\\\n");
for(k=0;k<currentTerritoryGroupIndex;k++){
// osSyncPrintf("comparing at index: %d",k);
// osSyncPrintf("x: %d, y: %d",pebblesInCurrentCaptureGroup[k].x,pebblesInCurrentCaptureGroup[k].y);
if(pebblesInCurrentTerritoryGroup[k].x == x && pebblesInCurrentTerritoryGroup[k].y == y){
return TRUE;
}
}
return FALSE;
}
int isAlreadyCheckedForTerritory(int x, int y){
// osSyncPrintf("/\\/\\ welcome to the isInCUrrentCaptureGroup function! /\\/\\\n");
for(k=0;k<spacesCheckedForTerritoryIndex;k++){
// osSyncPrintf("comparing at index: %d",k);
// osSyncPrintf("x: %d, y: %d",pebblesInCurrentCaptureGroup[k].x,pebblesInCurrentCaptureGroup[k].y);
if(spacesAlreadyCheckedForTerritory[k].x == x && spacesAlreadyCheckedForTerritory[k].y == y){
return TRUE;
}
}
return FALSE;
}
void checkGameOver(){
if(turnCount >= maxTurns || (lastTurnWasSkipped == TRUE && thisTurnWasSkipped == TRUE)){
gameOver = TRUE;
setTopDownCamera();
// nuAuSeqPlayerStop(0);
// nuAuSeqPlayerSetNo(0,0);
// nuAuSeqPlayerPlay(0);
}
}
// the 'draw' function
void makeDL01() {
unsigned short perspNorm;
GraphicsTask * gfxTask;
char conbuf[30];
// switch the current graphics task
// also updates the displayListPtr global variable
gfxTask = gfxSwitchTask();
// prepare the RCP for rendering a graphics task
gfxRCPInit();
// clear the color framebuffer and Z-buffer, similar to glClear()
gfxClearCfb();
// initialize the projection matrix, similar to glPerspective() or glm::perspective()
guPerspective(&gfxTask->projection, &perspNorm, FOVY, ASPECT, NEAR_PLANE,
FAR_PLANE, 1.0);
// Our first actual displaylist command. This writes the command as a value at
// the tail of the current display list, and we increment the display list
// tail pointer, ready for the next command to be written.
// As for what this command does... it's just required when using a perspective
// projection. Try pasting 'gSPPerspNormalize' into google if you want more
// explanation, as all the SDK documentation has been placed online by
// hobbyists and is well indexed.
gSPPerspNormalize(displayListPtr++, perspNorm);
// initialize the modelview matrix, similar to gluLookAt() or glm::lookAt()
guLookAt(&gfxTask->modelview, cameraPos.x, cameraPos.y,
cameraPos.z, cameraTarget.x, cameraTarget.y,
cameraTarget.z, cameraUp.x, cameraUp.y, cameraUp.z);
// guLookAt(&gfxTask->modelview, -xLocation - 400.0f, zLocation,
// cameraPos.z, -xLocation, zLocation,
// cameraTarget.z, cameraUp.x, cameraUp.y, cameraUp.z);
// load the projection matrix into the matrix stack.
// given the combination of G_MTX_flags we provide, effectively this means
// "replace the projection matrix with this new matrix"
gSPMatrix(
displayListPtr++,
// we use the OS_K0_TO_PHYSICAL macro to convert the pointer to this matrix
// into a 'physical' address as required by the RCP
OS_K0_TO_PHYSICAL(&(gfxTask->projection)),
// these flags tell the graphics microcode what to do with this matrix
// documented here: http://n64devkit.square7.ch/tutorial/graphics/1/1_3.htm
G_MTX_PROJECTION | // using the projection matrix stack...
G_MTX_LOAD | // don't multiply matrix by previously-top matrix in stack
G_MTX_NOPUSH // don't push another matrix onto the stack before operation
);
gSPMatrix(displayListPtr++,
OS_K0_TO_PHYSICAL(&(gfxTask->modelview)),
// similarly this combination means "replace the modelview matrix with this new matrix"
G_MTX_MODELVIEW | G_MTX_NOPUSH | G_MTX_LOAD
);
gSPSetLights0(displayListPtr++, my_ambient_only_light);
gSPSetLights1(displayListPtr++, sun_light);
//sets the background to white
gDPSetCycleType(displayListPtr++, G_CYC_FILL);
gDPSetRenderMode(displayListPtr++, G_RM_OPA_SURF, G_RM_OPA_SURF);
if(gameOver == FALSE){
gDPSetFillColor(displayListPtr++, screenWhite);
}else{
gDPSetFillColor(displayListPtr++, (blackCaptureScore+blackTerritoryScore > whiteCaptureScore+whiteTerritoryScore) ? screenBlack:screenWhite);
}
gDPFillRectangle(displayListPtr++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
gDPNoOp(displayListPtr++);
gDPPipeSync(displayListPtr++);
{
if(gameOver== FALSE){
CURRENT_GFX = -1;
CURRENT_GFX++;
guPosition(&gfxTask->objectTransforms[CURRENT_GFX],0.0f,0.0f,0.0f,2.5f, debugX, 50.0f, debugY);
gSPMatrix(displayListPtr++,
OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
G_MTX_MODELVIEW | // operating on the modelview matrix stack...
G_MTX_PUSH | // ...push another matrix onto the stack...
G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
);
drawTransModel(Wtx_selectionring);
gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
// for(i=0;i<(squareCount-1)/2; ++i){
// for(o=0;o<(squareCount-1)/2; ++o){
// CURRENT_GFX++;
// guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
// 0.0f, //angle it to be flat
// 0.0f, 0.0f,
// (2.5f), //scale based on square size
// i * squareSize*2.0f - boardSize/2.0f + squareSize, //x, the *2 is the same as the /2 in the for loop
// 0.0f,//y move down
// o * squareSize*2.0f - boardSize/2.0f + squareSize); //z
// gSPMatrix(displayListPtr++,
// OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
// G_MTX_MODELVIEW | // operating on the modelview matrix stack...
// G_MTX_PUSH | // ...push another matrix onto the stack...
// G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
// );
// drawModel(Wtx_boardsquare);
// gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
// }
// }
// for(i=0;i<2; ++i){
// for(o=0;o<2; ++o){
CURRENT_GFX++;
guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
0.0f, //angle it to be flat
0.0f, 0.0f,
(2.5f), //scale based on square size
0.0f, //x, the *2 is the same as the /2 in the for loop
0.0f,//y move down
0.0f); //z
gSPMatrix(displayListPtr++,
OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
G_MTX_MODELVIEW | // operating on the modelview matrix stack...
G_MTX_PUSH | // ...push another matrix onto the stack...
G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
);
drawModel(Wtx_boardsquarealt);
gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
// }
// }
CURRENT_GFX++;
guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
0.0f, //angle it to be flat
0.0f, 0.0f,
2.5f, //scale based on square size
0.0f, //x
0.0f,//y move down
0.0f); //z
gSPMatrix(displayListPtr++,
OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
G_MTX_MODELVIEW | // operating on the modelview matrix stack...
G_MTX_PUSH | // ...push another matrix onto the stack...
G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
);
drawModel(Wtx_boardedge);
gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
// for(i=0;i<4;i++){
// CURRENT_GFX++;
// guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
// 0.0f, //angle it to be flat
// i*90.0f, 0.0f,
// 2.5f, //scale based on square size
// 0.0f, //x
// 0.0f,//y move down
// 0.0f); //z
// gSPMatrix(displayListPtr++,
// OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
// G_MTX_MODELVIEW | // operating on the modelview matrix stack...
// G_MTX_PUSH | // ...push another matrix onto the stack...
// G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
// );
// if(i < 2){
// drawModel(Wtx_boardside);
// }else{
// drawModel(Wtx_boardside_mirror);
// }
// gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
// }
// CURRENT_GFX++;
// guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
// 0.0f, //angle it to be flat
// 0.0f, 0.0f,
// 2.5f, //scale based on square size
// 0.0f, //x
// 0.0f,//y move down
// 0.0f); //z
// gSPMatrix(displayListPtr++,
// OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
// G_MTX_MODELVIEW | // operating on the modelview matrix stack...
// G_MTX_PUSH | // ...push another matrix onto the stack...
// G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)
// );
// drawModel(Wtx_floor);
// gSPPopMatrix(displayListPtr++, G_MTX_MODELVIEW);
//
//
//
// CURRENT_GFX++;
// guPosition(&gfxTask->objectTransforms[CURRENT_GFX],
// 0.0f, //angle it to be flat
// 0.0f, 0.0f,
// 2.5f, //scale based on square size
// 0.0f, //x
// 0.0f,//y move down
// 0.0f); //z
// gSPMatrix(displayListPtr++,
// OS_K0_TO_PHYSICAL(&(gfxTask->objectTransforms[CURRENT_GFX])),
// G_MTX_MODELVIEW | // operating on the modelview matrix stack...
// G_MTX_PUSH | // ...push another matrix onto the stack...
// G_MTX_MUL // ...which is multipled by previously-top matrix (eg. a relative transformation)