You are on page 1of 91

////////////////////////////////////////

//
// 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 <string.h>
#include <stdlib.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 CsBot_AI_C//DO NOT delete this line


#define MAX_TIME 2000
#define MAX_OBJECT 6
#define MAX_RED 2
#define MAX_GREEN 2
#define MAX_BLACK 2
#define MAX_OBJECT1 6
#define DPSPAN 30
#define ObjsREnough 6
#define DepositDanceTime 1200
#define ANSI_COLOR_RED ""
#define ANSI_COLOR_GREEN ""
#define ANSI_COLOR_YELLOW ""
#define ANSI_COLOR_BLUE ""
#define ANSI_COLOR_MAGENTA ""
#define ANSI_COLOR_CYAN ""
#define ANSI_COLOR_RESET ""
#define MAX_WALL 22
#define MIN_WALL 18
#define four 22
#define five 30

//Area
#define bO 0
#define rO 1
#define gO 2
#define n 6
//FUNCTIONS
boolean rast();
boolean chap();
boolean TrapsArea();
boolean IGNOREDAREAS();
boolean SlowdownCondition();
boolean Move1();
boolean CompleteTurn();
boolean CHANGEFOLLOWDIR();
boolean WALLFOLLOWCONDITION();
boolean BorderField1();
boolean TrapField1();
boolean DepositBoxField1();
boolean FollowingDepositBox();
boolean DepositDance();
boolean ObstacleField1();
boolean RedObj1();
boolean GreenObj1();
boolean BlackObj1();
boolean FullObj();
boolean NotFullObj();
boolean OBJECTISNOTFULL1();
boolean DepositPossible1();
boolean CheckDepo1();
boolean bothSensorDepoBoxField1();
boolean oneSensorDepoBoxField1();
boolean DepoBoxDetected1();
boolean StopAndCheck1();
boolean DP(int dpstate, int direction, int nextifwall, int nextifborder, int
nextiftrap, int Timer, int nextiftimer);
boolean FiveObjects();
boolean Move2();
boolean BorderField2();
boolean TrapField2();
boolean DepositBoxField2();
boolean ObstacleField2();
boolean RedObj2();
boolean GreenObj2();
boolean BlackObj2();
boolean SuperObj();
boolean isViewable4(int xme, int yme, int x, int y);
boolean GOTO(int XGoal, int YGoal, char purpose);
boolean REACH(int XGoal, int YGoal);
boolean TURNTO(int angle);
boolean DEPOSITPOSSIBLE();
boolean BIKHIALCONDITION();
boolean DETECTSOBJ();
boolean TurnLeftKam();
boolean TurnRightKam();
boolean BlackGoal();
boolean CompassSpan();
boolean isViewable(int x, int y);
boolean Intersects(int P1X, int P1Y, int P2X, int P2Y, int p3X, int p3Y, int p4X,
int p4Y);
boolean SearchSobj();
boolean CheckDepo();
boolean bothSensorDepoBoxField2();
boolean oneSensorDepoBoxField2();
boolean DepoBoxDetected();
boolean StopAndCheck();
boolean FIRSTAREA();
boolean isNEAR(int x, int y, int p);
boolean AreasFlag();
boolean RedArea();
boolean GreenkArea();
boolean BlackArea();
boolean LASTPOS();
boolean Sobj();
boolean SignalBlockZone();
boolean DontLeaveArea(int minx, int maxx, int miny, int maxy);
boolean TurnLeft();
boolean OneSet();
boolean MoveBackward();
boolean CompassGoal();
boolean OBJECTISNOTFULL();
boolean ACTION(int l, int r, int led, int duration);
boolean NormalState();
boolean NormalState2();
boolean CollectObjStateFiield1();
boolean FullObjStateField1();
boolean FrwState();
boolean TurnLeft();
boolean CollectObjStateField2();
boolean FullObjStateField2();
boolean ChangeState();
boolean ObstacleState();
boolean Counter();
boolean Areas();
boolean WallTurn();
boolean stend();
boolean AreaSearch();
boolean csearch(int x, int y);
boolean ZigZagSearch();
boolean CircleSearch();
boolean Area();
boolean StayInColoredAreas(char);
boolean zigzag(int nunmber, int x1, int x2, int y1, int y2);
boolean SobjPosition();
int NearestArea();
int CALCULATEANGLE(int YGoalx, int XGoal);
int WARNING();
int SUPEROBJECTCONDITION();
int ENDPOINT(int p);
void AreaObj();
void AreasPosition();
void MantagheAbiVasatTale();
void Colour();
void CalculateSpeed();
void CalculatePath();
void Restricted();
void NoSignal();
void Zero();
void StartTime();
void StopTime();
void DEPOSITCONDITION();
void SwampLand();
//void Restricted();
//void NoSignal();
void positions();
void LastObj();
void teleport();
void DepositDanceTurning();
void RecognizingSpecialZone();

//MOTEQAYERS
int StateFlag = 0;
int Duration = 0;
int SuperDuration = 0;
int bGameEnd = false;
int CurAction = -1;
int CurGame = 0;
int SuperObj_Num = 0;
int SuperObj_X = 0;
int SuperObj_Y = 0;
int Teleport = 0;
int LoadedObjects = 0;
int US_Front = 0;
int US_Left = 0;
int US_Right = 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 PositionX = 0;
int PositionY = 0;
int TM_State = 0;
int Compass = 0;
int Time = 0;
int WheelLeft = 0;
int WheelRight = 0;
int LED_1 = 0;
int MyState = 0;
int AI_SensorNum = 13;
int ObjCounter = 0;
int bati = 0;
int SwampFlag = 0;
int SuperObjCounter = 0;
int BlackObjCounter1 = 0;
int GreenObjCounter1 = 0;
int RedObjCounter1 = 0;
int BlackObjCounter2 = 0;
int GreenObjCounter2 = 0;
int RedObjCounter2 = 0;
int TeleportAfterDeposit = 0;
int comin = 0;
int comax = 0;
boolean biaaghab = 0;
int comin2 = 0;
int comax2 = 0;
int WheelLeftCompass;
int wheel_right_compass;
int CompassIdeal = 2000;
int CompassBorder = 2000;
int disminex = 0;
int SwampSpeed = 1;
int depositdancetimer = 0;
int sobjpurpose = 0;
int PATHSELECTED = 0;
int FIRSTPOINT = 0;
int bordercounter = 0;
int data[100][3];
int datacounter = 0;
int validdata = 0;
int ATFIRST = 0;
int POSITIONFLAG = 0;
int IGNOREDAREASFLAG = 0;
int FIRSTX = 0;
int FIRSTY = 0;
int DepositBoxPurpose = 0;
int BIKHIALTIMER = 0;
int XGOAL = 0;
int YGOAL = 0;
int LXGOAL = 0;
int LYGOAL = 0;
int WELLTIMER = 0;
int RestrictedFlag = 0;
int RestrictedFlag3 = 0;
int LastPositionX = 0;
int LastPositionY = 0;
int LastPositionX1st = 0;
int LastPositionY1st = 0;
int LastPositionX2nd = 0;
int LastPositionY2nd = 0;
int PositionFluxionX = 0;
int PositionFluxionY = 0;
int Positionx = 0;
int Positiony = 0;
int WheelCompass = 0;
int trapcounter = 0;
int field = 0;
int MaxTimeDp = 0;
int Cmpideal = -1;
int dpflag = 0;
int dds = 1;
int RPOSX = 0;
int RPOSY = 0;
int LASTPOSX = 0;
int LASTPOSY = 0;
int TeleportAfterDepositFlag = 0;
int TOLERANCE = 0;
int ObjFlag = 0;
int LASTTIMEFLAG = 0;
int LASTTIME = 0;
int LASTPOSITION_X = 0;
int LASTPOSITION_Y = 0;
int CollectSobj = 0;
int GreenAreaCounter = 0;
int RedAreaCounter = 0;
int BlackAreaCounter = 0;
int BlackAreaTime = 0;
int GreenAreaTime = 0;
int RedAreaTime = 0;
int GreenFlag = 0;
int BlackFlag = 0;
int RedFlag = 0;
int FirstFlag = 0;
double dismin = 0;
double Side1 = 0;
double Side2 = 0;
double Side3 = 0;
double XGoal = 0;
double YGoal = 0;
double alpha = 0;
double Beta = 0;
double XSide = 0; //Nosignal
double YSide = 0; //NoSignal
float PositionFluxion = 0;
float Path = 0;
float TimeFluxion = 0;
float v = 0; //soraat
clock_t T1st = 0;
clock_t T2nd = 0;
clock_t T3rd = 0;
clock_t GameTime = 0;
clock_t GameTime1 = 0;
clock_t LGameTime = 0;
clock_t Start = 0;
clock_t Stop = 0;
clock_t WasteTime = 0;
int DPFLAGII = 0;
int counter_follow = 0;
int wallCompass[1000];
int IGNORI = 0;
int CollectingObjFlag = 0;
int compassCounter = 0;
int compassy = 0;
int jahat = 0;
int ZXGOAL = 0;
int ZYGOAL = 0;
int EndMinex = -1;
boolean STOPFLAG = false;
boolean CALCPOSFLAG = true;
int AreaArray[100][100];
int stcounter = 0;
int encounter = 0;
int ViewedFromStart[100];
int ViewedFromEnd[100];
int sides1 = 0;
int sides2 = 0;
int sides3 = 0;
int sidee1 = 0;
int sidee2 = 0;
int sidee3 = 0;
int distanceStart[1000];
int distanceEnd[1000];
int semin = 0;
int seminex = 0;
int fiveTime = 1000;
int fiveFlag = 0;
int fourFlag = 0;
int fourTime = 1000;
int superobjflag = 0;
int Adisminex = -1;
int Adismin = 0;
int AXGoal = 0;
int AYGoal = 0;
int AreaFlag = -1;
int AreasFlags = 0;
int BigAreasFlags = 0;
int BlackObjs = 0;
int GreenObjs = 0;
int RedObjs = 0;
int BlackRedObjs = 0;
int GreenRedObjs = 0;
int BlackGreenObjs = 0;
int numbers = 0;
int ZArray[2][100];
int bironcon = 0;
int SearchState = 0;
int Znumber = 1;
int searchtime = 0;
int stop1 = 0;
int endcounter = 0;
int colorflag = 0;
int colorcounterii = 0;
clock_t Time1 = 0;
int Time2 = 0;
int SideAA1;
int SideAA2;
int SideAA3[10][500];
int SidePP1;
int SidePP2;
int SidePP3[500];
int ViewedFromStartAreas[10][100];
int startcounterareas[10];
int ViewedFromEndArea[100];
int Pdisminex = -1;
int Pdismin = 0;
int Ndisminex[20] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1 };
int Ndismin[500];
int FXGOAL = 0;
int FYGOAL = 0;
int ArrayFlag = 0;
int SobjCreater = 0;
int Objiii = 0;
int ColourCounter = 0;
int ColourFlag = 0;
int DepositFlag = 0;
int BlackObjFlag = 0;
int validCompass = 0;
int jolocounter = 0;
int RedBlackGreen = 0;
int notFullObjFlag = 0;
int WallFollowingFlag = 0;
int sobjCounter = 0;
boolean Blackk = true;
boolean Redd = true;
boolean Greenn = true;
boolean RedBlack = true;
boolean RedGreen = true;
boolean GreenBlack = true;
//CHARACTER
char PURPOSE = '-';
char Left = 'a';
char Right = 'b';
char Swamp = 'c';
char Orange = 'd';
char Black = 'e';
char Green = 'f';
char yellow = 'g';
char Blue = 'h';
char Red = 'i';
char DarkBlue = 'j';
char violet = 'k';
char SOBJColor = 'l';
char yellow3 = 'm';
char Orange2 = 'n';
char colorful = 'o';
char halat[100] = "adi";
char halat2[100] = "adi";
char wall_following = '-';
char aghabmirim = 0;

int position[5][500] = { { -1, 28, 116, 159, 224, 288, 340, 326, 328, 349, 334,
322, 345, 339, 295, 259, 120, 43, 29, 117, 158, 224, 289, 338, 325, 326, 349, 323,
343, 337, 294, 232, 186, 112, 68, 22, 26, 82, 113, 167, 231, 29, 117, 160, 223,
287, 341, 326, 348, 320, 344, 338, 293, 260, 123, 105, 105, 87, 71, 50, 58, 141,
224, 256 },
{ -1, 246, 239, 258, 239, 258, 231, 212, 184, 159, 125, 89, 64, 23, 14, 56, 14, 17,
245, 238, 259, 240, 259, 234, 207, 185, 161, 93, 60, 21, 15, 91, 95, 97, 128, 126,
193, 182, 163, 163, 186, 248, 239, 259, 240, 260, 234, 189, 159, 89, 63, 21, 16,
59, 14, 35, 68, 98, 125, 131, 183, 166, 185, 192 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1 },
{ -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1000, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 1000, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
1000 },
{ -1, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1000, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 } };
int add[64][64] = { { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1 }, { -1, 0, 87, 134, 201, 267, 324, 347, 375, 406, 442,
479, 512, 553, 596, 650, 794, 871, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -87, 0, 47, 114, 180,
237, 260, 288, 319, 355, 392, 425, 466, 509, 563, 707, 784, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1,
-134, -47, 0, 67, 133, 190, 213, 241, 272, 308, 345, 378, 419, 462, 516, 660, 737,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1 }, { -1, -201, -114, -67, 0, 66, 123, 146, 174, 205, 241, 278, 311,
352, 395, 449, 593, 670, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -267, -180, -133, -66, 0, 57,
80, 108, 139, 175, 212, 245, 286, 329, 383, 527, 604, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -
324, -237, -190, -123, -57, 0, 23, 51, 82, 118, 155, 188, 229, 272, 326, 470, 547,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1 }, { -1, -347, -260, -213, -146, -80, -23, 0, 28, 59, 95, 132, 165,
206, 249, 303, 447, 524, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -375, -288, -241, -174, -108, -
51, -28, 0, 31, 67, 104, 137, 178, 221, 275, 419, 496, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -
406, -319, -272, -205, -139, -82, -59, -31, 0, 36, 73, 106, 147, 190, 244, 388,
465, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1 }, { -1, -442, -355, -308, -241, -175, -118, -95, -67, -36,
0, 37, 70, 111, 154, 208, 352, 429, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -479, -392, -345, -278,
-212, -155, -132, -104, -73, -37, 0, 33, 74, 117, 171, 315, 392, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1 }, { -1, -512, -425, -378, -311, -245, -188, -165, -137, -106, -70, -33, 0, 41,
84, 138, 282, 359, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -553, -466, -419, -352, -286, -229, -
206, -178, -147, -111, -74, -41, 0, 43, 97, 241, 318, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -
596, -509, -462, -395, -329, -272, -249, -221, -190, -154, -117, -84, -43, 0, 54,
198, 275, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1 }, { -1, -650, -563, -516, -449, -383, -326, -303, -275,
-244, -208, -171, -138, -97, -54, 0, 144, 221, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -794, -707,
-660, -593, -527, -470, -447, -419, -388, -352, -315, -282, -241, -198, -144, 0,
77, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1 }, { -1, -871, -784, -737, -670, -604, -547, -524, -496, -465, -
429, -392, -359, -318, -275, -221, -77, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 87, 132, 199, 266, 320, 348,
369, 402, 473, 511, 549, 591, 689, 734, 807, 860, 906, 972, 1028, 1064, 1117, 1184,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-87, 0, 45, 112, 179, 233, 261, 282, 315, 386, 424, 462, 504, 602, 647, 720, 773,
819, 885, 941, 977, 1030, 1097, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -132, -45, 0, 67, 134, 188, 216, 237, 270, 341,
379, 417, 459, 557, 602, 675, 728, 774, 840, 896, 932, 985, 1052, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -199, -112, -
67, 0, 67, 121, 149, 170, 203, 274, 312, 350, 392, 490, 535, 608, 661, 707, 773,
829, 865, 918, 985, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -266, -179, -134, -67, 0, 54, 82, 103, 136, 207, 245, 283, 325,
423, 468, 541, 594, 640, 706, 762, 798, 851, 918, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -320, -233, -188, -121, -54, 0,
28, 49, 82, 153, 191, 229, 271, 369, 414, 487, 540, 586, 652, 708, 744, 797, 864, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-348, -261, -216, -149, -82, -28, 0, 21, 54, 125, 163, 201, 243, 341, 386, 459,
512, 558, 624, 680, 716, 769, 836, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -369, -282, -237, -170, -103, -49, -21, 0, 33,
104, 142, 180, 222, 320, 365, 438, 491, 537, 603, 659, 695, 748, 815, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -402, -
315, -270, -203, -136, -82, -54, -33, 0, 71, 109, 147, 189, 287, 332, 405, 458,
504, 570, 626, 662, 715, 782, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -473, -386, -341, -274, -207, -153, -125, -104, -
71, 0, 38, 76, 118, 216, 261, 334, 387, 433, 499, 555, 591, 644, 711, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -511, -
424, -379, -312, -245, -191, -163, -142, -109, -38, 0, 38, 80, 178, 223, 296, 349,
395, 461, 517, 553, 606, 673, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -549, -462, -417, -350, -283, -229, -201, -180, -
147, -76, -38, 0, 42, 140, 185, 258, 311, 357, 423, 479, 515, 568, 635, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -591, -504,
-459, -392, -325, -271, -243, -222, -189, -118, -80, -42, 0, 98, 143, 216, 269,
315, 381, 437, 473, 526, 593, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -689, -602, -557, -490, -423, -369, -341, -320, -
287, -216, -178, -140, -98, 0, 45, 118, 171, 217, 283, 339, 375, 428, 495, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
734, -647, -602, -535, -468, -414, -386, -365, -332, -261, -223, -185, -143, -45,
0, 73, 126, 172, 238, 294, 330, 383, 450, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -807, -720, -675, -608, -541, -487, -
459, -438, -405, -334, -296, -258, -216, -118, -73, 0, 53, 99, 165, 221, 257, 310,
377, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -860, -773, -728, -661, -594, -540, -512, -491, -458, -387, -349, -311, -
269, -171, -126, -53, 0, 46, 112, 168, 204, 257, 324, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -906, -819, -774, -707, -640, -586, -558, -537, -504, -433, -395, -357, -315, -
217, -172, -99, -46, 0, 66, 122, 158, 211, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -972, -885, -840, -773, -706, -652,
-624, -603, -570, -499, -461, -423, -381, -283, -238, -165, -112, -66, 0, 56, 92,
145, 212, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1028, -941, -896, -829, -762, -708, -680, -659, -626, -555, -517, -
479, -437, -339, -294, -221, -168, -122, -56, 0, 36, 89, 156, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1064, -977, -932,
-865, -798, -744, -716, -695, -662, -591, -553, -515, -473, -375, -330, -257, -204,
-158, -92, -36, 0, 53, 120, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1117, -1030, -985, -918, -851, -797, -769, -748, -715,
-644, -606, -568, -526, -428, -383, -310, -257, -211, -145, -89, -53, 0, 67, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1184, -1097, -1052, -985, -918, -864, -836, -815, -782, -711, -673, -635, -593, -
495, -450, -377, -324, -278, -212, -156, -120, -67, 0, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 88, 134, 198,
265, 324, 370, 406, 480, 514, 556, 600, 653, 796, 823, 856, 890, 920, 941, 993,
1077, 1161, 1192 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -88, 0, 46, 110, 177, 236, 282, 318, 392, 426, 468, 512, 565,
708, 735, 768, 802, 832, 853, 905, 989, 1073, 1104 }, { -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -134, -46, 0, 64, 131, 190,
236, 272, 346, 380, 422, 466, 519, 662, 689, 722, 756, 786, 807, 859, 943, 1027,
1058 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -198, -110, -64, 0, 67, 126, 172, 208, 282, 316, 358, 402, 455, 598, 625,
658, 692, 722, 743, 795, 879, 963, 994 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -265, -177, -131, -67, 0, 59, 105, 141,
215, 249, 291, 335, 388, 531, 558, 591, 625, 655, 676, 728, 812, 896, 927 }, { -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -324, -
236, -190, -126, -59, 0, 46, 82, 156, 190, 232, 276, 329, 472, 499, 532, 566, 596,
617, 669, 753, 837, 868 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -370, -282, -236, -172, -105, -46, 0, 36, 110, 144,
186, 230, 283, 426, 453, 486, 520, 550, 571, 623, 707, 791, 822 }, { -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -406, -318, -
272, -208, -141, -82, -36, 0, 74, 108, 150, 194, 247, 390, 417, 450, 484, 514, 535,
587, 671, 755, 786 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -480, -392, -346, -282, -215, -156, -110, -74, 0, 34, 76, 120,
173, 316, 343, 376, 410, 440, 461, 513, 597, 681, 712 }, { -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -514, -426, -380, -316, -
249, -190, -144, -108, -34, 0, 42, 86, 139, 282, 309, 342, 376, 406, 427, 479, 563,
647, 678 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -556, -468, -422, -358, -291, -232, -186, -150, -76, -42, 0, 44, 97,
240, 267, 300, 334, 364, 385, 437, 521, 605, 636 }, { -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -600, -512, -466, -402, -335, -
276, -230, -194, -120, -86, -44, 0, 53, 196, 223, 256, 290, 320, 341, 393, 477,
561, 592 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -653, -565, -519, -455, -388, -329, -283, -247, -173, -139, -97, -53,
0, 143, 170, 203, 237, 267, 288, 340, 424, 508, 539 }, { -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -796, -708, -662, -598, -
531, -472, -426, -390, -316, -282, -240, -196, -143, 0, 27, 60, 94, 124, 145, 197,
281, 365, 396 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -823, -735, -689, -625, -558, -499, -453, -417, -343, -309, -267, -
223, -170, -27, 0, 33, 67, 97, 118, 170, 254, 338, 369 }, { -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -856, -768, -722, -658, -
591, -532, -486, -450, -376, -342, -300, -256, -203, -60, -33, 0, 34, 64, 85, 137,
221, 305, 336 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -890, -802, -756, -692, -625, -566, -520, -484, -410, -376, -334, -
290, -237, -94, -67, -34, 0, 30, 51, 103, 187, 271, 302 }, { -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -920, -832, -786, -722,
-655, -596, -550, -514, -440, -406, -364, -320, -267, -124, -97, -64, -30, 0, 21,
73, 157, 241, 272 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -941, -853, -807, -743, -676, -617, -571, -535, -461, -427, -
385, -341, -288, -145, -118, -85, -51, -21, 0, 52, 136, 220, 251 }, { -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -993, -905, -
859, -795, -728, -669, -623, -587, -513, -479, -437, -393, -340, -197, -170, -137,
-103, -73, -52, 0, 84, 168, 199 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1077, -989, -943, -879, -812, -753, -707, -
671, -597, -563, -521, -477, -424, -281, -254, -221, -187, -157, -136, -84, 0, 84,
115 }, { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1161, -1073, -1027, -963, -896, -837, -791, -755, -681, -647, -605, -561,
-508, -365, -338, -305, -271, -241, -220, -168, -84, 0, 31 }, { -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1192, -1104, -1058, -
994, -927, -868, -822, -786, -712, -678, -636, -592, -539, -396, -369, -336, -302,
-272, -251, -199, -115, -31, 0 } };
int Obstacles[4][500] = { { 0, -5, 360, 365, -4, 297, 302, 0, 302, -4, 288, 297,
302, 293, 302, 288, 125, 296, 301, 130, 301, 125, 139, 145, 150, 144, 150, 139,
109, 170, 175, 114, 175, 109, 137, 144, 149, 142, 149, 137, 104, 173, 178, 109,
178, 104, 138, 144, 149, 143, 149, 138, 106, 172, 177, 111, 177, 106, 65, 72, 77,
70, 77, 65, 38, 99, 104, 43, 104, 38, 0, 29, 34, 4, 34, 0, -1, 25, 30, 3, 30, -1,
240, 269, 274, 245, 274, 240, 293, 313, 318, 298, 318, 293, 307, 327, 332, 312,
332, 307, 293, 312, 317, 298, 317, 293, 46, 60, 65, 51, 65, 46, 106, 134, 139, 111,
139, 106, 99, 113, 118, 104, 118, 99, 165, 191, 196, 170, 196, 165, 155, 169, 174,
160, 174, 155, 216, 229, 234, 221, 234, 216, 223, 250, 255, 228, 255, 223, 293,
307, 312, 298, 312, 293, 336, 348, 353, 341, 353, 336, 302, 316, 321, 307, 321,
302, 336, 351, 356, 341, 356, 336, 343, 356, 361, 348, 361, 343, 319, 333, 338,
324, 338, 319, 305, 318, 323, 310, 323, 305, 291, 330, 335, 296, 335, 291 },
{ -5, 270, 275, 0, 224, 219, 228, 219, 233, 233, 76, 71, 227, 71, 232, 232, 129,
124, 133, 124, 138, 138, 103, 98, 158, 98, 163, 163, 131, 126, 133, 126, 138, 138,
175, 170, 229, 170, 234, 234, 201, 196, 203, 196, 208, 208, 32, 27, 90, 27, 95, 95,
59, 54, 61, 54, 66, 66, 28, 23, 88, 23, 93, 93, 59, 54, 61, 54, 66, 66, 57, 52, 59,
52, 64, 64, 2, -2, 27, -2, 32, 32, 2, -2, 27, -2, 32, 32, 61, 56, 75, 56, 80, 80,
45, 40, 61, 40, 66, 66, 31, 26, 45, 26, 50, 50, 101, 96, 109, 96, 114, 114, 260,
255, 268, 255, 273, 273, 249, 244, 258, 244, 263, 263, 230, 225, 238, 225, 243,
243, 236, 231, 246, 231, 251, 251, 250, 245, 259, 245, 264, 264, 259, 254, 267,
254, 272, 272, 225, 220, 235, 220, 240, 240, 87, 82, 96, 82, 101, 101, 195, 190,
204, 190, 209, 209, 194, 189, 204, 189, 209, 209, 259, 254, 268, 254, 273, 273,
154, 149, 165, 149, 170, 170, 119, 114, 128, 114, 133, 133, 158, 153, 160, 153,
165, 165 },
{ 0, 365, 360, -5, 302, 297, -4, 0, -4, 302, 302, 297, 288, 293, 288, 302, 301,
296, 125, 130, 125, 301, 150, 145, 139, 144, 139, 150, 175, 170, 109, 114, 109,
175, 149, 144, 137, 142, 137, 149, 178, 173, 104, 109, 104, 178, 149, 144, 138,
143, 138, 149, 177, 172, 106, 111, 106, 177, 77, 72, 65, 70, 65, 77, 104, 99, 38,
43, 38, 104, 34, 29, 0, 4, 0, 34, 30, 25, -1, 3, -1, 30, 274, 269, 240, 245, 240,
274, 318, 313, 293, 298, 293, 318, 332, 327, 307, 312, 307, 332, 317, 312, 293,
298, 293, 317, 65, 60, 46, 51, 46, 65, 139, 134, 106, 111, 106, 139, 118, 113, 99,
104, 99, 118, 196, 191, 165, 170, 165, 196, 174, 169, 155, 160, 155, 174, 234, 229,
216, 221, 216, 234, 255, 250, 223, 228, 223, 255, 312, 307, 293, 298, 293, 312,
353, 348, 336, 341, 336, 353, 321, 316, 302, 307, 302, 321, 356, 351, 336, 341,
336, 356, 361, 356, 343, 348, 343, 361, 338, 333, 319, 324, 319, 338, 323, 318,
305, 310, 305, 323, 335, 330, 291, 296, 291, 335 },
{ 275, 270, -5, 0, 224, 233, 228, 233, 219, 219, 76, 232, 227, 232, 71, 71, 129,
138, 133, 138, 124, 124, 103, 163, 158, 163, 98, 98, 131, 138, 133, 138, 126, 126,
175, 234, 229, 234, 170, 170, 201, 208, 203, 208, 196, 196, 32, 95, 90, 95, 27, 27,
59, 66, 61, 66, 54, 54, 28, 93, 88, 93, 23, 23, 59, 66, 61, 66, 54, 54, 57, 64, 59,
64, 52, 52, 2, 32, 27, 32, -2, -2, 2, 32, 27, 32, -2, -2, 61, 80, 75, 80, 56, 56,
45, 66, 61, 66, 40, 40, 31, 50, 45, 50, 26, 26, 101, 114, 109, 114, 96, 96, 260,
273, 268, 273, 255, 255, 249, 263, 258, 263, 244, 244, 230, 243, 238, 243, 225,
225, 236, 251, 246, 251, 231, 231, 250, 264, 259, 264, 245, 245, 259, 272, 267,
272, 254, 254, 225, 240, 235, 240, 220, 220, 87, 101, 96, 101, 82, 82, 195, 209,
204, 209, 190, 190, 194, 209, 204, 209, 189, 189, 259, 273, 268, 273, 254, 254,
154, 170, 165, 170, 149, 149, 119, 133, 128, 133, 114, 114, 158, 165, 160, 165,
153, 153 } };
#define OBS_MAX 196
#define TrapFlag 6
#define IgnoredFlag 1
#define Depositi -1

DLL_EXPORT void SetGameID(int GameID)


{
CurGame = GameID;
bGameEnd = 0;
}

DLL_EXPORT int GetGameID()


{
return CurGame;
}

//Only Used by CsBot Dance Platform


DLL_EXPORT int IsGameEnd()
{
return bGameEnd;
}

#ifndef CSBOT_REAL

DLL_EXPORT char* GetDebugInfo()


{
char info[1024];
/*s*///////printf(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 "Sina";
}

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 CSBOT_REAL

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;
}
static int flag = 0;

//MOVEMENTS
boolean FrwState()
{
ACTION(2, 2, 0, 6);
ChangeState("adi");
return true;
}
boolean TurnLeftKam()
{
ACTION(3, -3, 0, 7);
ChangeState("adi");
}
boolean TurnRightKam()
{
ACTION(-3, 3, 0, 7);
ChangeState("adi");
}
boolean TurnLeft()
{
ACTION(3, -3, 0, 7);
ChangeState("adi");
}

///////////////////////////////////////////////////////////////////////////////////
/////

