-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
1036 lines (611 loc) · 21.1 KB
/
Game.java
File metadata and controls
1036 lines (611 loc) · 21.1 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
package Auto120;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class Game {
int g_movecounter = 1; //for logging
String[] g_movelog = new String[999999];
int g_playerturn;
Player[] g_players = new Player[3];
//TODO initiate players 1 and 2
int g_dievalue = 0;
boolean g_gameover = false;
int m_owner;
int m_location;
public Game() {
// TODO Auto-generated constructor stub
g_movecounter = 0;
g_playerturn = g_return_random(2); //TODO
g_logmove("Player " + Integer.toString(g_playerturn) + " will go first."); //TODO
g_dievalue = 0;
g_gameover = false;
//rest of game
g_newgame(); //TODO
//g_displaylog();
}
//methods
public void g_newgame() {
//create players was done in constructor, now assign markers
g_players[1] = new Player(1);
g_logmove("Player 1 created.");
g_players[2] = new Player(2);
g_logmove("Player 2 created.");
}
public int g_get_playerturn() {
return g_playerturn;
}
public void g_flip_player() {
if (g_playerturn == 1) {
g_playerturn = 2;
}
else
{
g_playerturn = 1;
}
}
Player g_return_other_player() {
if (g_playerturn == 1) {
return g_players[2];
}
else
{
return g_players[1];
}
}
public int g_diceroll() {
g_dievalue = g_return_random(6);
return g_dievalue;
}
public Player g_return_player(int x_playerid) {
return g_players[x_playerid];
}
public void g_displaylog()
{
int x_counter = 0;
for (x_counter = 0; x_counter <= g_movecounter-1; x_counter++)
{
System.out.print(g_movelog[x_counter] + "\n");
}
}
public int g_return_random(int g_upper)
{
Random r = new Random();
return r.nextInt((g_upper - 1) + 1) + 1;
}
public void g_logmove(String x_logmove)
{
Integer x_movecounter = this.g_movecounter;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
String x_timestamp = dtf.format(now);
g_movelog[x_movecounter] = (x_timestamp + " -- " + x_logmove);
this.g_movecounter++;
}
public boolean g_move_onto_board_set_D(Player x_player)
{
int x_piece_pointer = g_find_to_move_onto_board(x_player);
if (x_piece_pointer == 0)
{
//no more pieces to move on to the board
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " did not have pieces to move into play.");
return false;
}
else
{
g_marker_move(x_player.p_get_playerid(), x_piece_pointer);
return true;
}
}
//D - find a marker not on the board, select one to move
public int g_find_to_move_onto_board(Player x_player) {
int[] x_piece_array_pointer = {0,0,0,0,0};
int x_counter_array = 0;
int x_counter = 0;
for (x_counter = 1; x_counter <= 4; x_counter++)
{
if (x_player.p_pieces[x_counter].m_get_location() == 1) {
x_piece_array_pointer[++x_counter_array] = x_counter;
}
}
//If there is one or more, return one at random
if (x_counter_array > 0) {
x_counter = g_return_random(x_counter_array);
return x_piece_array_pointer[x_counter];
}
else
{
//there were no markers 'off the board'...return an empty pointer;
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " was in SET D but could not find markers.");
return 0;
}
}
public void g_marker_move(int x_playerid, int x_piece_pointer)
{
String x_logstring = "";
String x_text = "";
int x_old_position = 0;
int x_new_location = 0;
Player x_other_player = g_return_other_player();
x_old_position = g_players[x_playerid].p_pieces[x_piece_pointer].m_get_location();
if (g_dievalue != 0)
{
x_new_location = g_players[x_playerid].p_pieces[x_piece_pointer].m_calclocation(g_dievalue);
}
else
{
//Piece has been bumped to the start either due to clash or blow-out
x_new_location = 1;
}
if (x_new_location > 120)
{
//blow-out!
x_logstring = "Player " + Integer.toString(x_playerid) + " busted piece " + Integer.toString(x_piece_pointer) + " to a value of " + Integer.toString(x_new_location) + "!";
g_logmove(x_logstring);
x_new_location = 1;
}
g_players[x_playerid].p_pieces[x_piece_pointer].m_setlocation(x_new_location);
x_logstring = "[[[Player " + Integer.toString(x_playerid) + " moved piece " + Integer.toString(x_piece_pointer) + " from position " + Integer.toString(x_old_position) + " to " + Integer.toString(g_players[x_playerid].p_pieces[x_piece_pointer].m_get_location()) + "]]]";
g_logmove(x_logstring);
//call clash detect unless it has moved to 1
if (x_new_location == 120)
{
//piece has made it to the end and will be disabled
if (g_players[x_playerid].p_pieces[x_piece_pointer].m_get_status())
{
x_text = "ACTIVE";
}
else
{
x_text = "INACTIVE";
}
x_logstring = "Player " + Integer.toString(x_playerid) + "s piece " + Integer.toString(x_piece_pointer) + " has reached position " + Integer.toString(g_players[x_playerid].p_pieces[x_piece_pointer].m_get_location()) + " successfully and is now " + x_text;
g_logmove(x_logstring);
}
if (x_new_location != 1 && x_new_location != 120)
{
g_detect_clash(g_players[x_playerid].p_pieces[x_piece_pointer].m_get_location(), x_other_player);
}
g_gameover = g_players[x_playerid].p_check_game_status(g_players[x_playerid]);
}
public boolean g_detect_clash(int x_location, Player x_player) {
//iterate through opposing players active pieces and reset them if the new move has caused a clash
int x_counter = 0;
boolean x_return_flag = false;
for (x_counter = 1; x_counter <= 4; x_counter++) {
//find an (opposition) player's marker which is on the board but active
if (x_player.p_pieces[x_counter].m_get_location() == x_location && x_player.p_pieces[x_counter].m_get_status())
{
//bump the clash piece
g_dievalue = 0;
g_marker_move(x_player.p_get_playerid(), x_counter);
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + "'s piece " + Integer.toString(x_counter) + " was bumped to the start of the board!");
x_return_flag = true;
} //if it doesn't find a clash, do nothing
}
return x_return_flag;
}
int g_find_to_move_in_play(Player x_player)
{
int[] x_piece_array_pointer = { 0,0,0,0,0 };
int[] x_piece_array_backup = { 0,0,0,0,0 };
int x_counter_array = 0;
int x_counter_loop = 0;
int x_temp_value = 0;
int x_counter = 0;
final Set<Integer> x_temp_magic_numbers = new HashSet<Integer>();
x_temp_magic_numbers.addAll( Arrays.asList( 20,24,30,40,60));
// integer x_temp_magic_numbers[] = { 20,24,30,40,60 };
boolean x_test_1 = false;
boolean x_test_2 = false;
for (x_counter = 1; x_counter <= 4; x_counter++)
//find a player's marker which is active
if (x_player.p_pieces[x_counter].m_get_status())
{
x_counter_array++;
x_piece_array_pointer[x_counter_array] = x_counter;
//x_piece_array_backup[x_counter_array] = x_counter; //redundant?
}
//hopefully won't fail as index 0 is not set //well...it did.. kes
System.arraycopy(x_piece_array_pointer, 0, x_piece_array_backup, 0, 5);
//If there is one or more, return one at random
if (x_counter_array > 0)
{
g_logmove("Considering between " + Integer.toString(x_counter_array) + " potential piece(s).");
for (x_counter_loop = 1; x_counter_loop <= x_counter_array; x_counter_loop++)
{
x_test_1 = false;
x_test_2 = false;
x_temp_value = x_piece_array_pointer[x_counter_loop];
g_logmove("Step " + Integer.toString(x_counter_loop) + " of " + Integer.toString(x_counter_array) + "..Looking at piece: " + Integer.toString(x_temp_value) + " at location " + Integer.toString(x_player.p_pieces[x_temp_value].m_get_location()));
x_test_1 = x_temp_magic_numbers.contains(x_player.p_pieces[x_temp_value].m_get_location());
if (x_test_1)
{
g_logmove("Considering ignoring piece " + Integer.toString(x_temp_value) + " as it is on a penultimate number.");
}
if ((x_player.p_pieces[x_temp_value].m_get_location() * g_dievalue) > 120)
{
x_test_2 = true;
g_logmove("Considering ignoring piece " + Integer.toString(x_temp_value) + " as it may cause a blowout.");
}
if (x_test_1 || x_test_2)
{
//one of these is a 'good' number we wish to avoid moving randomly, or could cause a blow-out
x_piece_array_backup[x_counter_loop] = 999;
}
}
//find the number of pieces in the backup array
x_counter = 0;
for(x_counter_loop = 1; x_counter_loop <= 4; x_counter_loop++)
{
if (x_piece_array_backup[x_counter_loop] != 999 && x_piece_array_backup[x_counter_loop] > 0)
{
x_counter++;
}
}
//pick a pointer at random from the remainder
if (x_counter == 0)
{
x_temp_value = 0;
g_logmove("Ignored too many...reverting."); //must choose a random from the remaining 'good' pointers
for (x_counter_loop = 1; x_counter_loop <= 4; x_counter_loop++)
{
if (x_piece_array_pointer[x_counter_loop] != 999 && x_piece_array_pointer[x_counter_loop] > 0)
{
x_temp_value++;
}
}
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " has " + Integer.toString(x_temp_value) + " possible piece(s) to move which are on the board.");
x_test_1 = true;
while (x_test_1)
{
x_counter_array = g_return_random(4);
if (x_piece_array_pointer[x_counter_array] > 0 && x_piece_array_pointer[x_counter_array] != 999)
{
x_test_1 = false; //found one to move
}
}
}
else
{ //pick one from the backup array to use
x_temp_value = 0;
for (x_counter_loop = 1; x_counter_loop <= 4; x_counter_loop++)
{
if (x_piece_array_backup[x_counter_loop] != 999 && x_piece_array_backup[x_counter_loop] > 0)
{
x_temp_value++;
}
}
g_logmove("Choosing one from the remaining markers..."); //must choose a random from the remaining 'good' pointers
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " has " + Integer.toString(x_temp_value) + " possible piece(s) to move which are on the board.");
x_test_1 = true;
while (x_test_1)
{
x_counter_array = g_return_random(4);
if (x_piece_array_pointer[x_counter_array] > 0 && x_piece_array_pointer[x_counter_array] != 999)
{
x_test_1 = false; //found one to move
}
}
}
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " has chose to move " + Integer.toString(x_piece_array_pointer[x_counter_array]));
}
else
{
//there were no markers 'on the board'...return an empty pointer;
//this is captured by the calling function and acted upon
return 0;
}
return(x_piece_array_pointer[x_counter_array]);
} //end of function
//core calling function from controlling class
@SuppressWarnings("unused")
public boolean g_player_action(int x_playerid) {
//properties
boolean x_result = false;
String x_test;
String x_temp_return;
int x_temp_magic_numbers[] = { 0, 20, 24, 30, 40, 60, 120 };
int x_temp_factor_numbers[] = { 0, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 25, 50 };
String x_logstring = "";
g_dievalue = g_diceroll();
x_logstring = "[[[Player " + Integer.toString(x_playerid) + " rolled a " + Integer.toString(g_dievalue) + " ]]]";
g_logmove(x_logstring);
if (g_dievalue == 1) {
g_logmove("Player " + Integer.toString(x_playerid) + " has to forfeit their move!");
}
else
{
//SET A
x_result = g_target_magic_numbers(x_playerid, x_temp_magic_numbers, "penultimate",6);
if (x_result)
{
x_temp_return = "TRUE";
}
else {
x_temp_return = "FALSE";
}
x_temp_return = "";
//SET B
if (!x_result)
{
g_logmove("Player " + Integer.toString(x_playerid) + " did not find any penultimate targets.");
x_result = g_target_magic_numbers(x_playerid, x_temp_factor_numbers, "factor", 12);
if (x_result)
{
x_temp_return = "TRUE";
}
else { x_temp_return = "FALSE";
}
x_temp_return = ""; //BUG??
}
//SET C
if (!x_result)
{
//call function C here, return TRUE if it triggers successfully
g_logmove("Player " + Integer.toString(x_playerid) + " did not find any factor targets.");
x_result = g_target_potential_clashes_set_C(g_players[x_playerid]);
if (x_result)
{
x_temp_return = "TRUE";
}
else {
x_temp_return = "FALSE";
}
x_temp_return = "";
}
//SET D
if (!x_result)
{
x_result = g_move_onto_board_set_D(g_players[x_playerid]);
if (x_result)
{
x_temp_return = "TRUE";
}
else {
x_temp_return = "FALSE";
}
x_temp_return = "";
}
}
if (g_gameover)
{
System.out.print("**************************************\n");
System.out.print("*** Player " + Integer.toString(x_playerid) + " HAS WON THE MATCH! ***\n");
System.out.print("**************************************\n");
g_logmove("************************************");
g_logmove("*** Player " + Integer.toString(x_playerid) + " HAS WON THE MATCH! ***");
g_logmove("************************************");
}
return g_gameover;
}
public boolean g_target_magic_numbers(int x_playerid, int x_magicnumbers[], String x_type, int x_magic_count)
{
//properties
int[][] x_forecast_pointers = new int[5][3];
boolean x_found_target = false;
boolean x_test_count_flag = false;
int x_piece_pointer = 0;
int x_counter = 0;
int x_counter_m = 0;
int x_counter_test = 0;
int x_temp_forecast = 0;
//populate current players positions and status to temporary array
for (x_counter = 1; x_counter <= 4; x_counter++)
{
//HERE
if (!g_players[x_playerid].p_pieces[x_counter].m_get_status())
{
//this piece is out of play - set up a dummy which will never get hit
x_forecast_pointers[x_counter][0] = x_counter;
x_forecast_pointers[x_counter][1] = 999;
x_forecast_pointers[x_counter][2] = 0;
}
else
{
//otherwise, put in a forecast of where it would land based on the dice roll
x_forecast_pointers[x_counter][0] = x_counter;
x_forecast_pointers[x_counter][1] = g_players[x_playerid].p_pieces[x_counter].m_get_location() * g_dievalue;
x_forecast_pointers[x_counter][2] = 0;
}
}
//now for each potential location see if there is a match in magic numbers
for (x_counter_m = 1; x_counter_m <= 4; x_counter_m++)
{
x_temp_forecast = x_forecast_pointers[x_counter_m][1];
for (x_counter = 1; x_counter <= x_magic_count; x_counter++) //iterate through magic numbers to see if there is a match
{
if (x_magicnumbers[x_counter] == x_temp_forecast)
{ //found one
x_forecast_pointers[x_counter_m][2] = 1;
x_counter = 999;
}
}
//clear the array of player's pieces that are not a likely hit
x_test_count_flag = false;
for (x_counter_test = 1; x_counter_test <= 4; x_counter_test++)
{
if (x_forecast_pointers[x_counter_test][2] == 1)
{
//found at least one
x_test_count_flag = true;
}
else
{
x_forecast_pointers[x_counter_test][2] = 999;
}
}
//got at least one potential target
if (x_test_count_flag)
{
//now we have an array of only the possible markers to select to target
//loop until we find one that is not 999
while (!x_found_target)
{
x_counter = g_return_random(4);
if (x_forecast_pointers[x_counter][2] != 999)
{
//the piece we choose to move
x_piece_pointer = x_forecast_pointers[x_counter][0];
g_logmove("Player " + Integer.toString(x_playerid) + " is targeting " + x_type + " number " + Integer.toString(x_forecast_pointers[x_counter][1]) + " with piece " + Integer.toString(x_piece_pointer));
g_marker_move(x_playerid, x_piece_pointer);
//here??
x_found_target = true;
}
}
}
else
{
x_found_target = false;
}
} //END OF SET B
return x_found_target;
}
public boolean g_target_potential_clashes_set_C(Player x_player) {
//properties
int[][] x_forecast_pointers = new int[5][3];
boolean x_found_target = false;
boolean x_test_count_flag = false;
int x_piece_pointer = 0;
int x_temp_branch = 2;
int x_counter = 0;
int x_counter_o = 0;
int x_counter_p = 0;
int x_counter_test = 0;
int x_temp_opp_location = 0;
Player x_temp_opp = g_return_other_player();
boolean x_offboard_flag = false;
boolean x_onboard_flag = false;
//populate current players positions and status to temporary array
for (x_counter = 1; x_counter <= 4; x_counter++)
{
if (!x_player.p_pieces[x_counter].m_get_status())
{
//this piece is out of play - set up a dummy which will never get hit
x_forecast_pointers[x_counter][0] = x_counter;
x_forecast_pointers[x_counter][1] = 999;
x_forecast_pointers[x_counter][2] = 0;
}
else
{
//otherwise, put in a forecast of where it would land based on the dice roll
x_forecast_pointers[x_counter][0] = x_counter;
x_forecast_pointers[x_counter][1] = x_player.p_pieces[x_counter].m_get_location() * g_dievalue;
x_forecast_pointers[x_counter][2] = 0;
}
}
//now for each potential location see if there is a match in the opponent's pieces
for (x_counter_o = 1; x_counter_o <= 4; x_counter_o++)
{
if (!x_temp_opp.p_pieces[x_counter_o].m_get_status())
{
//opp position is out of play and should be ignored - dummy value
g_logmove("Ignoring target piece " + Integer.toString(x_counter_o) + " as it is out of play.");
x_temp_opp_location = 888;
}
else
{
//hold the location of a potential target piece to hit
x_temp_opp_location = x_temp_opp.p_pieces[x_counter_o].m_get_location();
}
for (x_counter_p = 1; x_counter_p <= 4; x_counter_p++)
{
//check that the locations match and that the opponents piece is not at the start, or inactive:
if (x_forecast_pointers[x_counter_p][1] == x_temp_opp_location && x_temp_opp_location != 1 && x_temp_opp_location != 888)
{
//we have a potential target
x_forecast_pointers[x_counter_p][2] = 1;
g_logmove("Player " + Integer.toString(x_temp_opp.p_get_playerid()) + "'s marker " + Integer.toString(x_counter_o) + " at location " + Integer.toString(x_temp_opp.p_pieces[x_counter_o].m_get_location()) + " is a target of piece " + Integer.toString(x_counter_p));
//don't even know if this works in c++
break; //we only need to know this once
}
} //move on to next player piece
} //move on to next opponent piece
//clear the array of player's pieces that are not a likely hit
x_test_count_flag = false;
for (x_counter_test = 1; x_counter_test <= 4; x_counter_test++)
{
if (x_forecast_pointers[x_counter_test][2] == 1)
{
//found at least one
x_test_count_flag = true;
}
else
{
x_forecast_pointers[x_counter_test][0] = 999;
}
}
//got at least one potential target
if (x_test_count_flag)
{
x_counter = 0;
while (!x_found_target)
{
x_counter = g_return_random(4);
if (x_forecast_pointers[x_counter][0] != 999)
{
x_piece_pointer = x_forecast_pointers[x_counter][0];
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " has targets to consider and chose to move piece " + Integer.toString(x_piece_pointer));
g_marker_move(x_player.p_get_playerid(), x_piece_pointer);
x_found_target = true;
return x_found_target;
}
}
}
else
{
g_logmove("Player " + Integer.toString(x_player.p_get_playerid()) + " could not find a clash target so is going to find a pointer at random to move.");
//toss up between on or off board
x_offboard_flag = false;
x_onboard_flag = false;
for (x_counter = 1; x_counter <= 4; x_counter++)
{
//loop and see if there is a mix of on-board or off-board marker; do a coin toss if there is
if (x_player.p_pieces[x_counter].m_get_location() == 1 && x_player.p_pieces[x_counter].m_get_status())
{
x_offboard_flag = true; //we could get a piece off the board
}
if (x_player.p_pieces[x_counter].m_get_location() > 1 && x_player.p_pieces[x_counter].m_get_status())
{
x_onboard_flag = true; // we could get a piece on the board
}
}
if (x_onboard_flag)
{
if (x_offboard_flag)
{
//choice is a wonderful thing - 1 is on-board, 2 is off-board
x_temp_branch = g_return_random(2);
}
else
x_temp_branch = 1;
}
if (x_temp_branch == 1)
{
x_piece_pointer = 0;
g_logmove("Finding a piece on the board.");
x_piece_pointer = g_find_to_move_in_play(x_player);
if (x_piece_pointer != 0)
{
//found one... move it
g_marker_move(x_player.p_get_playerid(), x_piece_pointer);