Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int up_down ;
- int left_right ;
- int shipDistance[MAX_SHIPS];
- int number_of_friends;
- int friendX[MAX_SHIPS];
- int friendY[MAX_SHIPS];
- int friendHealth[MAX_SHIPS];
- int friendFlag[MAX_SHIPS];
- int friendDistance[MAX_SHIPS];
- int friendType[MAX_SHIPS];
- int CallumX;
- int CallumY;
- int JackX;
- int JackY;
- int ChloeX;
- int ChloeY;
- int leaderX;
- int leaderY;
- int Callumhealth;
- int Chloehealth;
- int Jackhealth;
- int callumDistance;
- int jackDistance;
- int chloeDistance;
- int commonX;
- int commonY;
- int Distance;
- bool foundFriends = false;
- bool moveFriends = false;
- int leader;
- int leftright; //right 1 left 0
- int updown; //up 1 down 0
- bool chloeL = false;
- bool jackL = false;
- bool calumL = false;
- bool nicL = false;
- int counter = 0;
- long count = 0;
- int number_of_enemies;
- int enemyX[MAX_SHIPS];
- int enemyY[MAX_SHIPS];
- int enemyHealth[MAX_SHIPS];
- int enemyFlag[MAX_SHIPS];
- int enemyDistance[MAX_SHIPS];
- int enemyType[MAX_SHIPS];
- //FREINDLY LOCATIONS
- bool IsaFriend(int index)
- {
- bool rc;
- rc = false;
- if (shipFlag[index] == 18035241) //callum
- {
- rc = true; // I have just seen my friend 123
- }
- if (shipFlag[index] == 18006332) //jack
- {
- rc = true; // I have just seen my friend 123
- }
- if (shipFlag[index] == 18012950) //Chloe
- {
- rc = true; // I have just seen my friend 123
- }
- return rc;
- }
- //cite https://books.google.co.uk/books?id=Sz-Sqvm-hSYC&pg=PA7&lpg=PA7&dq=chase+algorithm+prey+predator&source=bl&ots=vOko5c6MjJ&sig=ACfU3U2KnVfBuICXEb36LpYmq20PdCGhlg&hl=en&sa=X&ved=2ahUKEwiBksHIlengAhW_QRUIHYhsA04Q6AEwA3oECAYQAQ#v=onepage&q=chase%20algorithm%20prey%20predator&f=false
- //MOVE TO X Y CORD
- void movement(int x, int y)
- {
- if (Distance < 3) {
- }
- else {
- if (myY == y) {
- }
- else {
- if (myY > y) {
- up_down = MOVE_DOWN * MOVE_FAST;
- }
- if (myY < y) {
- up_down = MOVE_UP * MOVE_FAST;
- }
- }
- if (myX == x) {
- }
- else {
- if (myX > x) {
- left_right = MOVE_LEFT * MOVE_FAST;
- }
- if (myX < x) {
- left_right = MOVE_RIGHT * MOVE_FAST;
- }
- }
- }
- }
- //https://www.geeksforgeeks.org/cpp-program-for-bubble-sort/
- /////////////////////////////////////////////////////////////////////////////////////////
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- //SORTING TEAMS
- void bubbleSort(int e[], int s[], int n) {
- bool swapped = true;
- int j = 0;
- int tmp;
- while (swapped) {
- swapped = false;
- j++;
- for (int i = 0; i < n - j; i++) {
- if (e[i] > e[i + 1]) {
- tmp = e[i];
- e[i] = e[i + 1];
- e[i + 1] = tmp;
- tmp = s[i];
- s[i] = s[i + 1];
- s[i + 1] = tmp;
- swapped = true;
- }
- }
- }
- }
- /*
- ███████╗███████╗███╗ ██╗██████╗ ██╗███╗ ██╗ ██████╗ ███╗ ███╗███████╗███████╗███████╗ █████╗ ██████╗ ███████╗███████╗
- ██╔════╝██╔════╝████╗ ██║██╔══██╗██║████╗ ██║██╔════╝ ████╗ ████║██╔════╝██╔════╝██╔════╝██╔══██╗██╔════╝ ██╔════╝██╔════╝
- ███████╗█████╗ ██╔██╗ ██║██║ ██║██║██╔██╗ ██║██║ ███╗ ██╔████╔██║█████╗ ███████╗███████╗███████║██║ ███╗█████╗ ███████╗
- ╚════██║██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██║ ██║ ██║╚██╔╝██║██╔══╝ ╚════██║╚════██║██╔══██║██║ ██║██╔══╝ ╚════██║
- ███████║███████╗██║ ╚████║██████╔╝██║██║ ╚████║╚██████╔╝ ██║ ╚═╝ ██║███████╗███████║███████║██║ ██║╚██████╔╝███████╗███████║
- ╚══════╝╚══════╝╚═╝ ╚═══╝╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
- */
- void freindlyMessaging() {
- char msg[100];
- sprintf_s(msg, "Im at %d %d %d %d %d %d", myX, myY, myHealth,leader,commonX,commonY);
- if (counter == 0) {
- send_message("18035241", "18020971", msg); // send my co-ordinates to Calum
- }
- else if (counter == 1) {
- send_message("18006332", "18020971", msg); // send my co-ordinates to Jack
- }
- else if (counter == 2) {
- send_message("18012950", "18020971", msg); // send my co-ordinates to Chloe
- }
- counter++;
- if (counter == 3) {
- counter = 0;
- }
- }
- //MOVING TO THE TEAM
- void moveToTeam() {
- //commonX = JackX + ChloeX + CallumX + myX;
- //commonX = commonX / 4;
- //commonY = JackY + ChloeY + CallumY + myY;
- //commonY = commonY / 4;
- commonX = 500;
- commonY = 500;
- Distance = (int)sqrt((double)((commonX - myX)*(commonX - myX) + (commonY - myY)*(commonY - myY)));
- if (Distance < 3){
- }
- else {
- movement(commonX, commonY);
- }
- //printf("commonX =%d commonY = %d\r",commonX,commonY);
- }
- /*
- ████████╗ █████╗ ██████╗████████╗██╗ ██████╗███████╗
- ╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝██║██╔════╝██╔════╝
- ██║ ███████║██║ ██║ ██║██║ ███████╗
- ██║ ██╔══██║██║ ██║ ██║██║ ╚════██║
- ██║ ██║ ██║╚██████╗ ██║ ██║╚██████╗███████║
- ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
- */
- void tactics()
- {
- //RESSETTING
- int i;
- count++;
- left_right = 0;
- up_down = 0 ;
- ////////////////////////////////
- // FREINDLY DISTANCES
- ///////////////////////////////
- callumDistance = (int)sqrt((double)((CallumX - myX)*(CallumX - myX) + (CallumY - myY)*(CallumY - myY)));
- jackDistance = (int)sqrt((double)((JackX - myX)*(JackX - myX) + (JackY - myY)*(JackY - myY)));
- chloeDistance = (int)sqrt((double)((ChloeX - myX)*(ChloeX -myX) + (ChloeY - myY)*(ChloeY - myY)));
- //SHIP DETECTION
- for (i = 0; i < number_of_ships; i++)
- {
- shipDistance[i] = (int)sqrt((double)((shipX[i] - shipX[0])*(shipX[i] - shipX[0]) + (shipY[i] - shipY[0])*(shipY[i] - shipY[0])));
- }
- for (i = 0; i < 30; i++)
- {
- //Detection cancellation
- enemyX[i] = 0;
- enemyY[i] = 0;
- enemyHealth[i] = 0;
- enemyFlag[i] = 0;
- enemyDistance[i] = 0;
- enemyType[i] = 0;
- }
- number_of_friends = 0;
- number_of_enemies = 0;
- if (number_of_ships > 1)
- {
- for (i = 1; i < number_of_ships; i++)
- {
- //FIND FREINDS AND MARK THEM
- if (IsaFriend(i))
- {
- friendX[number_of_friends] = shipX[i];
- friendY[number_of_friends] = shipY[i];
- friendHealth[number_of_friends] = shipHealth[i];
- friendFlag[number_of_friends] = shipFlag[i];
- friendDistance[number_of_friends] = shipDistance[i];
- friendType[number_of_friends] = shipType[i];
- number_of_friends++;
- }
- //FIND ENEMYS AND MARK THEM
- else
- {
- enemyX[number_of_enemies] = shipX[i];
- enemyY[number_of_enemies] = shipY[i];
- enemyHealth[number_of_enemies] = shipHealth[i];
- enemyFlag[number_of_enemies] = shipFlag[i];
- enemyDistance[number_of_enemies] = shipDistance[i];
- enemyType[number_of_enemies] = shipType[i];
- number_of_enemies++;
- }
- }
- }
- //Kill FREINDS
- int f = number_of_friends;
- bubbleSort(friendHealth, friendX, f);
- bubbleSort(friendHealth, friendY, f);
- bubbleSort(friendHealth, friendFlag, f);
- bubbleSort(friendHealth, friendType, f);
- bubbleSort(friendHealth, friendDistance, f);
- if (friendHealth[0] < 3) {
- fire_at_ship(friendX[0], friendY[0]);
- }
- //FIRE CONTROL
- int n = number_of_enemies;
- bubbleSort(enemyDistance, enemyX, n);
- bubbleSort(enemyDistance, enemyY, n);
- bubbleSort(enemyDistance, enemyHealth, n);
- bubbleSort(enemyDistance, enemyFlag, n);
- bubbleSort(enemyDistance, enemyType, n);
- if (number_of_enemies > 0)
- {
- fire_at_ship(enemyX[0], enemyY[0]);
- }
- //FRENDLY MESSAGING
- freindlyMessaging();
- //SHIP MODES
- f = number_of_friends;
- bubbleSort(friendDistance, friendX, f);
- bubbleSort(friendDistance, friendY, f);
- bubbleSort(friendDistance, friendFlag, f);
- bubbleSort(friendDistance, friendType, f);
- bubbleSort(friendDistance, friendHealth, f);
- //LEADER
- if (moveFriends == true) {
- if (myHealth == 10 && Chloehealth == 10 && Jackhealth == 10 && Callumhealth == 10)
- {
- leader = 2;
- }
- else {
- if (myHealth > Chloehealth && Jackhealth && Callumhealth) {
- leader = 1;
- }
- else if (Callumhealth > myHealth && Jackhealth && Chloehealth) {
- leader = 2;
- }
- else if (Jackhealth > myHealth && Chloehealth && Callumhealth) {
- leader = 3;
- }
- else if (Chloehealth > myHealth && Jackhealth && Callumhealth) {
- leader = 4;
- }
- }
- }
- //FIND FREINDS - AVOID OTHER SHIPS - DONT ENGAGE MULTIPLE SHIPS
- if (jackDistance < 10 && chloeDistance< 10 && callumDistance < 10) {
- moveFriends = true;
- }
- if (jackDistance < 30 && chloeDistance < 30 && callumDistance < 30) {
- if (moveFriends == true) {
- //MOVMENT AS A GROUP//
- if (leader == 1) {
- if (myHealth < 5 || Callumhealth < 5 || Jackhealth < 5 || Chloehealth < 5) {
- //ROAMING NO ENEMYS
- if (number_of_enemies == 0) {
- if (myY > 900)
- {
- up_down = MOVE_DOWN * MOVE_SLOW;
- }
- if (myX < 200)
- {
- left_right = MOVE_RIGHT * MOVE_SLOW;
- }
- if (myY < 100)
- {
- up_down = MOVE_UP * MOVE_SLOW;
- }
- if (myX > 800)
- {
- left_right = MOVE_LEFT * MOVE_SLOW;
- }
- }
- else {
- if (myY > 900)
- {
- up_down = MOVE_DOWN * MOVE_FAST;
- }
- if (myX < 200)
- {
- left_right = MOVE_RIGHT * MOVE_FAST;
- }
- if (myY < 100)
- {
- up_down = MOVE_UP * MOVE_FAST;
- }
- if (myX > 800)
- {
- left_right = MOVE_LEFT * MOVE_FAST;
- }
- }
- //RUN AWAY from nearest enemy
- if (number_of_enemies > number_of_friends) {
- }
- //OUTNUMBER ATTACK kill closest enemy
- if (number_of_friends > number_of_enemies) {
- }
- //LOW HEALTH
- //SHIP TYPES
- }
- else if (leader == 2) {
- movement(CallumX, CallumY);
- }
- else if (leader == 3) {
- movement(JackX, JackY);
- }
- else if (leader == 4) {
- movement(ChloeX, ChloeY);
- }
- }
- }
- }
- //TEAM IS UNGROUPED
- if (jackDistance > 30 && chloeDistance > 30 && callumDistance > 30) {
- moveFriends = false;
- moveToTeam();
- }
- //SEND MOVMENT TO SERVER
- movement(500, 500);
- //running on even grid
- if (myX % 2 == 0) {
- }
- else {
- left_right = MOVE_LEFT * MOVE_SLOW;
- }
- if (myY % 2 == 0) {
- }
- else {
- up_down = MOVE_DOWN * MOVE_SLOW;
- }
- move_in_direction(left_right, up_down);
- if (moveFriends == false) {
- leader = 0;
- }
- //DISPLAY status
- if ((count % 10) == 0) {
- printf("distance to target = %d X= %d Y=%d moveFriends = %d ", Distance, myX, myY, moveFriends);
- printf(" \r");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement