void initStrategy2012(int strategyIndex) { initLocationList(&locationList, (Location(*)[]) &locationListArray, STRATEGY_2012_BIT_LIST_NAVIGATION_TEST_ARRAY_LENGTH); initPathList(&pathList, (PathData(*)[]) &pathListArray, STRATEGY_2012_NAVIGATION_PATH_LIST_TEST_ARRAY_LENGTH); initBitList(&outgoingPathBitList, (unsigned int(*)[]) &outgoingPathBitArray, STRATEGY_2012_BIT_LIST_NAVIGATION_TEST_ARRAY_LENGTH); initBitList(&availablePathBitList, (unsigned int(*)[]) &availablePathBitArray, STRATEGY_2012_BIT_LIST_NAVIGATION_TEST_ARRAY_LENGTH); initNavigation(&locationList, &pathList, &outgoingPathBitList, &availablePathBitList); initLocations2012(); initPaths2012(strategyIndex); initTargets2012(); initTargetActions2012(); initTargetActionsItems2012(); initStrategies2012(); initStrategiesItems2012(strategyIndex); GameStrategy* strategy = getGameStrategy(0); GameStrategyContext* strategyContext = getStrategyContext(); strategyContext->gameStrategy = strategy; if (strategyIndex == STRATEGY_HOMOLOGATION) { strategyContext->maxTargetToHandle = 1; } else { strategyContext->maxTargetToHandle = getGameTargetList()->size; } //OutputStream* debugOutputStream = getInfoOutputStreamLogger(); //printStrategyAllDatas(debugOutputStream); // opponent Point* p = &(getStrategyContext()->opponentRobotPosition); p->x = 0; p->y = 0; // obstacle p = &(getStrategyContext()->lastObstaclePosition); p->x = 0; p->y = 0; strategyContext->hasMoreNextSteps = true; // reinitialize the game board to change elements / targets ... }
void dealWithUDPMessage(char* buf, int length, struct NetworkTopoStruct* p, int tcpsockfd) { if(length>MAXMESSAGESIZE) { printf("dealWithUDPMessage: Message Size too Big! Can not deal with it!\n"); return; } MSG message,*pMSG; pMSG = initMSG(&message); char newMessage[MAXMESSAGESIZE]; //char buf[MAXMESSAGESIZE]; //memset(buf,'\0',sizeof(char)*MAXMESSAGESIZE); //memcpy(buf,receivebuf,sizeof(char)*(length+2)); int newMSGLen = 0; int neiID=0; int i; char sendbuf[MAXDATASIZE]; SPATH s_path; SPATH *shortestPath = initPathList(&s_path,1); if (fetchReceivedMessage(pMSG, buf)==0) { perror("ERR in dealWithUDPMessage: fetch received message error !\n"); return; } switch(pMSG->msgType){ case 1: if(CalculateShortestPath(shortestPath, pMSG->dest,p) != 1) { printf("dealWithUDPMessage: no route exist!\n"); sprintf(sendbuf,"DROP %s",pMSG->message); sendmessage(tcpsockfd,sendbuf); receive(tcpsockfd,buf); break; } generateForWardingMessage(newMessage,&newMSGLen,shortestPath,pMSG); // send log information sprintf(sendbuf,"LOG FWD %d %s",shortestPath->nexthop,pMSG->message); sendmessage(tcpsockfd,sendbuf); receive(tcpsockfd,buf); // This is LOG OK // send newMessage to the neighbour if((neiID = fetchNeiIdByAddr(p,shortestPath->nexthop))<0){ perror("ERR dealWithUDPMessage case 1: neigh id not found\n"); exit(1); } printf("dealWithUDPMessage: sending %d bytes with %d messages to %d through %d\n",newMSGLen,strlen(pMSG->message),pMSG->dest,p->Neighs[neiID].addr); if(udpTalkTo(p->Neighs[neiID].host,p->Neighs[neiID].udpport,newMessage,newMSGLen) != 0) { perror("ERR dealWithUDPMessage case 1: udp talking error.\n"); exit(1); } break; case 2: // find myself in the path list, for(i=0;i<pMSG->hopNum;i++){ if(pMSG->path[i] == p->myaddr) break; } //if not in the list, err if(i==pMSG->hopNum){ perror("ERR dealWithUDPMessage: src not in path list\n"); break; } // if in the list but not the last one, forward and send the log information if( i < pMSG->hopNum-1 ){ // send log information sprintf(sendbuf,"LOG FWD %d %s",pMSG->path[i+1],pMSG->message); sendmessage(tcpsockfd,sendbuf); receive(tcpsockfd,buf); // This is LOG OK received // generate forward message generateForWardingMessage(newMessage,&newMSGLen,NULL,pMSG); if((neiID = fetchNeiIdByAddr(p,pMSG->path[i+1])) < 0){ perror("ERR dealWithUDPMessage case 2: neigh id not found\n"); exit(1); } // forward the information printf("dealWithUDPMessage: sending %d bytes with %d messages to %d through %d\n",newMSGLen,strlen(pMSG->message),pMSG->dest,p->Neighs[neiID].addr); if(udpTalkTo(p->Neighs[neiID].host,p->Neighs[neiID].udpport,newMessage,newMSGLen) != 0) { perror("ERR dealWithUDPMessage case 2: udp talking error.\n"); exit(1); } } else{ // else, report received the list sprintf(sendbuf,"RECEIVED %s",pMSG->message); sendmessage(tcpsockfd,sendbuf); } break; case 3: case 4: // check whether the link cost is already stored if(!isLinkStored(pMSG->linkinfo,p)){ //if it is not stored. // stores it and broadcast it updateLinkChange(pMSG->linkinfo,p); if(!broadCastLinkInfo(pMSG->msgType, pMSG->linkinfo, p)){ printf("ERR dealWithUDPMessage: broadcastlinkinfo\n"); } } break; default: break; } }