-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.c
1877 lines (1768 loc) · 35.2 KB
/
ai.c
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
////////////////////////////////////////
//
// File : ai.c
// CoSpace Robot
// Version 1.0.0
// Jan 1 2016
// Copyright (C) 2016 CoSpace Robot. All Rights Reserved
//
//////////////////////////////////////
//
// ONLY C Code can be compiled.
//
/////////////////////////////////////
#define CsBot_AI_H//DO NOT delete this line
#ifndef CSBOT_REAL
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define DLL_EXPORT extern __declspec(dllexport)
#define false 0
#define true 1
#endif//The robot ID : It must be two char, such as '00','kl' or 'Cr'.
char AI_MyID[2] = { '0','2' };
#define Yellow 1
#define Red 2
#define Blue 3
#define Green 4
#define Cyan 5
#define Gray 6
#define trapblue 7
#define Orange 8
#define White 9
#define pBlue 10
#define superobj 11
#define Yellow2 12
#define Orange2 13
//a
int AI_SensorNum = 13;
int afterdeposit = 0;
int antilit = 0;
//b
int borojlo = 0;
int bGameEnd = false;
//c
int watchdogs = 0;
int CurAction = -1;
int CurGame = 0;
int CSLeft_R = 0;
int CSLeft_G = 0;
int CSLeft_B = 0;
int CSRight_R = 0;
int CSRight_G = 0;
int CSRight_B = 0;
int Compass = 0;
int cyanobj = 0;
int colorcount = 0;
clock_t t;
int checkblockzone = 0;
//d
int Duration = 0;
//e
//f
int i2 = 0;
//g
int greenobj = 0;
//h
int shartenadidanobsacle = 0;
//i
//j
int j = 100;
//k
int kodumdarimirim = 0;
//l
int ltime = 0;
int LoadedObjects = 0;
int LED_1 = 0;
int Left = 0;
int level = 3;
int gotosuper[100];
//m
int mapx = 350;
int mapy = 260;
int maxbox = 19;
int MyState = 0;
int mame = 0;
//n
//o
int orangexy[2][2] = { { 47,23 },{ 346,241 } };
int obs = 0;
//p
int PositionX = 0;
int PositionY = 0;
int positionx = 0;
int positiony = 0;
//q
//r
int redobj = 0;
int Right = 0;
int Range = 10;
//s
int Speed = 0;
int shartnadidanobsacle = 0;
int superobject = 0;
int superobject1 = 0;
int SuperObj1_flag = 0;
int SuperDuration = 0;
int SuperObj_Num = 0;
int SuperObj_X = 0;
int SuperObj_Y = 0;
int SuperObj_X1 = 0;
int SuperObj_Y1 = 0;
//t
int TimeTrap = 0;
int tedadesuper = 0;
int tafrishi2 = 100;
int supere1barmasraf = 0;
int Teleport = 0;
int TM_State = 0;
int Time = 0;
int time2 = 0;
int time3 = 0;
int type = 2;
static int time1 = 0;
time_t timezone;
double timezone1 = 0;
//u
int usimbolt = 0;
int masircount =16 ;
int unloadw2[100][4] = { { 180, 212, 1, -1 },{ 181, 254, 2, 0 },{ 116, 249, -1, 1 },{ 182, 213, 4, -1 },{ 190, 252, 5, 3 },{ 298, 242, 6, 4 },{ 345, 159, 7, 5 },{ 335, 96, 8, 6 },{ 245, 101, 9, 7 },{ 153, 80, -1, 8 },{ 184, 211, 11, -1 },{ 191, 250, 12, 10 },{ 309, 237, 13, 11 },{ 350, 148, 14, 12 },{ 327, 63, 15, 13 },{ 253, 44, -1, 14 } };
int MAX = 37;
int khat[1000][4] = { { 148,230,157,230, },{ 158,231,158,186, },{ 149,187,158,187, },{ 149,187,148,229, },{ 250,156,198,156, },{ 199,156,199,116, },{ 198,117,86,115, },{ 86,115,87,105, },{ 87,104,209,105, },{ 209,103,210,146, },{ 210,146,250,145, },{ 250,147,248,127, },{ 250,125,276,126, },{ 277,128,279,157, },{ 280,156,309,156, },{ 309,156,309,114, },{ 309,114,322,115, },{ 322,115,322,156, },{ 322,156,309,158, },{ 309,158,309,186, },{ 309,186,278,186, },{ 277,187,279,157, },{ 278,157,251,156, },{ 311,81,268,81, },{ 268,81,269,70, },{ 269,70,312,69, },{ 312,68,312,80, },{ 209,70,198,71, },{ 198,70,198,39, },{ 197,40,159,40, },{ 158,39,159,28, },{ 159,27,210,26, },{ 210,27,210,69, },{ 87,105,60,104, },{ 60,103,60,74, },{ 60,74,89,71, },{ 89,73,89,103 } };
//int unloadw2[100][4] = { { 10000,10000,-1,1 },{ 98,95,2,-1 },{ 137,74,3,1 },{ 141,50,4,2 },{ 161,29,5,3 },{ 144,8,6,4 },{ 14,20,7,5 },{ 47,57,8,6 },{ 15,90,9,7 },{ 99,167,10,8 },{ 256,26,11,9 },{ 346,115,12,10 },{ 249,153,13,11 },{ 85,236,-1,12 }};
int US_Front = 0;
int US_Left = 0;
int US_Right = 0;
//w
int WheelLeft = 0;
int WheelRight = 0;
int WheelSum = 0;
//x
int SuperObj_X2 = 0;
int SuperObj_Y2 = 0;
//y
int yy = 0;
//z
float zz = 0;
#define CsBot_AI_C
DLL_EXPORT void SetGameID(int GameID)
{
CurGame = GameID;
bGameEnd = 0;
}
DLL_EXPORT int GetGameID()
{
return CurGame;
}
DLL_EXPORT int IsGameEnd()
{
return bGameEnd;
}
#ifndef CSBOT_REAL
DLL_EXPORT char* GetDebugInfo()
{
char info[1024];
sprintf(info, "Duration=%d;SuperDuration=%d;bGameEnd=%d;CurAction=%d;CurGame=%d;SuperObj_Num=%d;SuperObj_X=%d;SuperObj_Y=%d;Teleport=%d;LoadedObjects=%d;US_Front=%d;US_Left=%d;US_Right=%d;CSLeft_R=%d;CSLeft_G=%d;CSLeft_B=%d;CSRight_R=%d;CSRight_G=%d;CSRight_B=%d;PositionX=%d;PositionY=%d;TM_State=%d;Compass=%d;Time=%d;WheelLeft=%d;WheelRight=%d;LED_1=%d;MyState=%d;", Duration, SuperDuration, bGameEnd, CurAction, CurGame, SuperObj_Num, SuperObj_X, SuperObj_Y, Teleport, LoadedObjects, US_Front, US_Left, US_Right, CSLeft_R, CSLeft_G, CSLeft_B, CSRight_R, CSRight_G, CSRight_B, PositionX, PositionY, TM_State, Compass, Time, WheelLeft, WheelRight, LED_1, MyState);
return info;
}
DLL_EXPORT char* GetTeamName()
{
return " Salam Zeynoddin";
}
DLL_EXPORT int GetCurAction()
{
return CurAction;
}
//Only Used by CsBot Rescue Platform
DLL_EXPORT int GetTeleport()
{
return Teleport;
}
//Only Used by CsBot Rescue Platform
DLL_EXPORT void SetSuperObj(int X, int Y, int num)
{
SuperObj_X = X;
SuperObj_Y = Y;
SuperObj_Num = num;
}
//Only Used by CsBot Rescue Platform
DLL_EXPORT void GetSuperObj(int *X, int *Y, int *num)
{
*X = SuperObj_X;
*Y = SuperObj_Y;
*num = SuperObj_Num;
}
#endif
DLL_EXPORT void SetDataAI(volatile int* packet, volatile int *AI_IN)
{
int sum = 0;
US_Front = AI_IN[0]; packet[0] = US_Front; sum += US_Front;
US_Left = AI_IN[1]; packet[1] = US_Left; sum += US_Left;
US_Right = AI_IN[2]; packet[2] = US_Right; sum += US_Right;
CSLeft_R = AI_IN[3]; packet[3] = CSLeft_R; sum += CSLeft_R;
CSLeft_G = AI_IN[4]; packet[4] = CSLeft_G; sum += CSLeft_G;
CSLeft_B = AI_IN[5]; packet[5] = CSLeft_B; sum += CSLeft_B;
CSRight_R = AI_IN[6]; packet[6] = CSRight_R; sum += CSRight_R;
CSRight_G = AI_IN[7]; packet[7] = CSRight_G; sum += CSRight_G;
CSRight_B = AI_IN[8]; packet[8] = CSRight_B; sum += CSRight_B;
PositionX = AI_IN[9]; packet[9] = PositionX; sum += PositionX;
PositionY = AI_IN[10]; packet[10] = PositionY; sum += PositionY;
TM_State = AI_IN[11]; packet[11] = TM_State; sum += TM_State;
Compass = AI_IN[12]; packet[12] = Compass; sum += Compass;
Time = AI_IN[13]; packet[13] = Time; sum += Time;
packet[14] = sum;
}
DLL_EXPORT void GetCommand(int *AI_OUT)
{
AI_OUT[0] = WheelLeft;
AI_OUT[1] = WheelRight;
AI_OUT[2] = LED_1;
AI_OUT[3] = MyState;
}
boolean CheckL(int LR, int HR, int LG, int HG, int LB, int HB)
{
if (LR <= CSLeft_R && CSLeft_R <= HR && LG <= CSLeft_G && CSLeft_G <= HG && LB <= CSLeft_B && CSLeft_B <= HB)
{
return true;
}
return false;
}
boolean CheckR(int LR, int HR, int LG, int HG, int LB, int HB)
{
if (LR <= CSRight_R && CSRight_R <= HR && LG <= CSRight_G && CSRight_G <= HG && LB <= CSRight_B && CSRight_B <= HB)
{
return true;
}
return false;
}
float distance(int x1, int y1)
{
float dis = sqrt(((y1 - PositionY)*(y1 - PositionY)) + ((x1 - PositionX)*(x1 - PositionX)));
return dis;
}
float distance2(int x1, int y1)
{
float dis = sqrt(((y1 - SuperObj_Y1)*(y1 - SuperObj_Y1)) + ((x1 - SuperObj_X1)*(x1 - SuperObj_X1)));
return dis;
}
int intcorrecter(int a)
{
if (a > 360) {
a = a - 360;
}
if (a < 0) {
a = a + 360;
}
return a;
}
float floatcorrecter(float a)
{
if (a > 360) {
a = a - 360;
}
if (a < 0) {
a = a + 360;
}
return a;
}
double doublecorrecter(double a)
{
if (a > 360)
{
a = a - 360;
}
if (a < 0)
{
a = a + 360;
}
return a;
}
void Colorcheck() {
Left = 0;
Right = 0;
if (CheckL(204, 235, 217, 248, 0, 0)) {
Left = Yellow;
}
if (CheckR(204, 235, 217, 248, 0, 0)) {
Right = Yellow;
}
if (CheckL(204, 235, 217, 248, 0, 0)) {
Left = Yellow2;
}
if (CheckR(204, 235, 217, 248, 0, 0)) {
Right = Yellow2;
}
if (CheckL(232, 255, 29, 39, 29, 39)) {
Left = Red;
}
if (CheckR(232, 255, 29, 39, 29, 39)) {
Right = Red;
}
if (CheckL(0, 10, 0, 20, 0, 30)) {
Left = Blue;
}
if (CheckR(0, 10, 0, 20, 0, 30)) {
Right = Blue;
}
if (CheckL(29, 39, 249, 255, 255, 255)) {
Left = Green;
}
if (CheckR(29, 39, 249, 255, 255, 255)) {
Right = Green;
}
if (CheckL(29, 39, 29, 39, 29, 39)) {
Left = Cyan;
}
if (CheckR(29, 39, 29, 39, 29, 39)) {
Right = Cyan;
}
if (CheckL(133, 153, 141, 161, 187, 207)) {
Left = Gray;
}
if (CheckR(133, 153, 141, 161, 187, 207)) {
Right = Gray;
}
if (CheckL(54, 62, 97, 111, 221, 245)) {
Left = trapblue;
}
if (CheckR(54, 62, 97, 111, 221, 245)) {
Right = trapblue;
}
if (CheckL(54, 62, 97, 111, 221, 245)) {
Left = pBlue;
colorcount++;
}
if (CheckR(54, 62, 97, 111, 221, 245)) {
Right = pBlue;
colorcount++;
}
if (CheckL(194, 240, 153, 190, 0, 0)) {
Left = Orange;
}
if (CheckR(194, 240, 153, 190, 0, 0)) {
Right = Orange;
}
if (CheckL(194, 240, 153, 190, 0, 0)) {
Left = Orange2;
}
if (CheckR(194, 240, 153, 190, 0, 0)) {
Right = Orange2;
}
if (CheckL(190, 217, 184, 205, 185, 189)) {
Left = White;
}
if (CheckR(190, 217, 184, 205, 185, 189)) {
Right = White;
}
if (CheckL(232, 255, 30, 40, 254, 255)) {
Left = superobj;
}
if (CheckR(232, 255, 30, 40, 254, 255)) {
Right = superobj;
}
}
boolean Intersects(int P1X, int P1Y, int P2X, int P2Y, int p3X, int p3Y, int p4X, int p4Y)
{
boolean lines_intersect;
boolean segments_intersect;
float dx12 = P2X - P1X;
float dy12 = P2Y - P1Y;
float dx34 = p4X - p3X;
float dy34 = p4Y - p3Y;
float denominator = (dy12 * dx34 - dx12 * dy34);
float t1 = 0;
float t2 = 0;
if (denominator == 0)
{
lines_intersect = false;
segments_intersect = false;
// intersection = new PointF(float.NaN, float.NaN);
// close_p1 = new PointF(float.NaN, float.NaN);
// close_p2 = new PointF(float.NaN, float.NaN);
return false;
}
else
{
t1 = ((P1X - p3X) * dy34 + (p3Y - P1Y) * dx34) / denominator;
}
lines_intersect = true;
t2 = ((p3X - P1X) * dy12 + (P1Y - p3Y) * dx12) / -denominator;
// intersection = new PointF(P1.X + dx12 * t1, P1.Y + dy12 * t1);
segments_intersect = ((t1 > 0) && (t1 < 1) && (t2 > 0) && (t2 < 1));
// if (t1 < 0)
// {
// t1 = 0;
// }
// else if (t1 > 1)
// {
// t1 = 1;
// }
// if (t2 < 0)
// {
// t2 = 0;
// }
// else if (t2 > 1)
// {
// t2 = 1;
// }
// close_p1 = new PointF(P1.X + dx12 * t1, P1.Y + dy12 * t1);
// close_p2 = new PointF(p3.X + dx34 * t2, p3.Y + dy34 * t2);
// return segments_intersect ? (float)(Math.Sqrt(Math.Pow(p3.X - intersection.X, 2) + Math.Pow(p3.Y - intersection.Y, 2))) : -1;
return segments_intersect ? true : false;
}
boolean isViewable(int x, int y)
{
int i = 0;
for (i = 0; i < MAX; i++)
{
if (Intersects(PositionX, PositionY, x, y, khat[i][0], khat[i][1], khat[i][2], khat[i][3]))
return false;
}
return true;
}
boolean isViewable2(int x, int y, int x2, int y2)
{
int i = 0;
for (i = 0; i < MAX; i++)
{
if (Intersects(x2, y2, x, y, khat[i][0], khat[i][1], khat[i][2], khat[i][3]))
return false;
}
return true;
}
void execute(int left, int right, int led, int duration);
boolean stayincolor(int color, int durat)
{
time3++;
if (durat > time3)
{
if (Left == color || Right == color)
{
if (Left == color)
{
if (Right != color)
{
execute(-1, 3, 0, 0);
return true;
}
}
if (Right == color)
{
if (Left != color)
{
execute(3, -1, 0, 0);
return true;
}
}
}
if (colorcount > 0)
{
if (Right != color && Left != color)
{
execute(-5, 5, 0, 0);
return true;
}
}
}
if (time3 > durat)
{
time3 = 0;
}
return false;
}
int zaviebeinmavaoon(int x, int y)
{
double darajebeinemavaoon = (((atan((double)(y - PositionY) / (x - PositionX))) * 180) / 3.1415);
doublecorrecter(darajebeinemavaoon);
return (int)darajebeinemavaoon;
}
int converttocompass(int darajebeinemavaoon, int x, int y)
{
if ((x - PositionX >= 0) && (y - PositionY >= 0))
{
darajebeinemavaoon = darajebeinemavaoon + 270;
}
if ((x - PositionX < 0) && (y - PositionY >= 0))
{
darajebeinemavaoon = darajebeinemavaoon - 270;
}
if ((x - PositionX >= 0) && (y - PositionY < 0))
{
darajebeinemavaoon = darajebeinemavaoon - 90;
}
if ((x - PositionX < 0) && (y - PositionY < 0))
{
darajebeinemavaoon = darajebeinemavaoon + 90;
}
return darajebeinemavaoon;
}
boolean gotoxymanage(int darajebeinemavaoon, int x, int y, int led, int duration2)
{
shartnadidanobsacle = 0;
if ((abs(PositionX - x) < 5) && (abs(PositionY - y) < 5))
{
//execute(0, 0, led, duration2);
time3 = 0;
if (kodumdarimirim == 4)
{
j = unloadw2[j][3];
}
if (kodumdarimirim == 3)
{
printf("avazshod = %d\n", tedadesuper - 1);
tedadesuper = tedadesuper - 1;
}
if (kodumdarimirim == 2)
{
printf("-----------------------residim be super\n");
execute(0, 0, 1, 50);
SuperObj1_flag = 0;
shartenadidanobsacle = 90;
SuperObj_X1 = 0;
SuperObj_Y1 = 0;
}
// printf("changed j= %d\n", j);
//if (SuperObj1_flag == 1) {
// SuperObj_X1 = 0;
// SuperObj_Y1 = 0;
//}
return true;
}
else
{
if (darajebeinemavaoon > 0)
{
superobject1 = superobject;
}
int min = darajebeinemavaoon - 15;
int max = darajebeinemavaoon + 15;
int arcom = darajebeinemavaoon - Compass;
min = intcorrecter(min);//ablah jolosh bayad benevisi ,return faghat meghdar mide
max = intcorrecter(max);
arcom = intcorrecter(arcom);
if ((arcom) > 180)
{
execute(1, -1, 0, 0);
if (max > min)
{
if ((min < Compass) && (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
if (max<min)
{
if ((Compass>min) || (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
return true;
}
if ((arcom) < -180)
{
execute(-1, 1, 0, 0);
if (max > min)
{
if ((min < Compass) && (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
if (max<min)
{
if ((Compass>min) || (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
return true;
}
if (0 < (arcom) && (arcom) < 180)
{
execute(-1, 1, 0, 0);
if (max > min) {
if ((min < Compass) && (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
if (max<min)
{
if ((Compass>min) || (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
return true;
}
if (0 >(arcom) && (arcom)>-180)
{
execute(1, -1, 0, 0);
if (max > min) {
if ((min < Compass) && (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
if (max<min) {
if ((Compass>min) || (Compass < max))
{
if (superobject1 == superobject)
{
execute(3, 3, 0, 0);
return true;
}
}
}
return true;
}
}
return false;
}
void gotoxy(int x, int y, int led, int duration2)
{
int darajebeinemavaoon2 = zaviebeinmavaoon(x, y);
int compassbeinemavaoon = converttocompass(darajebeinemavaoon2, x, y);
printf("x=%d\t", x);
printf("y=%d\t", y);
shartenadidanobsacle = 13;
gotoxymanage(compassbeinemavaoon, x, y, led, duration2);
time2 = 0;
}
boolean cmp(int bo, int dur)
{
int wcmp = 0;
wcmp = bo - Compass;
wcmp = intcorrecter(wcmp);
int min = wcmp - 10;
int max = wcmp + 10;
min = intcorrecter(min);
max = intcorrecter(max);
if (min < max)
{
if (min < Compass && Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (wcmp < 180)
{
if (wcmp > 0 && wcmp < 45)
{
execute(-1, 1, 0, 0);
return true;
}
if (wcmp > 45 && wcmp < 90)
{
execute(-2, 1, 0, 0);
return true;
}
}
else
{
execute(1, -1, 0, 0);
return true;
}
}
else
{
if (min < Compass || Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (wcmp < 180)
{
execute(-1, 1, 0, 0);
return true;
}
else
{
execute(1, -1, 0, 0);
return true;
}
}
return false;
}
boolean TrapCheck()
{
if (Left == Yellow || Left == Yellow2)
{
printf("leftyellow\n");
execute(3, -4, 0, 0);
return true;
}
if (Right == Yellow || Right == Yellow2)
{
printf("rightyellow\n");
execute(-4, 3, 0, 0);
return true;
}
if ((Left == Yellow && Right == Yellow) || (Left == Yellow2 && Right == Yellow2)|| (Left == Yellow && Right == Yellow2)|| (Left == Yellow2 && Right == Yellow))
{
printf("everywhere yellow\n");
execute(-3, -5, 0, 2);
return true;
}
return false;
}
boolean tto(int deg)
{
int baze = 15;
int min = deg - baze;
int max = deg + baze;
int arcom = deg - Compass;
min = intcorrecter(min);//ablah jolosh bayad benevisi ,return faghat meghdar mide
max = intcorrecter(max);
arcom = intcorrecter(arcom);
if (min < max)
{
//printf("normal\n");
if (min < Compass && Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (arcom < 180)
{
// printf("normal <\n");
execute(-1, 1, 0, 0);
return false;
}
else
{
// printf("normal >\n");
execute(1, -1, 0, 0);
return false;
}
}
else
{
// printf("UUUnoraml\n");
if (min < Compass || Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (arcom < 180)
{
// printf("UUUnoraml <\n");
execute(-1, 1, 0, 0);
return false;
}
else
{
// printf("UUUnoraml >\n");
execute(1, -1, 0, 0);
return false;
}
}
}
boolean tto2(int deg)
{
int baze = 15;
int min = deg - baze;
int max = deg + baze;
int arcom = deg - Compass;
min = intcorrecter(min);//ablah jolosh bayad benevisi ,return faghat meghdar mide
max = intcorrecter(max);
arcom = intcorrecter(arcom);
if (min < max)
{
if (min < Compass && Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (arcom < 180)
{
zz = (float)arcom / 45;
//printf("zz1=%f\n", zz);
if (zz < 4 && zz >= 3)
{
execute(-4, 4, 0, 0);
return false;
}
if (zz < 3 && zz >= 2)
{
execute(-3, 3, 0, 0);
return false;
}
if (zz < 2 && zz >= 1)
{
execute(-2, 2, 0, 0);
return false;
}
if (zz < 1 && zz >= 0)
{
execute(-1, 1, 0, 0);
return false;
}
}
else
{
zz = (float)arcom / 45;
// printf("zz2=%f\n", zz);
if (zz < 8 && zz >= 7)
{
execute(-1, 1, 0, 0);
return false;
}
if (zz < 7 && zz >= 6)
{
execute(-2, 2, 0, 0);
return false;
}
if (zz < 6 && zz >= 5)
{
execute(-3, 3, 0, 0);
return false;
}
if (zz < 5 && zz >= 4)
{
execute(-4, 4, 0, 0);
return false;
}
}
}
else
{
if (min < Compass || Compass < max)
{
execute(3, 3, 0, 0);
return true;
}
else if (arcom < 180)
{
zz = (float)arcom / 45;
// printf("zz3=%f\n", zz);
if (zz < 4 && zz >= 3)
{
execute(-4, 4, 0, 0);
return false;
}
if (zz < 3 && zz >= 2)
{
execute(-3, 3, 0, 0);
return false;
}
if (zz < 2 && zz >= 1)
{
execute(-2, 2, 0, 0);
return false;
}
if (zz < 1 && zz >= 0)
{
execute(-1, 1, 0, 0);
return false;
}
}
else
{
zz = (float)arcom / 45;
// printf("zz4=%f\n", zz);
if (zz < 8 && zz >= 7)
{
execute(-4, 4, 0, 0);
return false;
}
if (zz < 7 && zz >= 6)
{
execute(-3, 3, 0, 0);
return false;
}
if (zz < 6 && zz >= 5)
{
execute(-2, 2, 0, 0);
return false;
}
if (zz < 5 && zz >= 4)
{
execute(-1, 1, 0, 0);
return false;
}
}
}
}
void teleport(int timez)
{
if (Time > timez)
{
Teleport = 2;
greenobj = 0;
redobj = 0;
cyanobj = 0;
}
}
void execute(int left, int right, int led, int duration)
{
LED_1 = led;
Duration = duration;
if (checkblockzone == 1)
{
if (left == right)
{
if (left > 0)
{
WheelLeft = 3;
WheelRight = 3;
}
if (left < 0)