//Both Worlds
boolean ACTION(int l, int r, int led, int duration)
{
aghabmirim = 0;
//if (field == 0)
//{
// WheelLeft = l;
// WheelRight = r;
// LED_1 = led;
// Duration = duration;
// ////////printf("left%d\n", WheelLeft);
// ////////printf("right%d\n", WheelRight);
// ////////printf("DURATION%d\n", duration);
//}
//else
//{
int left = l, right = r;
double offset;
//printf("before left - right %d %d", left, right);
left *= SwampSpeed;
right *= SwampSpeed;
if (SwampSpeed > 1)
{
//////printf("left111111111111111%d\n", WheelLeft);
//////printf("right1111111111111%d\n", WheelRight);
if (left > right && left >= 5)
{
offset = left / 5;
left = 5;
right = right / offset;
}
else if (left < right && right >= 5)
{
offset = right / 5;
right = 5;
left = left / offset;
}
else if (left < 0 && right < 0 && left < right && left <= -5)
{
offset = left / 5;
left = -5;
right = right / offset;
}
else if (left < 0 && right < 0 && left > right && right <= -5)
{
offset = right / 5;
right = -5;
left = left / offset;
}
if (abs(left) < 2 && left != 0)
left = left>0 ? 2 : -2;
if (abs(right) < 2 && right != 0)
right = right>0 ? 2 : -2;

if (left == 5 && right == 3)


{
right = -3;
}
if (left == 3 && right == 5)
{
left = -3;
}
}
if (field == 1 && SignalBlockZone())
{
if (left == 0 && right == 0)
{
StartTime();
}
else if (left == right)
{
if (left > 0)
{

if (bati == 0)
{
StopTime();
left = 3;
right = 3;
}
else
{
StopTime();
left = 25;
right = 25;
}
}
else
{
aghabmirim = 1;
if (bati == 0)
{
StopTime();
left = -3;
right = -3;
}
else
{
StopTime();
left = -25;
right = -25;
}
}
}
if (left != right)
{
StartTime();
}

if (left != right && (left != 0 && right != 0))


{
if (left != -right || right != -left)
{
if (left < right)
{
if (bati == 0)
{
int dif = right - left;
if ((dif % 2) == 1)
dif += 1;
right = dif / 2;
left = 0 - dif / 2;
}
else
{
left = -5;
right = 5;
}
}
else
{
if (bati == 0)
{
int dif = left - right;
if ((dif % 2) == 1)
dif += 1;
left = dif / 2;
right = 0 - dif / 2;
}
else
{
left = 5;
right = -5;
}
}
}
else if (bati == 1)
{
if (left < right)
{
left = -5;
right = 5;
}
else
{
left = 5;
right = -5;
}
}
}
}
if (left == 1 && right == -1)
{
left = 2;
right = -2;
}
else if (left == -1 && right == 1)
{
left = -2;
right = 2;
}
WheelLeft = left;
WheelRight = right;
LED_1 = led;
Duration = duration;
//printf("after left - right %d %d\n", left, right);
printf("left%d\n", WheelLeft);
printf("right%d\n", WheelRight);
//////printf("DURATION%d\n", duration);
//}

}
//Objects
boolean OneSet()
{
if ((RedObjCounter2 >= 1 && GreenObjCounter2 >= 1 && BlackObjCounter2 >= 1 &&
ObjCounter < ObjsREnough) ||
(RedObjCounter1 >= 1 && GreenObjCounter1 >= 1 && BlackObjCounter1 >= 1
&& ObjCounter < ObjsREnough))
{
return true;
}
return false;
}
boolean FiveObjects()
{
if ((((RedObjCounter1 >= 1 && GreenObjCounter1 >= 1) || (RedObjCounter1 >= 1
&& BlackObjCounter1 >= 1) || (BlackObjCounter1 >= 1 && GreenObjCounter1 >= 1)) ||
((RedObjCounter2 >= 1 && GreenObjCounter2 >= 1) || (RedObjCounter2 >= 1
&& BlackObjCounter2 >= 1) || (BlackObjCounter2 >= 1 && GreenObjCounter2 >= 1)))
&& ObjCounter <= 4)
{
return true;
}
return false;
}
void LastObj()
{
if (ObjCounter == 4 && fourFlag == 0)
{
fourTime = Time;
fourFlag = 1;
}
else if (ObjCounter == 5 && fiveFlag == 0)
{
fourTime = 1000;
fiveTime = Time;
fiveFlag = 1;
}
}
//colour
void Colour()
{
Left = 'x';
Right = 'x';

if (CSLeft_R >= 180 && CSLeft_R <= 255 && CSLeft_G >= 20 && CSLeft_G <= 205
&& CSLeft_B >= 0 && CSLeft_B <= 70)
{
Left = Orange;
}
if (CSRight_R >= 180 && CSRight_R <= 255 && CSRight_G >= 20 && CSRight_G <=
205 && CSRight_B >= 0 && CSRight_B <= 70)
{
Right = Orange;
}
if (CSLeft_R >= 103 && CSLeft_R <= 173 && CSLeft_G >= 121 && CSLeft_G <= 181
&& CSLeft_B >= 167 && CSLeft_B <= 227)
{
Left = Swamp;
}
if (CSRight_R >= 103 && CSRight_R <= 173 && CSRight_G >= 121 && CSRight_G <=
181 && CSRight_B >= 167 && CSLeft_B <= 227)
{
Right = Swamp;
}
if (CSLeft_R >= 212 && CSLeft_R <= 255 && CSLeft_G >= 9 && CSLeft_G <= 49 &&
CSLeft_B >= 9 && CSLeft_B <= 49)
{
Left = Red;
}
if (CSRight_R >= 212 && CSRight_R <= 255 && CSRight_G >= 9 && CSRight_G <= 40
&& CSRight_B >= 9 && CSRight_B <= 49)
{
Right = Red;
}
if (CSLeft_R >= 0 && CSLeft_R <= 59 && CSLeft_G >= 223 && CSLeft_G <= 255 &&
CSLeft_B >= 220 && CSLeft_B <= 255)
{
Left = Green;
}
if (CSRight_R >= 0 && CSRight_R <= 59 && CSRight_G >= 223 && CSRight_G <= 255
&& CSRight_B >= 220 && CSRight_B <= 255)
{
Right = Green;
}
if (CSLeft_R >= 0 && CSLeft_R <= 60 && CSLeft_G >= 0 && CSLeft_G <= 60 &&
CSLeft_B >= 0 && CSLeft_B <= 60)
{
Left = Black;
}
if (CSRight_R >= 0 && CSRight_R <= 60 && CSRight_G >= 0 && CSRight_G <= 60 &&
CSRight_B >= 0 && CSRight_B <= 60)
{
Right = Black;
}
if (CSLeft_R >= 0 && CSLeft_R <= 30 && CSLeft_G >= 130 && CSLeft_G <= 170 &&
CSLeft_B >= 235 && CSLeft_B <= 255)
{
Left = Blue;
}
if (CSRight_R >= 0 && CSRight_R <= 30 && CSRight_G >= 130 && CSRight_G <= 170
&& CSRight_B >= 235 && CSRight_B <= 255)
{
Right = Blue;
}
if (CSLeft_R >= 183 && CSLeft_R <= 255 && CSLeft_G >= 196 && CSLeft_G <= 255
&& CSLeft_B >= 0 && CSLeft_B <= 60)
{
Left = yellow3;
}
if (CSRight_R >= 183 && CSRight_R <= 255 && CSRight_G >= 196 && CSRight_G <=
255 && CSRight_B >= 0 && CSRight_B <= 60)
{
Right = yellow3;
}
if (CSLeft_R >= 30 && CSLeft_R <= 60 && CSLeft_G >= 27 && CSLeft_G <= 57 &&
CSLeft_B >= 188 && CSLeft_B <= 218)
{
Left = DarkBlue;
}
if (CSRight_R >= 30 && CSRight_R <= 60 && CSRight_G >= 27 && CSRight_G <= 57
&& CSRight_B >= 188 && CSRight_B <= 218)
{
Right = DarkBlue;
}
if (CSLeft_R >= 130 && CSLeft_R <= 150 && CSLeft_G >= 90 && CSLeft_G <= 110
&& CSLeft_B >= 168 && CSLeft_B <= 188)
{
Left = violet;
}
if (CSRight_R >= 130 && CSRight_R <= 150 && CSRight_G >= 90 && CSRight_G <=
110 && CSRight_B >= 168 && CSRight_B <= 188)
{
Right = violet;
}
if (CSLeft_R >= 231 && CSLeft_R <= 255 && CSLeft_G >= 20 && CSLeft_G <= 61 &&
CSLeft_B >= 114 && CSLeft_B <= 255)
{
Left = SOBJColor;
}
if (CSRight_R >= 231 && CSRight_R <= 255 && CSRight_G >= 20 && CSRight_G <=
61 && CSRight_B >= 114 && CSRight_B <= 255)
{
Right = SOBJColor;
}
//if (CSLeft_R >= 113 && CSLeft_R <= 173 && CSLeft_G >= 121 && CSLeft_G <=
181 && CSLeft_B >= 167 && CSLeft_B <= 227)
//{
// Left = colorful;
//}
//if (CSRight_R >= 113 && CSRight_R <= 173 && CSRight_G >= 121 && CSRight_G
<= 181 && CSRight_B >= 167 && CSLeft_B <= 227)
//{
// Right = colorful;
//}
//printf("right: %c\n", Right);
//printf("left: %c\n", Left);
}
//relevent to depositbox
boolean NotFullObj()
{

if (Left != Orange && Right != Orange)


{
notFullObjFlag = 0;
}
else if (ObjCounter < 6 && Left == Orange && Right == Orange && NotFullObj ==
0)
{
notFullObjFlag = 1;
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("adi");
return true;
}
else if (ObjCounter < 6 && Left == Orange && notFullObjFlag == 0)
{
notFullObjFlag = 1;
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("adi");
return true;
}
else if (ObjCounter < 6 && Right == Orange && notFullObjFlag == 0)
{
notFullObjFlag = 1;
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("adi");
return true;
}

//////printf("notfullobj%d\n", notFullObjFlag);
return false;
}
boolean FullObj()
{
if (DepositPossible1() && Left == Orange)
{
ACTION(0, 2, 0, 0);
ChangeState("adi");
return true;
}
else if (DepositPossible1() && Right == Orange)
{
ACTION(2, 0, 0, 0);
ChangeState("adi");
return true;
}
return false;
}
//states
boolean ChangeState(char HalatJadid[100])
{
StateFlag = Time;
strcpy(halat, HalatJadid);
//printf("halat %s\n", halat);
}
//Turning
boolean CompassSpan()
{
int baze2 = 7;
comin2 = Cmpideal - baze2;
comax2 = Cmpideal + baze2;
if (comin2 < 0)
{
comin2 = comin2 + 360;
}
else if (comax2 > 360)
{
comax2 = comax2 - 360;
}
if (Cmpideal > baze2 && Cmpideal < 360 - baze2)
{
if (comin2 <= Compass && Compass <= comax2)
{
if (comin2 + baze2 < Compass)
{
Cmpideal = -1;
}
else if (comax2 - baze2 > Compass)
{
Cmpideal = -1;
}
return false;
}
else
{
return true;
}
}
else
{
if (Compass >= comin2 || Compass <= comax2)
{
if (comin2 + baze2 < Compass)
{
Cmpideal = -1;
}
else if (comax2 - baze2 > Compass)
{
Cmpideal = -1;
}
return false;
}
else
{
return true;
}
}
}
boolean CompassGoal()
{
int ekhtelaf2 = 0;
if (!CompassSpan())
{
return true;
}
else
{

if (abs(Cmpideal - Compass) < 180)


ekhtelaf2 = Cmpideal - Compass;
else
ekhtelaf2 = 360 - abs(Cmpideal - Compass);
ekhtelaf2 = abs(ekhtelaf2);
WheelCompass = abs(ekhtelaf2 / 45) + 1;
if (Cmpideal - Compass < -180)
{
ACTION(-WheelCompass, WheelCompass, 0, 0);
return true;
}
else if (Cmpideal - Compass >= -180 && Cmpideal - Compass <= 0)
{
ACTION(WheelCompass, -WheelCompass, 0, 0);
return true;
}
else if (Cmpideal - Compass < 180 && Cmpideal - Compass > 0)
{
ACTION(-WheelCompass, WheelCompass, 0, 0);
return true;
}
else if (Cmpideal - Compass >= 180)
{
ACTION(WheelCompass, -WheelCompass, 0, 0);
return true;
}
}
return false;
}
int eslah(int a)
{
if (a > 360)
a -= 360;
if (a < 0)
a += 360;
return a;
}
//trap
void MantagheAbiVasatTale()
{
if (Left == DarkBlue || Right == DarkBlue)
{
ObjCounter = 0;
GreenObjCounter2 = 0;
BlackObjCounter2 = 0;
RedObjCounter2 = 0;
GreenObjCounter1 = 0;
BlackObjCounter1 = 0;
RedObjCounter1 = 0;
if (PURPOSE == "D")
PURPOSE = "-";
}
}
///////////////////////////////////////////////////////////////////////////////////
/////

//World 1
boolean NormalState()
{
CollectingObjFlag = 0;
if (WARNING() != -1)
{
Cmpideal = eslah(Compass + 180);
CompassGoal();
return true;
}
if (WallTurn() != 0)
{
wall_following = '-';
WallFollowingFlag = Time;
//Cmpideal = eslah(Compass + 180);
//CompassGoal();
return true;
}
if (OBJECTISNOTFULL1() && (RedObj1() || GreenObj1() || BlackObj1()))
{
return true;
}
if (DepositPossible1())
{
//ChangeState("full");
FullObjStateField1();
return true;
}
//if (CHANGEFOLLOWDIR() == 1)
//{
// return true;
//}
if (TrapField1() == 1)
{
return true;
}

//if (wall_following == 'l')


//{
// chap();
// return true;
//}
//if (wall_following == 'r')
//{
// rast();
// return true;
//}
if (NotFullObj() == 1)
{
return true;
}
if (ObstacleField1() == 1)
{
return true;
}

if (Move1() == 1)
{
return true;
}
return false;
}
void Game0()
{
char c = 's';
Colour();
////////printf("CollectingObjFlag%d\n", CollectingObjFlag);
////////printf("objcounter%d\n", ObjCounter);
if (Duration > 0)
{
Duration--;
if (CollectingObjFlag == 1)
{
if (TrapField1() == 1)
{
////////printf("ganj too trap\n");
}
}
if ((Left == Red || Right == Red || Left == Green || Right == Green ||
Left == Black || Right == Black) && CollectingObjFlag == 0)
{
////////printf("SSSSSSSSSSSSSSSSSSSSSSS\n");
RedObj1();
GreenObj1();
BlackObj1();
}

}
else
{
if (Cmpideal == -1)
{
//////printf("objcounter%d\n", ObjCounter);
//////printf("notfullobj%d\n", notFullObjFlag);
//////printf("wall_following%c\n", wall_following);
if (Left == Orange && Right == Orange && ObjCounter >= 6)
{
wall_following = '-';
}
MantagheAbiVasatTale();
LastObj();
WALLFOLLOWCONDITION();
teleport();

if (strcmp(halat, "180") == 0)
{
CompleteTurn();
}
else if (strcmp(halat, "adi") == 0)
{
NormalState();
}
else if (strcmp(halat, "TurnLeftKam") == 0)
{
TurnLeftKam();
}
else if (strcmp(halat, "TurnRightKam") == 0)
{
TurnRightKam();
}
else if (strcmp(halat, "MoveBackward") == 0)
{
MoveBackward();
}
//else if (strcmp(halat, "full") == 0)
//{
// FullObjStateField1();
//}
else if (strcmp(halat, "CheckDepo") == 0)
{
CheckDepo1();
}
else if (strcmp(halat, "StopAndCheck") == 0)
{
StopAndCheck1();
}
else if (strcmp(halat, "ganjbardasht") == 0)
{
FrwState();
}
else if (strcmp(halat, "TurnLeft") == 0)
{
TurnLeft();
}
else if (strcmp(halat, "TurnLeftKam") == 0)
{
TurnLeftKam();
}
else if (strcmp(halat, "TurnRightKam") == 0)
{
TurnRightKam();
}

}
else
{
CompassGoal();
}
}
}
//Obstacle & Trap & Border
boolean ObstacleField1()
{
if (US_Front < 15 && US_Right < 15 && US_Left < 15)
{
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("**********************obs0");
ChangeState("adi");
}
else if (US_Front < 20)
{
if (US_Left < US_Right)
{
ACTION(3, -2, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;

}
else
{
ACTION(-2, 3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
}
//else if (US_Right < 25 && US_Left < 25)
//{
// ACTION(3, 3, 0, 1);
// ChangeState("obs0");
// ChangeState("adi");
// return true;
//}

else if (US_Right < 17)


{
ACTION(1, 3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
else if (US_Left < 17)
{
ACTION(3, 1, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
return false;
}
boolean TrapField1()
{
////////printf("heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_____________________\
n");
if (((Left == yellow3 && Right == yellow3)) && ObjCounter > 0)
{
ACTION(-3, -3, 0, 5);
ChangeState("talledidan");
if (trapcounter == 0)
{
ChangeState("TurnRightKam");
trapcounter++;
}
else
{
ChangeState("TurnLeftKam");
trapcounter = 0;
}
return true;
}
else if ((Left == yellow3) && ObjCounter > 0)
{
if (US_Right < 17)
{
ACTION(3, -2, 0, 0);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
else
{
ACTION(3, -2, 0, 0);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
}
else if ((Right == yellow3) && ObjCounter > 0)
{
if (US_Right < 17)
{
ACTION(-2, 3, 0, 0);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
else
{
ACTION(-2, 3, 0, 0);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
}
return false;
}
//DEPOSIT DANCE
boolean FollowingDepositBox()
{
int baze = 15;
comin = CompassIdeal - baze;
comax = CompassIdeal + baze;
if (comin < 0)
{
comin = comin + 360;
}
else if (comax > 360)
{
comax = comax - 360;
}
if (CompassIdeal != 2000)
{
if (CompassIdeal >= baze && CompassIdeal <= 360 - baze)
{
if (comin <= Compass && Compass <= comax)
{
if (comin + baze / 2 <= Compass)
{
ACTION(3, 3, 0, 0);
}
else if (comax - baze / 2 >= Compass)
{
ACTION(3, 3, 0, 0);
}
else if (comin <= Compass)
{
ACTION(2, 3, 0, 0);
}
else if (comin >= Compass)
{
ACTION(3, 2, 0, 0);
}
return false;
}
else
{
DepositDanceTurning();
return true;
}
}
else
{
if (Compass >= comin || Compass <= comax)
{
if (comin + baze / 2 <= Compass)
{
ACTION(3, 3, 0, 0);
}
else if (comax - baze / 2 >= Compass)
{
ACTION(3, 3, 0, 0);
}
else if (comin <= Compass)
ACTION(2, 3, 0, 0);
else if (comin >= Compass)
ACTION(3, 2, 0, 0);
return false;
}
else
{
DepositDanceTurning();
return true;
}
}
}
return false;
}
boolean ctrl = false;
boolean DP(int dpstate, int direction, int nextifwall, int nextiftrap, int
nextifborder, int Timer, int nextiftimer)
{
if (dds == dpstate && ctrl == false)
{
ctrl = true;
CompassIdeal = direction;
if (!FollowingDepositBox())
{
if (dpstate == 1 && DPFLAGII == 0)
{
dpflag = 1;
dds = 1;
DPFLAGII = 1;
}
if (depositdancetimer == 0)
{
depositdancetimer = Time;
}
if (US_Front < 14)
{
dds = nextifwall;
ACTION(-2, -2, 0, 5);
biaaghab = 1;
depositdancetimer = 0;
return true;
}
else if (Left == violet || Right == violet)
{
dpflag = 1;
}
else if ((Right == colorful || Left == colorful) && ObjCounter >
0)
{
dds = nextifborder;
ACTION(-1, -1, 0, 10);
biaaghab = 1;
depositdancetimer = 0;
return true;
}
else if ((Right == yellow3 || Left == yellow3 || Right == yellow3
|| Left == yellow3) && ObjCounter > 0)
{
dds = nextiftrap;
ACTION(-2, -2, 0, 10);
biaaghab = 1;
depositdancetimer = 0;
return true;
}
else if (Time > depositdancetimer + Timer)
{
dds = nextiftimer;
depositdancetimer = 0;
return true;
}
}
}
return false;
}
boolean DepositDance()
{
ctrl = false;
//if (dpflag == 1)
//{
// //DP(1, 180, 2, 2, 2, 10000, 2);
// //DP(2, 270, 5, 3, 3, 2, 4);
// //DP(3, 270, 4, 1, 1, 1, 1);
// //DP(3, 90, 1, 1, 1, 2, 1);
// //DP(4, 180, 5, 5, 5, 1000, 1);
// //DP(5, 90, 1, 1, 1, 1000, 1);
//}
//else
//{
// DP(1, 270, 2, 3, 3, 10000, 2);
// //DP(2, 0, 6, 6, 6, 4, 5);
// //DP(3, 0, 6, 6, 6, 4, 4);
// //DP(4, 270, 6, 6, 6, 1000, 1);
// //DP(5, 90, 6, 6, 6, 1000, 1);
// //DP(6, 180, 1, 1, 1, 1000, 1);
// //DP(7, 90, 1, 1, 1, 1, 1);
//}
DP(1, 270, 2, 2, 2, 1000, 2);
DP(2, 180, 3, 3, 3, 1000, 3);
DP(3, 90, 4, 4, 4, 1000, 4);
DP(4, 0, 5, 5, 5, 3, 5);
DP(5, 270, 1, 1, 1, 1000, 1);
return true;
}
void DepositDanceTurning()
{
int ekhtelaf = 0;
if (abs(CompassIdeal - Compass) < 180)
ekhtelaf = CompassIdeal - Compass;
else
ekhtelaf = 360 - abs(CompassIdeal - Compass);
ekhtelaf = abs(ekhtelaf);
WheelLeftCompass = abs(ekhtelaf / 45) + 1;
if (CompassIdeal - Compass < -180)
{
ACTION(-WheelLeftCompass, WheelLeftCompass, 0, 0);
}
else if (CompassIdeal - Compass >= -180 && CompassIdeal - Compass <= 0)
{
ACTION(WheelLeftCompass, -WheelLeftCompass, 0, 0);
}
else if (CompassIdeal - Compass < 180 && CompassIdeal - Compass > 0)
{
ACTION(-WheelLeftCompass, WheelLeftCompass, 0, 0);
}
else if (CompassIdeal - Compass > 180)
{
ACTION(WheelLeftCompass, -WheelLeftCompass, 0, 0);
}
wheel_right_compass = WheelLeftCompass;
}
//OBJECTS
boolean RedObj1()
{
if (ObjCounter < 4 || (ObjCounter >= 4 && RedObjCounter1 == 0) || OneSet() ||
FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
{
if (Left == Red || Right == Red)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
fiveFlag = 0;
fiveTime = 1000;
fourTime = 1000;
fourFlag = 0;
ObjCounter++;
RedObjCounter1++;
ChangeState("ganjbardasht");
return true;
}
}
return false;
}
boolean GreenObj1()
{
if (ObjCounter < 4 || (ObjCounter >= 4 && GreenObjCounter1 == 0) || OneSet()
|| FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
{
if (Left == Green || Right == Green)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
fiveFlag = 0;
fiveTime = 1000;
fourTime = 1000;
fourFlag = 0;
ObjCounter++;
GreenObjCounter1++;
ChangeState("ganjbardasht");
return true;
}
}
return false;
}
boolean BlackObj1()
{
if (ObjCounter < 4 || (ObjCounter >= 4 && BlackObjCounter1 == 0) || OneSet()
|| FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
{
if (Left == Black || Right == Black)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
fiveFlag = 0;
fiveTime = 1000;
fourTime = 1000;
fourFlag = 0;
ObjCounter++;
BlackObjCounter1++;
ChangeState("ganjbardasht");
return true;
}
}
return false;
}
boolean OBJECTISNOTFULL1()
{
if (ObjCounter < MAX_OBJECT1)
return true;
return false;
}
//WALL FOLLOWING
boolean CHANGEFOLLOWDIR()
{
//////////printf("***wall_following %c\n", wall_following);
if (wall_following == '-')
{
return false;
}
if (counter_follow > 120)
{
counter_follow = 0;
wall_following = '-';
return true;
}
if (wall_following == 'l')
{
if ((Left == yellow3 || Right == yellow3) && (ObjCounter > 0))
{
ACTION(-1, -5, 0, 6);
////////printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
return true;
}
else if (US_Front < 15)
{
ACTION(2, -2, 0, 5);
return true;
}
}
if (wall_following == 'r')
{
if ((Right == yellow3 || Left == yellow3) && (ObjCounter > 0))
{
ACTION(-5, -1, 0, 6);
////////printf("dddddddddddddddddddddddddddddddddddddd\n");
return true;
////////printf("wwwwwwwwwww\n");
}
else if (US_Front < 15)
{
ACTION(-2, 2, 0, 5);
return true;
}
}
return false;
}
boolean WALLFOLLOWCONDITION()
{
if (wall_following != '-')
return true;
if (US_Right < MIN_WALL && Time - WallFollowingFlag > 1)
{
counter_follow = 0;
wall_following = 'r';
validCompass = 0;
return true;
}
if (US_Left < MIN_WALL && Time - WallFollowingFlag > 2)
{
counter_follow = 0;
wall_following = 'l';
validCompass = 0;
return true;
}
return false;
}
boolean CompleteTurn()
{
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("adi");
return true;
}
boolean rast()
{
//if (ObjCounter < 6)
//{

// if (US_Right < MIN_WALL)


// {
// ACTION(2, 4, 0, 0);
// counter_follow = 0;
// }
// else if (US_Right > MAX_WALL)
// {
// ACTION(4, 2, 0, 0);
// counter_follow++;
// }
// else
// {
// ACTION(4, 4, 0, 0);
// }
//}
//else if (ObjCounter >= 6)
//{
if (US_Right < MIN_WALL)
{
ACTION(2, 5, 0, 0);
counter_follow = 0;
}
else if (US_Right > MAX_WALL)
{
ACTION(5, 2, 0, 0);
counter_follow++;
}
else
{
ACTION(4, 4, 0, 0);
}
/*}*/
}
boolean chap()
{
/*if (ObjCounter < 6)
{
if ((US_Left < MIN_WALL))
{
ACTION(4, 2, 0, 0);
counter_follow = 0;
}
else if ((US_Left > MAX_WALL))
{
ACTION(2, 4, 0, 0);
counter_follow++;
}
else
{
ACTION(4, 4, 0, 0);
}
}
else if (ObjCounter >= 6)
{
*/ if ((US_Left < MIN_WALL))
{
ACTION(5, 2, 0, 0);
counter_follow = 0;
}
else if ((US_Left > MAX_WALL))
{
ACTION(2, 5, 0, 0);
counter_follow++;
}
else
{
ACTION(4, 4, 0, 0);
}
/*}*/

}
boolean WallTurn()
{
////////////printf("inja\n\n\n");
//wallCompass[compassCounter] = Compass - 180;
////////////printf("wallcompass%d\n", wallCompass[compassCounter]);
//compassCounter++;
//validCompass++;
//if (compassCounter == 109)
// compassCounter = 0;
//if (compassy < 110)
// compassy++;

//int sumC = 0;

//for (int i = 0; i < 109; i++)


//{
// sumC += wallCompass[i];
//}
//////////printf("sumC %d | validCompass %d \n", sumC,validCompass);
//if (validCompass >= INT_MAX)
//{
// validCompass = 110;
//}
//if (validCompass > 109)
//{
// compassy = 0;
// if (sumC <= 0 && sumC >= -0)
// {
// ////////printf("SumC = %d \n", sumC);
// validCompass = 0;
// return 1;
// }
//}
//return 0;

////////printf("inja\n\n\n");
wallCompass[compassCounter] = Compass - 180;
////////printf("wallcompass%d\n", wallCompass[compassCounter]);
compassCounter++;

if (compassCounter == 109)
compassCounter = 0;
if (compassy < 110)
compassy++;

int sumC = 0;

for (int i = 0; i < 109; i++)


{
sumC += wallCompass[i];
}
////////printf("compassy%d\n", compassy);
////////printf("sum %d\n\n\n\n\n\n\n", sumC);
if (compassy == 80)
{
compassy = 0;
if (sumC <= 1400 && sumC >= -1400)
{
return 1;
}
}
return 0;
}
//DEPOSIT
boolean DepoBoxDetected1()
{
if (DepositPossible1() && bothSensorDepoBoxField1())
{
return true;
}
if (DepositPossible1() && oneSensorDepoBoxField1())
{
return true;
}
ChangeState("adi");
return false;
}
boolean bothSensorDepoBoxField1()
{
if (DepositPossible1() && Left == Orange && Right == Orange)
{
ACTION(1, 1, 0, 1);
ChangeState("StopAndCheck");
return true;
}
return false;
}
boolean oneSensorDepoBoxField1()
{
if (DepositPossible1() && Left == Orange)
{
ACTION(0, 2, 0, 0);
ChangeState("chapdid");
ChangeState("adi");
return true;
}
else if (DepositPossible1() && Right == Orange)
{
ACTION(2, 0, 0, 0);
ChangeState("leftdid");
ChangeState("adi");
return true;
}
return false;
}
boolean CheckDepo1()
{
if (Left == Orange && Right == Orange)
{
ACTION(0, 0, 2, 50);
ObjCounter = 0;
GreenObjCounter1 = 0;
BlackObjCounter1 = 0;
RedObjCounter1 = 0;
ChangeState("MoveBackward");
}
else
{
ChangeState("adi");
}
}
boolean StopAndCheck1()
{
if (DepositPossible1())
{
ACTION(0, 0, 0, 5);
ChangeState("CheckDepo");
return true;
}
else
{
ChangeState("adi");
}
return false;
}
boolean DepositPossible1()
{
if ((ObjCounter >= ObjsREnough && Time < 180 /*&& (Left == Orange || Right ==
Orange)*/) ||
(ObjCounter > 0 && Time > 180 && Time < 240 /*&& (Left == Orange ||
Right == Orange)*/) ||
(RedObjCounter1 >= 1 && GreenObjCounter1 >= 1 && BlackObjCounter1 >= 1
&& (Left == Orange || Right == Orange)) /*|| dpflag == 0*/)
{
return true;
}
return false;
}
boolean FullObjStateField1()
{
if (OBJECTISNOTFULL1() && (RedObj1() || GreenObj1() || BlackObj1()))
{
return true;
}
if (DepoBoxDetected1() == 1)
{
return true;
}
if (DepositDance() == 1)
{
return true;
}
ChangeState("adi");
return false;
}
//MOVE
int WARNING()
{
data[datacounter][0] = WheelRight;
data[datacounter][1] = WheelLeft;
data[datacounter][2] = Compass;
datacounter++;
if (datacounter == 99)
datacounter = 0;
if (validdata < 100)
validdata++;
int suml = 0, sumr = 0, sumc = 0;
for (int i = 0; i < 99; i++)
{
suml += data[i][1];
sumr += data[i][0];
sumc += data[i][2];
}
//////printf("suml= %d/n", suml);
//////printf("sumr= %d/n", sumr);
//////printf("sumc= %d/n", sumc);

if (validdata == 100 && sumr + suml < 100)


{
float c = (float)sumc / 100.0;
validdata = 0;
return c;
}
return -1;
}
boolean Move1()
{
if (clock() - Time1 > 1400)
{
Time1 = clock();
}
if (clock() - Time1 > 700)
{
ACTION(4, 4, 0, 0);
}

else if (clock() - Time1 < 700)


{
ACTION(4, 4, 0, 0);
}
return true;
}
//Teleport
void teleport()
{
if (Time > 180 && Time <= 210 && ObjCounter < 3 && ObjCounter > 0)
{
Teleport = 1;
ObjCounter = 0;
}
else if (Time > 180 && ObjCounter == 0 && TeleportAfterDepositFlag == 0)
{
TeleportAfterDepositFlag = 1;
}
else if (TeleportAfterDepositFlag == 1)
{
TeleportAfterDeposit++;
}
else if (Time >= 239)
{

Teleport = 1;
ObjCounter = 0;

}
if (TeleportAfterDeposit > 52)
{
Teleport = 1;
ObjCounter = 0;
}
}
///////////////////////////////////////////////////////////////////////////////////
///////

//WORLD 2
void Game1()

{
Colour();
SobjPosition();
field = 1;
//////printf("before= %d %d\t", PositionX, PositionY);
//if (PositionX > 26 && PositionX < 134 && PositionY > 142 && PositionY <
248)
//{
// PositionX = 0;
// PositionY = 0;
//}
//////printf("duration%d\n\n", Duration);
if (Duration>0)
{
//////printf("qqqqqqqqqqqqqqqqqqqqqqqqq\n\n");
//printf("duration2222222222%d\n\n", Duration);
Duration--;
if ((Left == Red || Right == Red || Left == Green || Right == Green ||
Left == Black || Right == Black || Left == SOBJColor || Right == SOBJColor) &&
CollectingObjFlag == 0)
{
RedObj2();
GreenObj2();
BlackObj2();
SuperObj();
}

}
else
{

//////printf("duration33333333%d\n\n", Duration);
RPOSX = PositionX;
RPOSY = PositionY;
//////printf("colorcounterii %d\n", colorcounterii);
////////printf("right %d\n", WheelRight);
//////printf("fxgoal: %d\n", FXGOAL);
//////printf("fygoal: %d\n", FYGOAL);
//printf("PURPOSE: %c\n", PURPOSE);
////printf("pathselected %d\n", PATHSELECTED);
////////printf("jahat %d\n", jahat);
////printf("areaflag %d\n", AreasFlags);
printf("adisminex %d\n", Adisminex);
printf("seminex %d\n", seminex);
printf("endminex %d\n", EndMinex);
////////printf("halat %s\n", halat);
//printf("SwampSpeed %d\n", SwampSpeed);
//printf("left %d\n", Left);
//printf("right %d\n", Right);
printf("disminex %d\n", disminex);
//printf("RedAreatime: %d\n", RedAreaTime);
//printf("BlackAreatime: %d\n", BlackAreaTime);
//printf("GreenAreatime: %d\n", GreenAreaTime);
//printf("GreenObjCounter2 %d\n", GreenObjCounter2);
//printf("RedObjCounter2: %d\n", RedObjCounter2);
//printf("BlackObjCounter2: %d\n", BlackObjCounter2);
////////printf("DepositFlag%d\n", DepositFlag);
//printf("AreasFlags%d\n", AreasFlags);
//printf("BigAreasFlags%d\n", BigAreasFlags);
LastObj();
if (Cmpideal == -1)
{

Zero();
if (!SignalBlockZone())
{
Positionx = RPOSX;
Positiony = RPOSY;
}
else
{
}
//printf("before= %d %d\t", PositionX, PositionY);
//printf("after= %d %d\n", Positionx, Positiony);
PositionX = Positionx;
PositionY = Positiony;
NearestArea();

if (abs(LASTPOSX - PositionX) > 20 || abs(LASTPOSY - PositionY) >


20)
{
if (PURPOSE != '-')
{
PATHSELECTED = 0;
PURPOSE = '-';
//////printf("||||||||||||R|E|L|O|C|A|T|
E||||||||||||||||||| \n");
}

LASTPOSX = PositionX;
LASTPOSY = PositionY;
MantagheAbiVasatTale();
SwampLand();
LASTPOS();
if (RedObj2() || BlackObj2() || GreenObj2() || SuperObj() ||
TrapField2())
//|| ((PositionX >= LXGOAL + 25 || PositionX <= LXGOAL - 25
|| PositionY >= LYGOAL + 25 || PositionY <= LYGOAL - 25) && TrapField2()) ||
//ObstacleField2())
{

}
else if (strcmp(halat, "SuperObj") == 0)
{
SearchSobj();
}

else if (strcmp(halat, "DSobj") == 0)


{
Sobj();
}
else if (strcmp(halat, "TurnLeft") == 0)
{
TurnLeft();
}
else if (strcmp(halat, "TurnLeftKam") == 0)
{
TurnLeftKam();
}
else if (strcmp(halat, "TurnRightKam") == 0)
{
TurnRightKam();
}
else if (strcmp(halat, "MoveBackward") == 0)
{
MoveBackward();
}
else if (strcmp(halat, "CheckDepo") == 0)
{
CheckDepo();
}
else if (strcmp(halat, "StopAndCheck") == 0)
{
StopAndCheck();
}
else if (GOTO(XGOAL, YGOAL, PURPOSE))
{
}
else if (strcmp(halat, "adi") == 0)
{
NormalState2();
}
if (Duration == 0)
{
Area();
AreaObj();
}
//FIRSTAREA();
DEPOSITCONDITION();
//////printf("PURPOSE11111: %c\n", PURPOSE);
DETECTSOBJ();
//////printf("PURPOSE2222222: %c\n", PURPOSE);
AreasPosition();
//////printf("PURPOSE333333333: %c\n", PURPOSE);

}
else
{
CompassGoal();
}
}
}
boolean NormalState2()
{
CollectingObjFlag = 0;
if (WARNING() != -1)
{
Cmpideal = eslah(Compass + 180);
CompassGoal();
return true;
}
if (OBJECTISNOTFULL() && (RedObj2() || GreenObj2() || BlackObj2() ||
SuperObj()))
{
return true;
}
//if (IGNOREDAREAS() == 1)
//{
// return true;
//}
if (BorderField2() == 1)
{
////////printf("border detected!\n");
return true;
}
if (TrapField2() == 1)
{
////////printf("trap detected!\n");
return true;
}
//if (StayInColoredAreas(Blue))
//{
// return true;
//}
if (DepoBoxDetected())
{
return true;
}
//if (NotFullObj() == 1)
//{
// return true;
//}
if (ObstacleField2() == 1)
{
////////printf("obstacle detected!\n");
return true;
}
if (Move2() == 1)
{
return true;
}
return false;
}
//Trap & Obstacles & Border
boolean BorderField2()
{
int offset = 15;

if (PositionX != 0 || PositionY != 0)
{

if (Compass <= 90 && PositionY > 270 - offset)


{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
ChangeState("hashiyedidan11111");
ChangeState("adi");
return true;
}
else if (Compass >= 270 && Compass <= 359 && PositionY > 270 - offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
ChangeState("hashiyedidan22222222222");
ChangeState("adi");
return true;
}
else if (Compass >= 270 && Compass <= 359 && PositionX > 360 - offset)
{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
ChangeState("hashiyedidan33333333333");
ChangeState("adi");
return true;
}
else if (Compass >= 180 && Compass < 270 && PositionX > 360 - offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
ChangeState("hashiyedidan444444444444");
ChangeState("adi");
return true;
}
else if (Compass >= 180 && Compass <= 270 && PositionY < offset)
{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
ChangeState("hashiyedidan555555555555555");
ChangeState("adi");
return true;
}
else if (Compass >= 90 && Compass < 180 && PositionY < offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
ChangeState("hashiyedidan66666666666666");
ChangeState("adi");
return true;
}
else if (Compass <= 90 && PositionX < offset)
{
if (US_Left < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
ChangeState("hashiyedidan777777777777");
ChangeState("adi");
return true;
}
else if (Compass >= 90 && Compass < 180 && PositionX < offset)
{
if (US_Right < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
ChangeState("hashiyedidan8888888888888");
ChangeState("adi");
return true;
}
}
return false;
}
boolean TrapField2()
{
if (((Left == yellow3 && Right == yellow3)) && ObjCounter > 0)
{
if (!SignalBlockZone())
{
ACTION(-3, -3, 0, 3);

ChangeState("talledidan");
if (trapcounter == 0)
{
ChangeState("TurnRightKam");
trapcounter++;
}
else
{
ChangeState("TurnLeftKam");
trapcounter = 0;
}
return true;
}
else
{
ACTION(3, -3, 0, 3);
return true;
}
}
else if ((Left == yellow3) && ObjCounter > 0)
{
if (US_Right < 14)
{
ACTION(-1, 3, 0, 2);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
else
{
ACTION(3, -1, 0, 2);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
}
else if ((Right == yellow3) && ObjCounter > 0)
{
if (US_Left < 14)
{
ACTION(3, -1, 0, 2);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
else
{
ACTION(-1, 3, 0, 2);
ChangeState("talledidan");
ChangeState("adi");
return true;
}
}
return false;
}
boolean ObstacleField2()
{
if (US_Front < 15 && US_Right < 15 && US_Left < 15)
{
Cmpideal = eslah(Compass + 180);
CompassGoal();
ChangeState("**********************obs0");
ChangeState("adi");
}
else if (US_Front < 20)
{
if (US_Left < US_Right)
{
if (US_Front > 5)
{
ACTION(3, -2, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
else
{
ACTION(3, -3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
}
else
{
if (US_Front > 5)
{
ACTION(-2, 3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
else
{
ACTION(-3, 3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
}
}
else if (US_Right < 25 && US_Left < 25)
{
ACTION(3, 3, 0, 1);
ChangeState("obs0");
ChangeState("adi");
return true;
}
else if (US_Right < 17)
{
ACTION(1, 3, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
else if (US_Left < 17)
{
ACTION(3, 1, 0, 2);
ChangeState("obs0");
ChangeState("adi");
return true;
}
return false;
}
//objects
boolean RedObj2()
{
if (((ObjCounter< 6 && RedObjCounter2 < 2 && LXGOAL == 0) || (ObjCounter< 5
&& RedObjCounter2 < 2 && LXGOAL != 0)) && PURPOSE != 'S')
//if (((ObjCounter < 4 || (ObjCounter >= 4 && RedObjCounter2 == 0) ||
OneSet() || FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
&& superobjflag == 0) ||
// (RedObjCounter2 < MAX_RED && superobjflag == 1) || (((Time -
fiveTime > 45) || (Time - fourTime > 45)) && superobjflag == 1))

{
if (Left == Red || Right == Red)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
RedObjCounter2++;
ObjCounter++;
fourFlag = 0;
ObjFlag = 0;
fiveFlag = 0;
fiveTime = 1000;
fourTime = 1000;
RedAreaTime = Time;
ChangeState("ganjbardasht");
ChangeState("adi");
return true;
}
}
return false;
}
boolean GreenObj2()
{
if (((ObjCounter< 6 && GreenObjCounter2 < 2 && LXGOAL == 0) || (ObjCounter< 5
&& GreenObjCounter2 < 2 && LXGOAL != 0)) && PURPOSE != 'S')
//if (((ObjCounter < 4 || (ObjCounter >= 4 && GreenObjCounter2 == 0) ||
OneSet() || FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
&& superobjflag == 0) ||
// (GreenObjCounter2 < MAX_GREEN && superobjflag == 1) || (((Time -
fiveTime > 45) || (Time - fourTime > 45)) && superobjflag == 1))
{
if (Left == Green || Right == Green)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
GreenObjCounter2++;
ObjCounter++;
fiveFlag = 0;
ObjFlag = 0;
fourFlag = 0;
fiveTime = 1000;
fourTime = 1000;
GreenAreaTime = Time;
ChangeState("ganjbardasht");
ChangeState("adi");
return true;
}
}
return false;
}
boolean BlackObj2()
{
if (((ObjCounter < 6 && BlackObjCounter2 < 2 && DepositFlag > Depositi &&
LXGOAL == 0) ||
(ObjCounter < 6 && BlackObjCounter2 < 6 && DepositFlag <= Depositi &&
LXGOAL == 0) ||
(ObjCounter < 5 && BlackObjCounter2 < 2 && DepositFlag > Depositi &&
LXGOAL != 0) ||
(ObjCounter < 5 && BlackObjCounter2 < 5 && DepositFlag <= Depositi &&
LXGOAL != 0)) && PURPOSE != 'S')
//if (((ObjCounter < 4 || (ObjCounter >= 4 && BlackObjCounter2 == 0) ||
OneSet() || FiveObjects() || (Time - fiveTime > five) || (Time - fourTime > four))
&& superobjflag == 0) ||
// (BlackObjCounter2 < MAX_BLACK && superobjflag == 1) || (((Time -
fiveTime > 45) || (Time - fourTime > 45)) && superobjflag == 1))
{
if (Left == Black || Right == Black)
{
CollectingObjFlag = 1;
ACTION(0, 0, 1, 50);
BlackObjCounter2++;
ObjCounter++;
fiveFlag = 0;
ObjFlag = 0;
fourFlag = 0;
fiveTime = 1000;
fourTime = 1000;
BlackAreaTime = Time;
ChangeState("ganjbardasht");
ChangeState("adi");
return true;
}
}
return false;
}
boolean SuperObj()
{
if ((Left == SOBJColor || Right == SOBJColor) && PURPOSE != 'S')
{
CollectingObjFlag = 1;
PURPOSE = '-';
ACTION(0, 0, 1, 50);
LXGOAL = 0;
LYGOAL = 0;
ObjCounter++;
PATHSELECTED = 0;
return true;
}
return false;
}
boolean OBJECTISNOTFULL()
{
if (ObjCounter < MAX_OBJECT)
return true;
return false;
}
//Deposit
boolean DEPOSITPOSSIBLE()
{
if (ObjCounter >= ObjsREnough || (ObjCounter > 2 && Time > 420 && Time < 450
&& PURPOSE != 'S') || (ObjCounter > 0 && Time > 450 && PURPOSE != 'S') ||
(RedBlackGreen == 1))
{
return true;
}
return false;
}
boolean MoveBackward()
{
ACTION(-2, -2, 0, 15);
RedAreaTime = Time;
BlackAreaTime = Time;
GreenAreaTime = Time;
ChangeState("TurnLeft");
}
boolean CheckDepo()
{
if (Left == Orange && Right == Orange)
{
PURPOSE = '-';
ACTION(0, 0, 2, 50);
PATHSELECTED = 0;
DepositFlag++;
ObjCounter = 0;
SobjCreater = 0;
GreenObjs = 0;
BlackObjs = 0;
RedObjs = 0;
GreenRedObjs = 0;
BlackRedObjs = 0;
BlackGreenObjs = 0;
superobjflag = 0;
GreenObjCounter2 = 0;
BlackObjCounter2 = 0;
RedObjCounter2 = 0;
//if (DepositFlag < 2)
//{
// for (int a = 1; a < n; a++)
// {
// AreaArray[4][a] = 0;
// BlackObjFlag = 0;
// ////////////printf("AreaArray%d\n", AreaArray[4][a]);
// ////////////printf("khalishod%d,number%d\n\n\n\n",
AreaArray[4][a], a);
// }
//}
//else
//{
if (DepositFlag % 2 == 1 || RedBlackGreen == 1)
{
for (int a = 1; a < n; a++)
{
AreaArray[4][a] = 0;
BlackObjFlag = 0;
////////////printf("AreaArray%d\n", AreaArray[4][a]);
////////////printf("khalishod%d,number%d\n\n\n\n",
AreaArray[4][a], a);
}
RedBlackGreen = 0;
}
ChangeState("MoveBackward");

}
else
{
ChangeState("adi");
}
}
boolean StopAndCheck()
{
if (DEPOSITPOSSIBLE() && Left == Orange && Right == Orange)
{
ATFIRST = 1;
ACTION(0, 0, 0, 5);
ChangeState("CheckDepo");
return true;
}
else
{
ChangeState("adi");
}
return false;
}
boolean bothSensorDepoBoxField2()
{
if (DEPOSITPOSSIBLE() && Left == Orange && Right == Orange)
{
ACTION(1, 1, 0, 3);
ChangeState("StopAndCheck");
return true;
}
return false;
}
boolean oneSensorDepoBoxField2()
{
if (DEPOSITPOSSIBLE() && Left == Orange)
{
ACTION(0, 2, 0, 0);
ChangeState("chapdid");
ChangeState("adi");
return true;
}
else if (DEPOSITPOSSIBLE() && Right == Orange)
{
ACTION(2, 0, 0, 0);
ChangeState("leftdid");
ChangeState("adi");
return true;
}
return false;
}
boolean DepoBoxDetected()
{
if ((/*(PositionX > 259 - DPSPAN && PositionX < 259 + DPSPAN && PositionY >
196 - DPSPAN && PositionY < 196 + DPSPAN) ||*/
//(PositionX > 137 - DPSPAN && PositionX < 137 + DPSPAN && PositionY >
200 - DPSPAN && PositionY < 200 + DPSPAN) ||
//(PositionX > 70 - DPSPAN && PositionX < 70 + DPSPAN && PositionY >
145 - DPSPAN && PositionY < 145 + DPSPAN) ||
//(PositionX > 313 - DPSPAN && PositionX < 313 + DPSPAN && PositionY >
131 - DPSPAN && PositionY < 131 + DPSPAN) ||
(PositionX > 23 - DPSPAN && PositionX < 23 + DPSPAN && PositionY > 242
- DPSPAN && PositionY < 242 + DPSPAN))
&& (DEPOSITPOSSIBLE() || DepositBoxPurpose == 1))
{
if (DepositBoxPurpose == 1 && (Left == Orange || Right == Orange) &&
PositionX > position[0][ENDPOINT(disminex)] - DPSPAN && PositionX
< position[0][ENDPOINT(disminex)] + DPSPAN &&
PositionY > position[1][ENDPOINT(disminex)] - DPSPAN && PositionY
< position[1][ENDPOINT(disminex)] + DPSPAN)
{
DepositBoxPurpose = 0;
sobjpurpose = 0;
CollectSobj = 1;
PATHSELECTED = 0;
}
if (DEPOSITPOSSIBLE() && bothSensorDepoBoxField2())
{
return true;
}
if (DEPOSITPOSSIBLE() && oneSensorDepoBoxField2())
{
return true;
}
}
ChangeState("adi");
return false;
}
void DEPOSITCONDITION()
{
if (PURPOSE == 'D')
{
return true;
}
if (DEPOSITPOSSIBLE() ||
DepositBoxPurpose == 1)
{
PURPOSE = 'D';
WELLTIMER = MAX_TIME;
for (int w = 1; w < MAX_PATH; w++)
{
Side1 = position[0][w] - PositionX;
Side2 = position[1][w] - PositionY;
Side3 = Side1 * Side1 + Side2 * Side2;
position[2][w] = sqrt(Side3);
}
dismin = INT_MAX;
disminex = 0;
for (int s = 1; s < MAX_PATH; s++)
{
if (position[0][s] != -1 && isViewable(position[0][s],
position[1][s]))
{
int endp = s;
while (position[4][endp] != 1000)
{
endp = position[4][endp];
}
if (add[s][endp] != -1 && (position[2][s] + abs(add[s]
[endp]))<dismin)
{
dismin = (position[2][s] + abs(add[s][endp]));
disminex = s;
}
}
}
XGOAL = position[0][disminex];
YGOAL = position[1][disminex];
if (disminex == 0)
{
PURPOSE = '-';
}
else
PATHSELECTED = 1;

}
}
//Signal Block Zone
boolean SignalBlockZone()
{
if (RPOSX == 0 && RPOSY == 0)
return true;
return false;
}
void Zero()
{
if (!SignalBlockZone())
{
LastPositionX = PositionX;
LastPositionY = PositionY;
}
if (!SignalBlockZone())
WasteTime = 0;
Restricted();
if (SignalBlockZone() && CALCPOSFLAG)
{
CalculatePath();
////////printf("path111111111111---------%f\n", Path);
NoSignal();
}
}
void Restricted()
{
if (SignalBlockZone() && RestrictedFlag == 0)
{
STOPFLAG = false;
CALCPOSFLAG = true;
T1st = clock();
LastPositionX1st = LastPositionX;
LastPositionY1st = LastPositionY;
RestrictedFlag = 1;
LGameTime = GameTime;
}
else if (!SignalBlockZone() && RestrictedFlag == 1)
{
T2nd = clock();
LastPositionX2nd = PositionX;
LastPositionY2nd = PositionY;
RestrictedFlag = 0;
Path = 0;
CalculateSpeed();
}
}
void CalculateSpeed()
{
T3rd = T2nd - T1st;
TimeFluxion = (float)T3rd / CLOCKS_PER_SEC;
PositionFluxionX = abs(LastPositionX2nd - LastPositionX1st);
PositionFluxionY = abs(LastPositionY2nd - LastPositionY1st);
PositionFluxion = sqrt((PositionFluxionX * PositionFluxionX) +
(PositionFluxionY * PositionFluxionY));
v = PositionFluxion / (float)TimeFluxion;
}
void CalculatePath()
{
GameTime = clock();
if ((((float)GameTime / CLOCKS_PER_SEC) - (float)LGameTime / CLOCKS_PER_SEC)
> 1)
{
StartTime();
StopTime();
}
else
{
if (bati == 0)
Path = (((float)GameTime / CLOCKS_PER_SEC) - (float)T1st /
CLOCKS_PER_SEC) * 35;
if (bati == 1)
Path = (((float)GameTime / CLOCKS_PER_SEC) - (float)T1st /
CLOCKS_PER_SEC) * 9;
LGameTime = GameTime;

}
////////printf("path2222222222----------%f\n", Path);
}
void NoSignal()
{
if (Compass < 180 && Compass != 0 && Compass != 90)
{
Beta = (abs(Compass - 90)) * 3.14 / 180;
YSide = abs(Path * sin(Beta));
XSide = abs(Path * cos(Beta));
if (Compass < 90 && Compass > 0)
{
Positionx = LastPositionX - XSide;
Positiony = LastPositionY + YSide;
}
else if (Compass < 180 && Compass > 90)
{
Positionx = LastPositionX - XSide;
Positiony = LastPositionY - YSide;
}
}
else if (Compass > 180 && Compass != 360 && Compass != 270)
{
Beta = (abs(Compass - 270)) * 3.14 / 180;
YSide = abs(Path * sin(Beta));
XSide = abs(Path * cos(Beta));
if (Compass < 270 && Compass > 180)
{
Positionx = LastPositionX + XSide;
Positiony = LastPositionY - YSide;
}
else if (Compass < 360 && Compass > 270)
{
Positionx = LastPositionX + XSide;
Positiony = LastPositionY + YSide;
}
}
else if (Compass == 0 || Compass == 360)
{

Positionx = LastPositionX;
Positiony = LastPositionY + Path;
}
else if (Compass == 180)
{

Positionx = LastPositionX;
Positiony = LastPositionY - Path;
}
else if (Compass == 90)
{

Positionx = LastPositionX - Path;


Positiony = LastPositionY;
}
else if (Compass == 270)
{

Positionx = LastPositionX + Path;


Positiony = LastPositionY;
}
}
void StartTime()
{
if (SignalBlockZone() && STOPFLAG == 0)
{
STOPFLAG = 1;
CALCPOSFLAG = 0;
}
}
void StopTime()
{
if (SignalBlockZone() && STOPFLAG == 1)
{
CALCPOSFLAG = 1;
LastPositionX = Positionx;
LastPositionY = Positiony;
T1st = clock();
Path = 0;
STOPFLAG = 0;
Stop = clock();
WasteTime = Stop - Start + WasteTime;
RestrictedFlag3 = 0;
LGameTime = GameTime;
}
}
boolean LASTPOS()
{

if (LASTTIME + 2 == Time)
{
LASTTIMEFLAG = 0;
}
if (LASTTIMEFLAG == 0)
{
LASTTIME = Time;
LASTPOSITION_X = PositionX;
LASTPOSITION_Y = PositionY;
LASTTIMEFLAG = 1;

}
//Areas
boolean Area()
{
//black = 0
//red = 1
//green = 2
if (ArrayFlag == 0)
{
AreaArray[0][1] = 231;
AreaArray[1][1] = 191;
AreaArray[2][1] = 2;
AreaArray[4][1] = 0;
AreaArray[5][1] = 169;
AreaArray[6][1] = 293;
AreaArray[7][1] = 158;
AreaArray[8][1] = 224;
AreaArray[0][2] = 53;
AreaArray[1][2] = 191;
AreaArray[2][2] = 1;
AreaArray[4][2] = 0;
AreaArray[5][2] = 5;
AreaArray[6][2] = 101;
AreaArray[7][2] = 159;
AreaArray[8][2] = 223;
AreaArray[0][3] = 54;
AreaArray[1][3] = 119;
AreaArray[2][3] = 0;
AreaArray[4][3] = 0;
AreaArray[5][3] = 6;
AreaArray[6][3] = 101;
AreaArray[7][3] = 92;
AreaArray[8][3] = 146;
AreaArray[0][4] = 146;
AreaArray[1][4] = 30;
AreaArray[2][4] = 2;
AreaArray[4][4] = 0;
AreaArray[5][4] = 44;
AreaArray[6][4] = 248;
AreaArray[7][4] = 1;
AreaArray[8][4] = 60;
AreaArray[0][5] = 146;
AreaArray[1][5] = 30;
AreaArray[2][5] = 1;
AreaArray[4][5] = 0;
AreaArray[5][5] = 43;
AreaArray[6][5] = 248;
AreaArray[7][5] = 1;
AreaArray[8][5] = 60;
ArrayFlag = 1;
}
if ((PURPOSE != '-' && PURPOSE != 'Z'))
{

//printf("___________________#swqddddddddddddddddddddddddd\n");
RedAreaTime = Time;
BlackAreaTime = Time;
GreenAreaTime = Time;
}
if (PURPOSE != '-' && PURPOSE != 'E' && PURPOSE != 'Z')
{
return true;

}
if (PURPOSE == 'E' && ((AreaArray[2][Adisminex] == bO && BlackObjCounter2 >=
2) || (AreaArray[2][Adisminex] == gO && GreenObjCounter2 >= 2) || (AreaArray[2]
[Adisminex] == rO && RedObjCounter2 >= 2)))
{
PURPOSE = '-';
}
int timy = 15;
for (int a = 1; a < n; a++)
{
if (AreasFlags == a)
{
if ((AreaArray[2][a] == bO && BlackObjCounter2 < 2 && Time -
BlackAreaTime >= timy && DepositFlag > Depositi) ||
(AreaArray[2][a] == bO && BlackObjCounter2 < 6 && Time -
BlackAreaTime >= timy && DepositFlag <= Depositi))
{
AreaArray[4][a] = 1;
BlackObjFlag = 1;
////////////printf("1111111111111111111111\n");
}
else if (AreaArray[2][a] == gO && GreenObjCounter2 < 2 && Time -
GreenAreaTime >= timy && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
AreaArray[4][a] = 1;
////////////printf("222222222222222222222\n");
}
else if (AreaArray[2][a] == rO && RedObjCounter2 < 2 && Time -
RedAreaTime >= timy && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
AreaArray[4][a] = 1;
////////////printf("3333333333333333333333\n");
}
////////////printf("porshode%d,number%d\n\n\n\n", AreaArray[4]
[a], a);
}
}
for (int a = 1; a < n; a++)
{
if (AreasFlags == a)
{
if ((AreaArray[2][a] == bO && BlackObjCounter2 < 2 &&
AreaArray[4][a] == 0 && DepositFlag > Depositi) ||
(AreaArray[2][a] == bO && BlackObjCounter2 < 6 &&
AreaArray[4][a] == 0 && DepositFlag <= Depositi))
{
if (PURPOSE == 'E')
{
PATHSELECTED = 0;
PURPOSE = '-';
}
DontLeaveArea(AreaArray[5][a], AreaArray[6][a],
AreaArray[7][a], AreaArray[8][a]);
////////////printf("444444444444444444444\n");
}
else if (AreaArray[2][a] == gO && GreenObjCounter2 < 2 &&
AreaArray[4][a] == 0 && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
if (PURPOSE == 'E')
{
PATHSELECTED = 0;
PURPOSE = '-';
}
DontLeaveArea(AreaArray[5][a], AreaArray[6][a],
AreaArray[7][a], AreaArray[8][a]);
////////////printf("5555555555555555555555\n");
}
else if (AreaArray[2][a] == rO && RedObjCounter2 < 2 &&
AreaArray[4][a] == 0 && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
if (PURPOSE == 'E')
{
PATHSELECTED = 0;
PURPOSE = '-';
}
DontLeaveArea(AreaArray[5][a], AreaArray[6][a],
AreaArray[7][a], AreaArray[8][a]);
////////////printf("66666666666666666666666666\n");
}
}
}
int not = 0;
for (int a = 1; a < n; a++)
{
if (BigAreasFlags == a)
{
if ((AreaArray[2][a] == bO && BlackObjCounter2 < 2 &&
AreaArray[4][a] == 0 && DepositFlag > Depositi) ||
(AreaArray[2][a] == bO && BlackObjCounter2 < 6 &&
AreaArray[4][a] == 0 && DepositFlag <= Depositi))
{
AreaFlag = 1;
not = 1;
////////////printf("77777777777777777777777777777777\n");
}
else if (AreaArray[2][a] == gO && GreenObjCounter2 < 2 &&
AreaArray[4][a] == 0 && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
AreaFlag = 1;
not = 1;
////////////printf("888888888888888888888888888888888\n");
}
else if (AreaArray[2][a] == rO && RedObjCounter2 < 2 &&
AreaArray[4][a] == 0 && (DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1)))
{
AreaFlag = 1;
not = 1;
////////////printf("9999999999999999999999999999\n");
}
}
}
if (not == 0)
{

AreaFlag = 0;
////////////printf("11111111000000000000000000000000000000000000\n");
}
return false;
}
void AreasPosition()
{ //black = 0
//red = 1
//green = 2
//&& ((BlackObjCounter2 < 2 && AreaArray[4][] == 0 && DepositFlag > Depositi)
|| (BlackObjCounter2 < 6 && AreaArray[4][] == 0 && DepositFlag <= Depositi))
//&& GreenObjCounter2 < 2 && AreaArray[4][] == 0 && (DepositFlag > Depositi
|| (DepositFlag <= Depositi && BlackObjFlag == 1))
//&& RedObjCounter2 < 2 && AreaArray[4][] == 0 && (DepositFlag > Depositi ||
(DepositFlag <= Depositi && BlackObjFlag == 1))

if (PositionX > 169 && PositionX < 293 && PositionY > 158 && PositionY < 224)
{ AreasFlags = 1; }
else if (PositionX > 5 && PositionX < 101 && PositionY > 159 && PositionY <
223){ AreasFlags = 2; }
else if (PositionX > 6 && PositionX < 101 && PositionY > 92 && PositionY <
146){ AreasFlags = 3; }
else if (PositionX > 44 && PositionX < 248 && PositionY > 1 && PositionY < 60
&& GreenObjCounter2 < 2 && AreaArray[4][4] == 0 && (DepositFlag > Depositi ||
(DepositFlag <= Depositi && BlackObjFlag == 1))){ AreasFlags = 4; }
else if (PositionX > 43 && PositionX < 248 && PositionY > 1 && PositionY < 60
&& RedObjCounter2 < 2 && AreaArray[4][5] == 0 && (DepositFlag > Depositi ||
(DepositFlag <= Depositi && BlackObjFlag == 1))){ AreasFlags = 5; }
else { AreasFlags = 0; }
int brange = 10;
if (PositionX > 169 - brange && PositionX < 293 + brange && PositionY > 158 -
brange && PositionY < 224 + brange) { BigAreasFlags = 1; }
else if (PositionX > 5 - brange && PositionX < 101 + brange && PositionY >
159 - brange && PositionY < 223 + brange) { BigAreasFlags = 2; }
else if (PositionX > 6 - brange && PositionX < 101 + brange && PositionY > 92
- brange && PositionY < 146 + brange) { BigAreasFlags = 3; }
else if (PositionX > 44 - brange && PositionX < 248 + brange && PositionY > 1
- brange && PositionY < 60 + brange&& GreenObjCounter2 < 2 && AreaArray[4][4] == 0
&& (DepositFlag > Depositi || (DepositFlag <= Depositi && BlackObjFlag == 1)))
{ BigAreasFlags = 4; }
else if (PositionX > 43 - brange && PositionX < 248 + brange && PositionY > 1
- brange && PositionY < 60 + brange&& RedObjCounter2 < 2 && AreaArray[4][5] == 0 &&
(DepositFlag > Depositi || (DepositFlag <= Depositi && BlackObjFlag == 1)))
{ BigAreasFlags = 5; }
else { BigAreasFlags = 0; }
}
void AreaObj()
{
Blackk = true;
Greenn = true;
Redd = true;
for (int c = 1; c < n; c++)
{
//printf("rang%d\n", AreaArray[2][c]);
if (AreaArray[2][c] == bO)
{
Blackk = Blackk & AreaArray[4][c];
//printf("blacki%d\n", AreaArray[4][c]);
//printf("Blackkkkkkkkkkkkkkkkkkkkkkk%d\n", Blackk);
}
else if (AreaArray[2][c] == gO)
{
Greenn = Greenn & AreaArray[4][c];
//printf("greeni%d\n", AreaArray[4][c]);
//printf("Greennnnnnnnnnnnnnnnnnnn%d\n", Greenn);
}
else if (AreaArray[2][c] == rO)
{
Redd = Redd & AreaArray[4][c];
//printf("redi%d\n", AreaArray[4][c]);
//printf("Reddddddddddddddddddddddddddddddddddddd%d\n", Redd);
}
}
if (SobjCreater == 1 && ObjCounter == 5 && ((Blackk == true &&
BlackObjCounter2 == 1) || (Redd == true && RedObjCounter2 == 1) || (Greenn == true
&& GreenObjCounter2 == 1)))
{
if (Blackk == 1 && BlackObjs == 0)
{
if (GreenObjCounter2 == 2 && RedObjCounter2 == 1)
{
BlackObjs = 1;
RedObjCounter2 += (BlackObjCounter2 - 2);
}
else if (GreenObjCounter2 == 1 && RedObjCounter2 == 2)
{
BlackObjs = 1;
GreenObjCounter2 += (BlackObjCounter2 - 2);
}
////////////printf("11111111111111111111111111111111111111111111\
n\n\n\n\n");
}
if (Greenn == 1 && GreenObjs == 0)
{
if (BlackObjCounter2 == 2 && RedObjCounter2 == 1)
{
GreenObjs = 1;
RedObjCounter2 += (GreenObjCounter2 - 2);
}
else if (BlackObjCounter2 == 1 && RedObjCounter2 == 2)
{
GreenObjs = 1;
BlackObjCounter2 += (GreenObjCounter2 - 2);
}
////////////printf("2222222222222222222222222222222222222222222\
n\n\n\n\n");
}
if (Redd == 1 && RedObjs == 0)
{
if (GreenObjCounter2 == 2 && BlackObjCounter2 == 1)
{
RedObjs = 1;
BlackObjCounter2 += (RedObjCounter2 - 2);
}
else if (GreenObjCounter2 == 1 && BlackObjCounter2 == 2)
{
RedObjs = 1;
GreenObjCounter2 += (RedObjCounter2 - 2);
}

////////////printf("33333333333333333333333333333333333333333333333333\n\n\n\
n\n");
}
if (Redd == 1 && Greenn == 1 && Blackk == 1)
{
RedBlackGreen = 1;
}
}
else
{

////////////printf("_______________________________________________________________
\n\n\n");
////////////printf("Blackkkk2222222222222222222222222222222%d\n",
Blackk);
////////////printf("Reddddd2222222222222222222222222222222%d\n", Redd);
if (Blackk == 1 && BlackObjs == 0)
{
if ((DepositFlag > Depositi || (DepositFlag <= Depositi &&
BlackObjFlag == 1 && BlackObjCounter2 > 3)))
{
BlackObjs = 1;
GreenObjCounter2 += (BlackObjCounter2 - 2);
//printf("1111----------------------------\n\n\n\n\n");
}
}
if (Greenn == 1 && GreenObjs == 0)
{
GreenObjs = 1;
BlackObjCounter2 += (GreenObjCounter2 - 2);

////////////printf("2222222222222222--------------------------------\n\n\n\n\
n");
}
if (Redd == 1 && RedObjs == 0)
{
RedObjs = 1;
BlackObjCounter2 += (RedObjCounter2 - 2);
////////////printf("3333333333---------------------------\n\n\n\
n\n");
}
if (Blackk == 1 && Redd == 1)
{
GreenObjCounter2 = -4;
////////////printf("4444444444444444-----------------------\n\n\
n\n\n");
}
if (Greenn == 1 && Redd == 1)
{
BlackObjCounter2 = -4;
////////////printf("5555555555555555------------------------\n\n\
n\n\n");
}
if (Blackk == 1 && Greenn == 1)
{
RedObjCounter2 = -4;

////////////printf("66666666666666-------------------------------\n\n\n\n\
n");
}
if (Redd == 1 && Greenn == 1 && Blackk == 1)
{
RedBlackGreen = 1;
}
}

}
int NearestArea()
{
if (PURPOSE != '-' && PURPOSE != 'Z')
return true;
if (AreaFlag == 0)
{
for (int x = 1; x < n; x++)
{
////////////printf("nnnnnnnnnnnnn__________________________________________________
________%d\n", x);
////////////printf("AreaArray[0][x]%d\n", AreaArray[0][x]);
////////////printf("AreaArray[1][x]%d\n", AreaArray[1][x]);
startcounterareas[x] = 0;
for (int a = 1; a < MAX_PATH; a++)
{
////////////printf("AreaArray[0]
[x]2222222222222222222222222222222222222%d\n", AreaArray[0][x]);
////////////printf("AreaArray[1]
[x]2222222222222222222222222222222222222%d\n", AreaArray[1][x]);
////////////printf("position[0][a]%d\n", position[0][a]);
////////////printf(" position[1][a]%d\n", position[1][a]);
if (position[0][a] != -1 && isViewable4(AreaArray[0][x],
AreaArray[1][x], position[0][a], position[1][a]))
{
ViewedFromStartAreas[x][startcounterareas[x]] = a;
startcounterareas[x]++;
////////////printf("ViewedFromStartAreas = %d x = %d,
y = %d,num= %d\n", a, position[0][a], position[1][a], x);
}

}
////////////printf("startcounterareas[x]%d\n",
startcounterareas[x]);
}

endcounter = 0;
for (int z = 1; z < MAX_PATH; z++)
{
if (position[0][z] != -1 && isViewable4(PositionX, PositionY,
position[0][z], position[1][z]))
{
ViewedFromEndArea[endcounter] = z;
endcounter++;
////////////printf("ViewedFromEndArea = %d x = %d, y =
%d\n", z, position[0][z], position[1][z]);
}

}
//////////////printf("positionx%d,positiony%d\n", PositionX,
PositionY);
//////////////printf("endcounter%d\n", endcounter);
for (int r = 1; r < n; r++)
{
for (int e = 0; e < startcounterareas[r]; e++)
{
SideAA1 = AreaArray[0][r] - position[0]
[ViewedFromStartAreas[r][e]];
SideAA2 = AreaArray[1][r] - position[1]
[ViewedFromStartAreas[r][e]];
SideAA3[r][e] = sqrt(SideAA1 * SideAA1 + SideAA2 *
SideAA2);
int b = SideAA3[r][e];
////////////printf("SideAA3[r][e]%d,number%d\n", b, r);
}
}
for (int ed = 0; ed < endcounter; ed++)
{
SidePP1 = position[0][ViewedFromEndArea[ed]] - PositionX;
SidePP2 = position[1][ViewedFromEndArea[ed]] - PositionY;
SidePP3[ed] = sqrt(SidePP1 * SidePP1 + SidePP2 * SidePP2);
////////////printf("SidePP3[p]%d\n", SidePP3[ed]);
}
for (int i = 1; i < n; i++)
{
Ndismin[i] = INT_MAX;
Ndisminex[i] = -1;
for (int s = 0; s < startcounterareas[i]; s++)
{
for (int e = 0; e < endcounter; e++)
{

if (add[ViewedFromEndArea[e]][ViewedFromStartAreas[i]
[s]] != -1)
{
////////////printf("PATH FOUNDED -> e=%d s=%d
dist=%d,number=%d\n", ViewedFromEndArea[e], ViewedFromStartAreas[i][s],
abs(add[ViewedFromEndArea[e]][ViewedFromStartAreas[i][s]]) + SidePP3[e] +
SideAA3[i][s], i);
////////////printf("distanceadd= %d, disEnd= %d
, DisStart = %d, Num%d\n", abs(add[ViewedFromEndArea[e]][ViewedFromStartAreas[i]
[s]]), SidePP3[e], SideAA3[i][s], i);
if (abs(add[ViewedFromEndArea[e]]
[ViewedFromStartAreas[i][s]]) + SideAA3[i][s] + SidePP3[e] < Ndismin[i])
{

Ndismin[i] =
abs(add[ViewedFromEndArea[e]][ViewedFromStartAreas[i][s]]) + SideAA3[i][s] +
SidePP3[e];
Ndisminex[i] = ViewedFromStartAreas[i]
[s];
int a = Ndisminex[i];
}
}
}

}
}
Adismin = INT_MAX;
Adisminex = -1;
for (int bb = 1; bb < n; bb++)
{

////////////printf("forrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n\n");
////////////printf("AreaArray %d\n", AreaArray[2][bb]);
////////////printf("BlackObjCounter2 %d\n", BlackObjCounter2);
////////////printf("DepositFlag %d\n", DepositFlag);
if (Ndismin[bb] < Adismin)
{
if (((AreaArray[2][bb] == bO && BlackObjCounter2 < 2 &&
DepositFlag > Depositi) ||
(AreaArray[2][bb] == bO && BlackObjCounter2 < 6 &&
DepositFlag <= Depositi) ||
(AreaArray[2][bb] == rO && RedObjCounter2 < 2 &&
(DepositFlag > Depositi || (DepositFlag <= Depositi && BlackObjFlag == 1))) ||
(AreaArray[2][bb] == gO && GreenObjCounter2 < 2 &&
(DepositFlag > Depositi || (DepositFlag <= Depositi && BlackObjFlag == 1)))) &&
AreaArray[4][bb] == 0)
{
Adismin = Ndismin[bb];
Adisminex = bb;
////////////printf("heyyyyyyyyyyyyyyyyyyyyyyyyyy\n");
}
}
//////////////printf("sssssssssssssssssssssssssssssssssss\n\n\
n");
}
if (Adisminex != -1)
{
PURPOSE = 'E';
PATHSELECTED = 0;
////////////printf("AreaArray[0][Adisminex]%d\n", AreaArray[0]
[Adisminex]);
////////////printf("AreaArray[1][Adisminex]%d\n", AreaArray[1]
[Adisminex]);
stend(PositionX, PositionY, AreaArray[0][Adisminex], AreaArray[1]
[Adisminex]);
}
}
}
//Areas search
boolean CircleSearch()
{
if (AreasFlags == 1 && BlackObjCounter2 < 2 && Time - BlackAreaTime < 25)
{
csearch(52, 233);
return true;
}
else if (AreasFlags == 4 && RedObjCounter2 < 2 && Time - RedAreaTime < 25)
{
csearch(186, 133);
return true;
}
else if (AreasFlags == 5 && BlackObjCounter2 < 2 && Time - BlackAreaTime <
25)
{
csearch(178, 32);
return true;
}
else if (AreasFlags == 6 && BlackObjCounter2 < 2 && Time - BlackAreaTime <
25)
{
csearch(186, 133);
return true;
}
else if (AreasFlags == 8 && GreenObjCounter2 < 2 && Time - GreenAreaTime <
25)
{
csearch(52, 233);
return true;
}
else if (AreasFlags == 9 && RedObjCounter2 < 2 && Time - RedAreaTime < 25)
{
csearch(52, 233);
return true;
}
}
boolean ZigZagSearch()
{
if (AreasFlags == 2 && GreenObjCounter2 < 2 && Time - GreenAreaTime < 25)
{
zigzag(4, 126, 224, 10, 220);
return true;
}
//else if (AreasFlags == 3 && GreenObjCounter2 < 2 && Time - GreenAreaTime <
25)
//{
// zigzag(5, 15, 187, 8, 14);
// return true;
//}
//else if (AreasFlags == 4 && BlackObjCounter2 < 2 && Time - BlackAreaTime <
25 && Znumber != 9)
//{
// zigzag(8, 283, 340, 16, 16);
// return true;
//}
return false;
}
boolean zigzag(int number, int x1, int x2, int y1, int y2)
{
if (PURPOSE != '-')
return true;
if (PATHSELECTED == 0)
{
for (int i = 1; i < number + 1; i++)
{
if (i % 2 == 0)
{
ZArray[0][i] = x1;
}
else
{
ZArray[0][i] = x2;
}
ZArray[1][i] = (i*y1) + y2;
}
XGOAL = ZArray[0][1];
YGOAL = ZArray[1][1];
Znumber = 1;
ZXGOAL = ZArray[0][number];
ZYGOAL = ZArray[1][number];

PURPOSE = 'Z';
}
if (Znumber = number)
{
Znumber = 1;
}
}
boolean csearch(int x, int y)
{
//////////////////////////////printf("wheelleft%d\n", WheelLeft);
//////////////////////////////printf("wheelright%d\n", WheelRight);
//////////////////////////////printf("searchtime%d\n", searchtime);
int sSpan = 8;
if (PositionX > x - sSpan && PositionX < x + sSpan && PositionY > y - sSpan
&& PositionY < y + sSpan && stop1 == 0)
{
stop1 = 1;
searchtime = clock();
}
if (stop1 == 1)
{
if (clock() - searchtime <= 800)
{
ACTION(4, -2, 0, 0);
}
else if (clock() - searchtime <= 5000)
{
ACTION(4, 0, 0, 0);
}
else if (clock() - searchtime <= 7000)
{
ACTION(5, 2, 0, 0);
}
else if (clock() - searchtime <= 15000)
{
ACTION(5, 3, 0, 0);
}
else if (clock() - searchtime <= 20000)
{
ACTION(5, 3, 0, 0);
}

}
}
//Ignored Areas
boolean IGNOREDAREAS()
{
int IgnoredSpan = 3;
int IgnoredArray[4][IgnoredFlag] = { 190, 34, 290, 134 };

int ignori = 0;
if (PURPOSE == '-')
{
for (int a = 0; a < IgnoredFlag; a++)
{

if (PositionX > IgnoredArray[0][a] && PositionX < IgnoredArray[2]


[a] && PositionY > IgnoredArray[1][a] && PositionY < IgnoredArray[3][a])
{

//////printf("_____________________________________________________________________
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP\n");
//////printf("ignori%d\n", IGNORI);
//////printf("IGNOREDAREASFLAG%d\n", IGNOREDAREASFLAG);
if (IGNORI > 7)
{
IGNOREDAREASFLAG = 1;
}
if (PositionX > IgnoredArray[0][a] && PositionX <
IgnoredArray[2][a] && PositionY > IgnoredArray[1][a] && PositionY < IgnoredArray[3]
[a])
{
IGNORI++;
}
if (PositionX > IgnoredArray[0][a] && PositionX <
IgnoredArray[2][a] && PositionY > IgnoredArray[1][a] && PositionY < IgnoredArray[3]
[a] && IGNOREDAREASFLAG == 0)
{
if (PositionX < IgnoredArray[0][a] + IgnoredSpan)
{
if (Compass > 270)
{
ACTION(-4, -1, 0, 15);
return true;
}
else
{
ACTION(-1, -4, 0, 15);
return true;
}
}
else if (PositionX > IgnoredArray[2][a] -
IgnoredSpan)
{
if (Compass < 90)
{
ACTION(-1, -4, 0, 15);
return true;
}
else
{
ACTION(-4, -1, 0, 15);
return true;
}
}
else if (PositionY < IgnoredArray[1][a] +
IgnoredSpan)
{
if (Compass < 90)
{
ACTION(-4, -1, 0, 15);
return true;
}
else
{
ACTION(-1, -4, 0, 15);
return true;
}
}
else if (PositionY > IgnoredArray[3][a] -
IgnoredSpan)
{
if (Compass < 180)
{
ACTION(-1, -4, 0, 15);
return true;
}
else
{
ACTION(-4, -1, 0, 15);
return true;
}
}

}
//////////////////////printf("aaa %d\n", aaa);
//////////////////////printf("IGNOREDAREASFLAG %d\n",
IGNOREDAREASFLAG);
ignori = 1;
}
}
if (ignori == 0)
{
IGNOREDAREASFLAG = 0;
IGNORI = 0;
}

}
return false;
}
//Move
boolean Move2()
{
if (SlowdownCondition() || TrapsArea())
{
ACTION(3, 3, 0, 0);
return true;
}
else
{
ACTION(5, 5, 0, 0);
return true;
}
return true;
}
boolean SlowdownCondition()
{
int offset = 30;
int up = 0;
int left = 90;
int down = 180;
int right = 270;
int little = 5;
int MINX = 0 + offset;
int MAXX = 360 - offset;
int MINY = 0 + offset;
int MAXY = 270 - offset;

if (PositionX != 0 && PositionY != 0)


{
if (Compass <= 90 - little && PositionY > MAXY)
{
return true;
}
else if (Compass >= 270 + little && PositionY > MAXY)
{
return true;
}
else if (Compass >= 270 && Compass < 360 - little && PositionX > MAXX)
{
return true;
}
else if (Compass >= 180 + little && Compass < 270 && PositionX > MAXX)
{
return true;
}
else if (0 + little <= Compass && Compass <= 90 && PositionX < MINX)
{
return true;
}
else if (Compass >= 90 && Compass < 180 - little && PositionX < MINX)
{
return true;
}
else if (Compass >= 90 + little && Compass < 180 && PositionY < MINY)
{
return true;
}
else if (Compass >= 180 && Compass <= 270 - little && PositionY < MINY)
{
return true;
}
}
return false;
}
boolean TrapsArea()
{

int TrapArray[4][TrapFlag] = { 16, 0, 37, 105, 106, 109, -33, 15, 25, 25, 98,
167, 86, 44, 107, 180, 182, 179, 36, 100, 95, 96, 168, 237 };
for (int a = 0; a < TrapFlag; a++)
{
if (PositionX > TrapArray[0][a] && PositionX < TrapArray[2][a] &&
PositionY > TrapArray[1][a] && PositionY < TrapArray[3][a])
{
return true;
}
}
return false;
}
//be in Areas
boolean StayInColoredAreas(char color)
{
if (ColourCounter > 2)
{
//////printf("aaaaaaaaaaaaaaa");
colorflag = 0;
}
if (Left == color || Right == color)
{
//////printf("BBBBBBBBBBBBBBBBBBBB\n");
colorflag = 1;
ColourCounter = 0;
}
else if (colorflag == 1 && (Left != color || Right != color))
{
ColourCounter++;
if (Left != color && Right != color)
{
ACTION(-3, -3, 0, 8);
//if (colorcounterii == 0)
//{
ChangeState("TurnRightKam");
// colorcounterii++;
//}
//else
//{
// ChangeState("TurnLeftKam");
// colorcounterii = 0;
//}
return true;
}
else if (Left != color)
{
ACTION(3, -2, 0, 0);
return true;
}
else if (Right != color)
{
ACTION(-2, 3, 0, 0);
return true;
}

}
return false;

}
boolean DontLeaveArea(int minx, int maxx, int miny, int maxy)
{
int offset = 15;

if (bironcon < 50)


{

if (Compass <= 90 && PositionY > maxy - offset)


{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
return true;
}
else if (Compass >= 270 && Compass <= 359 && PositionY > maxy - offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
return true;
}
else if (Compass >= 270 && Compass <= 359 && PositionX > maxx - offset)
{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
return true;
}
else if (Compass >= 180 && Compass < 270 && PositionX > maxx - offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
return true;
}
else if (Compass >= 180 && Compass <= 270 && PositionY < miny + offset)
{
if (US_Left < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
return true;
}
else if (Compass >= 90 && Compass < 180 && PositionY < miny + offset)
{
if (US_Right < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
return true;
}
else if (Compass <= 90 && PositionX < minx + offset)
{
if (US_Left < 20)
ACTION(-2, 2, 0, 7 * (SwampSpeed));
else
ACTION(2, -2, 0, 1);
return true;
}
else if (Compass >= 90 && Compass < 180 && PositionX < minx + offset)
{
if (US_Right < 20)
ACTION(2, -2, 0, 7 * (SwampSpeed));
else
ACTION(-2, 2, 0, 1);
return true;
}
}
if (PositionX <= minx || PositionX >= maxx || PositionY <= miny || PositionY
>= maxy)
{
bironcon++;
}
else
{
bironcon = 0;
}
return false;
}
//Swamp Land
void SwampLand()
{
if (Left == Swamp || Right == Swamp)
{
SwampSpeed = 5;
bati = 1;
SwampFlag = 1;
}
else
{
SwampSpeed = 1;
bati = 0;
SwampFlag = 0;
}
if (SignalBlockZone())
{
}
if (SignalBlockZone() && RestrictedFlag3 == 0 && bati == 1)
{
StartTime();
StopTime();
RestrictedFlag3 = 1;
}
else if (SignalBlockZone() && RestrictedFlag3 == 1 && bati == 0)
{
StartTime();
StopTime();
RestrictedFlag3 = 0;
}
}
//Following points
boolean GOTO(int XGoal, int YGoal, char purpose)
{
//////printf("IIIIIIIIIIIIIIIIIIIIIIIIII________________________\n");
int next;
int IDEALCOMPASS;
if (PURPOSE == '-')
return false;
if (BIKHIALTIMER > 0)
{
BIKHIALTIMER--;
return false;
}
if (BIKHIALCONDITION())
{
return false;
}
if (DepoBoxDetected())
{
return true;
}
IDEALCOMPASS = CALCULATEANGLE(XGoal, YGoal);
if (REACH(XGoal, YGoal))
{
if (purpose == 'D')
{
if (position[4][disminex] == 1000)
{
PATHSELECTED = 0;
return true;
}
else
{
WELLTIMER = MAX_TIME;
disminex = position[4][disminex];
XGOAL = position[0][disminex];
YGOAL = position[1][disminex];
return true;
}
}
else if (purpose == 'S')
{
superobjflag = 1;
if ((abs(PositionX - LXGOAL) <= 3 && abs(PositionY - LYGOAL) <=
3) || sobjCounter > 150)
{
ACTION(0, 0, 1, 50);
sobjpurpose = 0;
LXGOAL = 0;
LYGOAL = 0;
SobjCreater = 1;
ObjCounter++;
PATHSELECTED = 0;
sobjCounter = 0;
ChangeState("SuperObj");
return true;
}
else if (isViewable4(LXGOAL, LYGOAL, XGoal, YGoal))
{
XGOAL = LXGOAL;
YGOAL = LYGOAL;
return true;
}
else
{
if (jahat == 1)
{
////////////printf("jahat111111111111111111111111111\
n");
/*seminex = position[3][seminex];*/
int Point = seminex;
////////////printf("point111111111111111111%d\n",
Point);
int a = 0;
int WhileCounter = 0;
while (position[3][Point] != 1000 && EndMinex >
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[3][Point];
////////////printf("point22222222222222%d\n",
Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;
////////////printf("seminex11111111111111111%d\n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[3][seminex] != 1000 &&
EndMinex > seminex)
{
seminex = position[3][seminex];
////////////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
else if (jahat == 2)
{

////////////printf("jahat222222222222222222222222222222222222\n");
/*seminex = position[4][seminex];*/
int Point = seminex;
////////////printf("point111111111111111111%d\n",
Point);
int a = 0;
int WhileCounter = 0;
while (position[4][Point] != 1000 && EndMinex <
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[4][Point];
////////////printf("point22222222222222%d\n",
Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;

////////////printf("seminex11111111111111111%d\n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[4][seminex] != 1000 &&
EndMinex < seminex)
{
seminex = position[4][seminex];
////////////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
WELLTIMER = MAX_TIME;
XGOAL = position[0][seminex];
YGOAL = position[1][seminex];
return true;
}
}
else if (purpose == 'F')
{

//////printf("SQWDDDDDDDDDDDDDWAFSDDFDZDV____________________________________\n\n\
n");
if (abs(PositionX - FXGOAL) < 10 && abs(PositionY - FYGOAL) < 10)
{
ATFIRST = 1;
PURPOSE = '-';
PATHSELECTED = 0;
//////////////printf("path99999999999999999999999999999999\
n");
return true;
}
else if (isViewable4(FXGOAL, FYGOAL, XGoal, YGoal))
{
XGOAL = FXGOAL;
YGOAL = FYGOAL;

//////printf("hhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n\n\n");
return true;
}
else
{
if (jahat == 1)
{

//////////////printf("jahat111111111111111111111111111\n");
/*seminex = position[3][seminex];*/
int Point = seminex;
//////////////printf("point111111111111111111%d\n",
Point);
int a = 0;
int WhileCounter = 0;
while (position[3][Point] != 1000 && EndMinex >
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[3][Point];
//////////////printf("point22222222222222%d\n",
Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;

//////////////printf("seminex11111111111111111%d\n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[3][seminex] != 1000 &&
EndMinex > seminex)
{
seminex = position[3][seminex];
//////////////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
else if (jahat == 2)
{

//////////////printf("jahat222222222222222222222222222222222222\n");
/*seminex = position[4][seminex];*/
int Point = seminex;
//////////////printf("point111111111111111111%d\n",
Point);
int a = 0;
int WhileCounter = 0;
while (position[4][Point] != 1000 && EndMinex <
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[4][Point];
//////////////printf("point22222222222222%d\n",
Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;

//////////////printf("seminex11111111111111111%d\n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[4][seminex] != 1000 &&
EndMinex < seminex)
{
seminex = position[4][seminex];
//////////////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
WELLTIMER = MAX_TIME;
XGOAL = position[0][seminex];
YGOAL = position[1][seminex];
return true;
}
}
else if (purpose == 'E')
{
if (abs(PositionX - AXGoal) < 10 && abs(PositionY - AYGoal) < 10)
{
PURPOSE = '-';
GreenAreaTime = Time;
RedAreaTime = Time;
BlackAreaTime = Time;
//printf("___________________#DQWDXGX\n");
AXGoal = 0;
AYGoal = 0;
jahat = 0;
PATHSELECTED = 0;
return true;
}
else if (isViewable4(AXGoal, AYGoal, XGoal, YGoal))
{
XGOAL = AXGoal;
YGOAL = AYGoal;
//////printf("hhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiiii\
n\n\n");
return true;
}
else
{
if (jahat == 1)
{
//////printf("jahat111111111111111111111111111\n");
/*seminex = position[3][seminex];*/
int Point = seminex;
//////printf("point111111111111111111%d\n", Point);
int a = 0;
int WhileCounter = 0;
while (position[3][Point] != 1000 && EndMinex >
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[3][Point];
//////printf("point22222222222222%d\n", Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;
//////printf("seminex11111111111111111%d\
n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[3][seminex] != 1000 &&
EndMinex > seminex)
{
seminex = position[3][seminex];
//////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
else if (jahat == 2)
{

//////printf("jahat222222222222222222222222222222222222\n");
int Point = seminex;
//////printf("point111111111111111111%d\n", Point);
int a = 0;
int WhileCounter = 0;
while (position[4][Point] != 1000 && EndMinex <
seminex && WhileCounter < 200)
{
WhileCounter++;
printf("WhileCounter%d\n\n", WhileCounter);
Point = position[4][Point];
//////printf("point22222222222222%d\n", Point);
if (isViewable(position[0][Point], position[1]
[Point]))
{
seminex = Point;
a = 1;
//////printf("seminex11111111111111111%d\
n", seminex);
}
}
printf("WhileCounter%d\n\n", WhileCounter);
if (WhileCounter >= 200)
{
PURPOSE = '-';
PATHSELECTED = 0;
}
if (a == 0 && position[4][seminex] != 1000 &&
EndMinex < seminex)
{
seminex = position[4][seminex];
//////printf("seminex222222222222%d\n",
seminex);
}
if (add[EndMinex][seminex] < 0)
{
jahat = 1;
}
else
{
jahat = 2;
}
}
WELLTIMER = MAX_TIME;
XGOAL = position[0][seminex];
YGOAL = position[1][seminex];
return true;
}
}
else if (purpose == 'Z')
{
if (abs(PositionX - ZXGOAL) < 10 && abs(PositionY - ZYGOAL) < 10)
{
PURPOSE = '-';
Znumber = 0;
PATHSELECTED = 0;
//////////////printf("path112222222222222222222222\n");
return true;
}
else
{
XGOAL = ZArray[0][Znumber];
YGOAL = ZArray[1][Znumber];
Znumber++;
return true;
}
}
}
if (TURNTO(IDEALCOMPASS))
{
if ((PositionX >= LXGOAL - 30 && PositionX <= LXGOAL + 30 && PositionY
>= LYGOAL - 30 && PositionY <= LYGOAL + 30) ||
(PositionX > 20 - DPSPAN && PositionX < 20 + DPSPAN && PositionY
> 20 - DPSPAN && PositionY < 20 + DPSPAN) ||
(PositionX > 338 - DPSPAN && PositionX < 338 + DPSPAN &&
PositionY > 23 - DPSPAN && PositionY < 3 + DPSPAN) ||
(PositionX > 295 - DPSPAN && PositionX < 295 + DPSPAN &&
PositionY > 185 - DPSPAN && PositionY < 185 + DPSPAN))
{
ACTION(2, 2, 0, 0);
return true;
}
else
{
ACTION(5, 5, 0, 0);
return true;
}
}
return true;
}
boolean REACH(int XGoal, int YGoal)
{
int offset = 15;
if (position[4][disminex] == 1000)
offset = 5;
if (abs(XGoal - PositionX) <= offset && abs(YGoal - PositionY) <= offset)
{

//////printf("_________________________________________________________\n\
n");
return true;
}
return false;
}
boolean TURNTO(int angle)
{
int min = 0, max = 0;
if (bati == 1)
{
TOLERANCE = 20;
}
else
{
TOLERANCE = 7;
}
int DIFF;
min = (angle > TOLERANCE) ? angle - TOLERANCE : (angle + 360) - TOLERANCE;
max = (angle < 360 - TOLERANCE) ? angle + TOLERANCE : (angle - 360) +
TOLERANCE;
if (min < max)
{
if ((Compass >= min && Compass <= max))
{
SuperObjCounter++;
return true;
}
}
else
{
if ((Compass >= min || Compass <= max))
{
SuperObjCounter++;
return true;
}
}
DIFF = Compass - angle;
if (DIFF < 0)
{
DIFF = DIFF + 360;
}
else if (DIFF > 360)
{
DIFF = DIFF - 360;
}
if (DIFF < 180)
{
if ((PositionX >= LXGOAL - 45 && PositionX <= LXGOAL + 45 && PositionY
>= LYGOAL - 45 && PositionY <= LYGOAL + 45))
{
//printf("111111111111111\n");
ACTION(2, -2, 0, 0);
//return true;
}
if (DIFF < 12)
{
ACTION(2, 1, 0, 0);
//return true;
}
else if (DIFF < 50 && DIFF >= 12)
{
ACTION(5, 3, 0, 0);
//return true;
}
else
{
int speed = DIFF / 45 + 1;
//printf("speed111111111%d\n", speed);
ACTION(speed, -speed, 0, 0);
//return true;
}

}
else
{
if ((PositionX >= LXGOAL - 45 && PositionX <= LXGOAL + 45 && PositionY
>= LYGOAL - 45 && PositionY <= LYGOAL + 45))
{
ACTION(-2, 2, 0, 0);
//printf("22222222222222222\n");
//return true;
}
if (DIFF > 348)
{
ACTION(1, 3, 0, 0);
//return true;
}
else if (DIFF > 310 && DIFF <= 348)
{
ACTION(3, 5, 0, 0);
//return true;
}
else
{
int speed = (DIFF - 180) / 45 + 1;
//printf("speed2222222%d\n", speed);
ACTION(-speed, speed, 0, 0);
//return true;
}

}
return false;
}
boolean isViewable(int x, int y)
{
int i = 0;
for (i = 0; i < OBS_MAX; i++)
{
if (Intersects(PositionX, PositionY, x, y, Obstacles[0][i],
Obstacles[1][i], Obstacles[2][i], Obstacles[3][i]) && ((PURPOSE == 'S' &&
Obstacles[4][i] == 2) || PURPOSE != 'S'))
return false;
}
return true;
}
boolean isViewable4(int xme, int yme, int x, int y)
{
int i = 0;
for (i = 0; i < OBS_MAX; i++)
{
if (Intersects(xme, yme, x, y, Obstacles[0][i], Obstacles[1][i],
Obstacles[2][i], Obstacles[3][i]) && ((PURPOSE == 'S' && Obstacles[4][i] == 2) ||
PURPOSE != 'S'))
return false;
}
return true;
}
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;
return false;
}
else
{
t1 = ((P1X - p3X) * dy34 + (p3Y - P1Y) * dx34) / denominator;
}
lines_intersect = true;

t2 = ((p3X - P1X) * dy12 + (P1Y - p3Y) * dx12) / -denominator;


segments_intersect = ((t1 > 0) && (t1 < 1) && (t2 > 0) && (t2 < 1));
return segments_intersect ? true : false;
}
int CALCULATEANGLE(int XGoal, int YGoal)
{
int ANGLE = 0;
alpha = atan2((double)((double)YGoal - (double)PositionY), (double)
((double)XGoal - (double)PositionX));
alpha = (alpha * 180.0) / 3.14;
if (PositionX <= XGoal && PositionY >= YGoal)
{
ANGLE = (int)alpha + 270;
}
else if (PositionX >= XGoal && PositionY >= YGoal)
{
ANGLE = (int)alpha + 270;
}
else if (PositionX <= XGoal && PositionY <= YGoal)
{
ANGLE = (int)alpha + 270;
}
else if (PositionX >= XGoal && PositionY <= YGoal)
ANGLE = (int)alpha - 90;
ANGLE = (ANGLE>360) ? ANGLE - 360 : ANGLE;
ANGLE = (ANGLE<0) ? ANGLE + 360 : ANGLE;
return ANGLE;
}
boolean stend(int sx, int sy, int ex, int ey)
{
if (PATHSELECTED == 0)
{
//////printf("______________________\n\n\n\n\n");

AXGoal = ex;
AYGoal = ey;
//////printf("axgoal%d\n", AXGoal);
//////printf("aygoal%d\n", AYGoal);
stcounter = 0;
encounter = 0;
for (int a = 1; a < MAX_PATH; a++)
{

if (position[0][a] != -1 && isViewable4(sx, sy, position[0][a],


position[1][a]))
{
ViewedFromStart[stcounter] = a;
stcounter++;
//////printf("ViewedFromSSStart = %d x = %d, y = %d\n", a,
position[0][a], position[1][a]);
}
if (position[0][a] != -1 && isViewable4(ex, ey, position[0][a],
position[1][a]))
{
ViewedFromEnd[encounter] = a;
encounter++;
//////printf("ViewedFromEEEnd = %d x = %d, y = %d\n", a,
position[0][a], position[1][a]);
}
}
//////printf("stcounter %d\n", stcounter);
//////printf("encounter %d\n", encounter);
for (int sd = 0; sd < stcounter; sd++)
{
//////////////printf("W:%d\n", w);
sides1 = position[0][ViewedFromStart[sd]] - sx;
sides2 = position[1][ViewedFromStart[sd]] - sy;
sides3 = sides1 * sides1 + sides2 * sides2;
distanceStart[sd] = sqrt(sides3);
}
//////////////printf("stcounterrrrrrrrrrr %d\n", stcounter);
//////////////printf("encounterrrrrrrrrrr %d\n", encounter);
for (int ed = 0; ed < encounter; ed++)
{

sidee1 = position[0][ViewedFromEnd[ed]] - ex;


sidee2 = position[1][ViewedFromEnd[ed]] - ey;
sidee3 = sidee1 * sidee1 + sidee2 * sidee2;
distanceEnd[ed] = sqrt(sidee3);
}
semin = INT_MAX;
seminex = -1;
EndMinex = -1;
//////printf("stcounter %d\n", stcounter);
//////printf("encounter %d\n", encounter);
for (int s = 0; s < stcounter; s++)
{
for (int e = 0; e < encounter; e++)
{
//////printf("ViewedFromEnd[e] %d\n", ViewedFromEnd[e]);
//////printf("[ViewedFromStart[s] %d\n",
ViewedFromStart[s]);
if (add[ViewedFromEnd[e]][ViewedFromStart[s]] != -1)
{
//////printf("PATH FOUNDED -> e=%d s=%d dist=%d\n",
ViewedFromEnd[e], ViewedFromStart[s], abs(add[ViewedFromEnd[e]]
[ViewedFromStart[s]]) + distanceEnd[e] + distanceStart[s]);

if (abs(add[ViewedFromEnd[e]][ViewedFromStart[s]]) +
distanceEnd[e] + distanceStart[s] < semin)
{

if (add[ViewedFromEnd[e]][ViewedFromStart[s]] <
0)
{
jahat = 1;
}
else
{
jahat = 2;
}
semin = abs(add[ViewedFromEnd[e]]
[ViewedFromStart[s]]) + distanceEnd[e] + distanceStart[s];
seminex = ViewedFromStart[s];
EndMinex = ViewedFromEnd[e];
}
}
}
}

XGOAL = position[0][seminex];
YGOAL = position[1][seminex];
//////printf("xgoal%d\n", XGOAL);
//////printf("ygoal%d\n", YGOAL);
//////printf("seminex %d\n", seminex);
//////printf("endminex %d\n", EndMinex);
if (isViewable(ex, ey))
{
XGOAL = ex;
YGOAL = ey;
}
if (seminex == -1 || EndMinex == -1)
{

PURPOSE = '-';
//////printf("_______________________________________\n");
}
else
PATHSELECTED = 1;

}
//SuperObject
boolean SearchSobj()
{
ACTION(-2, -2, 0, 8);
ChangeState("DSobj");
}
boolean Sobj()
{
ACTION(0, 0, 1, 80);
PURPOSE = '-';
ChangeState("adi");
}
boolean DETECTSOBJ()
{
if (PURPOSE == 'S')
{
return true;
}
if (SuperObj_X > 0 && SuperObj_Y > 0)
{
LXGOAL = SuperObj_X;
LYGOAL = SuperObj_Y;
}
//////////////printf("lxgoal %d\n", LXGOAL);
//////////////printf("lYGOAL %d\n", LYGOAL);
//////////////printf("sobjflag %d\n", sobjflag);
//if (wwwwwwwwwww == 0)
//{
// wwwwwwwwwww = 1;
// LXGOAL = 272;
// LYGOAL = 210;
//}
if (LXGOAL > 0 && LYGOAL > 0)
{
PURPOSE = 'S';
WELLTIMER = MAX_TIME;
PATHSELECTED = 0;
stend(PositionX, PositionY, LXGOAL, LYGOAL);
return true;
}
return false;
}
boolean SobjPosition()
{
if (PositionX > LXGOAL - 20 && PositionX < LXGOAL + 20 && PositionY > LYGOAL
- 20 && PositionY < LYGOAL + 20)
{
sobjCounter++;
}
else
{
sobjCounter = 0;
}

}
//FirstArea
boolean FIRSTAREA()
{
//if (PURPOSE != '-')
//{
// return true;
//}
if (ATFIRST == 0)
{
FXGOAL = 118;
FYGOAL = 25;
PURPOSE = 'F';
//////printf("PURPOSE0000: %c\n", PURPOSE);
stend(PositionX, PositionY, FXGOAL, FYGOAL);
}
//////printf("fxgoal %d fygoal%d\n", FXGOAL, FYGOAL);
//////printf("PURPOSE: %c\n", PURPOSE);
return false;
}
//Not Used
int SUPEROBJECTCONDITION()
{
if (PURPOSE == '-')
return 1;
if (PATHSELECTED == 0 && sobjpurpose == 0 && DETECTSOBJ())
{
PURPOSE = 'S';
WELLTIMER = MAX_TIME;
for (int w = 1; w < MAX_PATH; w++)
{
Side1 = position[0][w] - LXGOAL;
Side2 = position[1][w] - LYGOAL;
Side3 = Side1 * Side1 + Side2 * Side2;
position[2][w] = sqrt(Side3);
}
dismin = INT_MAX;
disminex = 0;
for (int s = 1; s < MAX_PATH; s++)
{
if (position[0][s] != -1 && isNEAR(PositionX, PositionY,
ENDPOINT(s)) && isViewable4(LXGOAL, LYGOAL, position[0][s], position[1][s]))
{
int ends = s;
while (position[4][ends] != 1000)
{
ends = position[4][ends];
}
if (add[s][ends] != -1 && (position[2][s] + abs(add[s]
[ends])) < dismin)
{
dismin = (position[2][s] + abs(add[s][ends]));
disminex = s;
}
}
}
if (disminex == 0)
{
PURPOSE = '-';
return 1;
}
FIRSTPOINT = disminex;
while (position[4][disminex] != 1000)
{
disminex = position[4][disminex];
}
if (position[4][disminex] != position[4][FIRSTPOINT])
{
disminex = position[3][disminex];
XGOAL = position[0][disminex];
YGOAL = position[1][disminex];
}
else
{
XGOAL = LXGOAL;
YGOAL = LYGOAL;
}
PATHSELECTED = 1;
}
}
int ENDPOINT(int p)
{
while (position[4][p] != 1000)
p = position[4][p];
return p;
}
boolean isNEAR(int x, int y, int p)
{
if (abs(position[0][p] - x) < 40 && abs(position[1][p] - y) < 40)
{
return true;
}
return false;
}
boolean BIKHIALCONDITION()
{
return false;
if (US_Front < 10 || US_Right < 10 || US_Left < 10 || Right == yellow3 ||
Right == yellow || Left == yellow3 || Left == yellow)
{
BIKHIALTIMER = 10;
return true;
}
if (PositionX == 0 && PositionY == 0)
{
BIKHIALTIMER = 10;
return true;
}
return false;
}
DLL_EXPORT void OnTimer()
{
switch (CurGame)
{
case 9:
break;
case 10:
WheelLeft = 0;
WheelRight = 0;
LED_1 = 0;
MyState = 0;
break;
case 0:
Game0();
break;
case 1:
Game1();
break;
default:
break;
}
}

You might also like