/* execute la simulation, avec n tours */ static void simulation(unsigned long n) { unsigned long i; int a, b; printf("Simulation de %lu tours...\n", n); for (i=0; i<n || !n; i++) { putchar('.'); fflush(stdout); rendu(i); /* n est nul -> on regarde si il reste du surcre * sur la grille */ if (!n) { for (a=0; a<=19; a++) { for (b=0; b<=19; b++) { if (kor(a,b)->sucre || kor(a,b)->quoi == 'F' || kor(a,b)->ph_sucre) { goto encore; } } } /* plus de sucre -> on s'arrete */ break; } encore: tour(); } printf("\n"); printf("Fin de la simulation : %lu tours.\n", i); }
/* retourne VRAI si la case de coordonnees (c,d) est une * case vide adjacente a celle de coordonnees (a,b) * dont la pheromone de nid est egale a la plus faible * parmi les cases adjacentes a (a,b) */ static int plus_loin_nid(int a, int b, int c, int d) { int i,j; float min = 2.0; /* la case ou la pheromone est la plus faible */ coor k = { 0, 0 }; /* Voir si elle est vide */ if (!vide(c,d)) { return 0; } for (i=-1; i<=1; i++) { for (j=-1; j<=1; j++) { if (!i && !j) { continue; } /* on ignore la case si elle est non vide */ if (!vide(a+i, b+j)) { continue; } if (kor(a+i,b+j)->ph_nid < min) { k.x = a+i; k.y = b+j; min = kor(a+i,b+j)->ph_nid; } } } /* on a maintenant k, la case ou la pheromone est la * plus faible, on regarde si k = (c,d) */ return (kor(c,d)->ph_nid == min); }
static void enleve_sucre(int a, int b) { if (!sucre(a,b)) { return; } /* on enleve le sucre */ kor(a,b)->sucre--; /* plus de sucre ? */ if (kor(a,b)->sucre <= 0) { kor(a,b)->quoi = 'r'; } }
/* effectue un tour */ static void tour(void) { int i, j; kase *k = NULL; /* on remet a 0 les flags "fait" */ for (i=0; i<20; i++) { for (j=0; j<20; j++) { kor(i,j)->fait = 0; } } /* on traite maintenant chaque case */ for (i=0; i<20; i++) { for (j=0; j<20; j++) { k = kor(i,j); /* on diminue la pheromone de sucre */ if (k->ph_sucre >= 5) { k->ph_sucre -= 5; } else if (k->ph_sucre) { k->ph_sucre = 0; } /* on ne fait rien si la case est deja traitee */ if (kor(i,j)->fait) { continue; } /* on essaye chaque regle de 1 a 6 * (priorite la + haute a la + faible) */ if (!charge(i,j)) { if (!depose(i,j)) { if (!achemine(i,j)) { if (!remonte(i,j)) { if (!retourve(i,j)) { deplace(i,j); } } } } } /* fin de traitement de cette case */ } } }
/* deplace une fourmi de (a_1, b_1) vers (a_2, b_2) * si (a_2, b_2) est non vide, le programme s'arrete * sauf si (a_2, b_2) == (a_1, b_2) * cette fonction met le flag 'fait' a 1 */ static void depf(int a_1, int b_1, int a_2, int b_2) { if (!fourmi(a_1, b_1)) { fprintf(stderr, "Erreur fatale : la case (%d,%d) ne contient pas de fourmi.\n", a_1, b_1); exit(1); } if (!vide(a_2, b_2)) { fprintf(stderr, "Erreur fatale : la case (%d,%d) est non vide.\n", a_2, b_2); exit(1); } kor(a_2, b_2)->quoi = kor(a_1, b_1)->quoi; kor(a_1, b_1)->quoi = 'r'; kor(a_2, b_2)->fait = 1; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); x1 = new xing(); if(x1->init()){ if(x1->ETK_Connect(0)){ }else{ qDebug()<<kor("접속 실패"); } }else{ qDebug()<<kor("초기화 실패"); } Loginwiget w1; wk = new webwiget(); x1->wk=wk; mf = new mainframe(); //xcom = new xingcom(); wk->show(); w1.show(); tjango_th *jango_th; jango_th = new tjango_th(); jango_th->start(); tpricemoniter *pricemoniter_th; pricemoniter_th = new tpricemoniter(); pricemoniter_th->start(); tsitemoniter *sitemoniter; sitemoniter = new tsitemoniter(); sitemoniter->start(); return a.exec(); }
/* retourne la couleur que doit avoir le pixel (i,j) */ couleur pixcouleur(int i, int j) { couleur c = { 0, 0, 0 }; kase *k = NULL; int division; /* on obtient un pointeur vers la case * de la grille correspondante */ k = kor(i/20, j/20); if (k->quoi == 'n') { c.r = 0; c.v = 0x99; c.b = 0; } else { division = divca(i,j); /* a defaut d'autre chose on met la pheronome de nid */ c.r = 0; c.v = 0; c.b = (k->ph_nid * 100 + 100); if (division < 3) { if (k->quoi == 's') { c.r = k->sucre; c.v = (k->sucre / 2 + 128); c.b = (k->ph_nid * 100 + 100); } else { c.r = k->ph_sucre; c.v = 0; c.b = (k->ph_nid * 100 + 100); } } if (division < 2) { if (k->quoi == 'f' || k->quoi == 'F') { c.r = c.v = c.b = 0; } } if (division < 1) { if (k->quoi == 'F') { c.r = 0xff; c.v = 0x99; c.b = 0; } } } return c; }
/* Si une fourmi est adjacente au nid et qu'elle porte * de la nourriture, la depose et pose une pheromone de * sucre */ static int depose(int a, int b) { int i, j; if (!rentre(a,b)) { return 0; } /* elle pose la pheromone */ kor(a,b)->ph_sucre = 255; for (i=-1; i<=1; i++) { for (j=-1; j<=1; j++) { /* on ignore la case (a,b) elle-meme */ if (!i && !j) { continue; } if (nid(a+i,b+j)) { kor(a,b)->quoi = 'f'; return 1; } } } return 0; }
/* S'il y a une fourmi sur la case (a,b), et qu'elle ne * transporte pas de sucre et qu'elle en trouve, * charge du sucre et pose une pheromone de sucre */ static int charge(int a, int b) { int i,j; if (!cherche(a,b)) { return 0; } for (i=-1; i<=1; i++) { for (j=-1; j<=1; j++) { /* on ignore la case (a,b) elle-meme */ if (!i && !j) { continue; } if (sucre(a+i, b+j)) { kor(a,b)->quoi = 'F'; enleve_sucre(a+i, b+j); kor(a,b)->ph_sucre = 255; return 1; } } } return 0; }
void xing::func_t1452outblock1(LPRECV_PACKET pRpData){ //xing api bug config memory---------------------------------------- unsigned char * pRplpdata ; unsigned int src = (unsigned int)&(pRpData->lpData)-1; memcpy(&pRplpdata,(void *)src,4); //------------------------------------------------------------------ LPt1452OutBlock1 pOutBlock = (LPt1452OutBlock1)pRplpdata; int nCount = pRpData->nDataLength / sizeof( t1452OutBlock1 ); // Block Mode 시엔 전체크기 / 하나의 Record 크기 로 갯수를 구한다. for( int i=0; i<nCount; i++ ) { //데이터 처리 QString hname = QString::fromLocal8Bit(pOutBlock[i].hname,20); QString hprice = QString::fromLocal8Bit(pOutBlock[i].price,8); qDebug()<<kor("결과 %1: %2 , %3").arg(i).arg(hname).arg(hprice); } }
static void placer(unsigned char nb_sucre) { int i, j, a; /* Met les fourmis */ printf("Mise en place des fourmis...\n"); for (i=8;i<=11;i++) { for (j=8;j<=11;j++) { kor(i,j)->quoi = 'f'; } } /* Met le nid */ printf("Mise en place du nid...\n"); for (i=9;i<=10;i++) { for (j=9;j<=10;j++) { kor(i,j)->quoi = 'n'; } } /* insere la pheromone nid */ printf("Placement de la pheromone de nid...\n"); for (i=-10; i<=9; i++) { for (j=-10; j<=9; j++) { kor(i,j)->ph_nid = (float)intmin(abs(i<0?i+1:i),abs(j<0?j+1:j)) / 10.0; } } /* met le sucre */ printf("Mise en place du sucre...\n"); /* on place plusieurs morceaux de sucre au hasard */ a = rand() % 15 + 2; for (i=0; i<=3 ; i++) { for (j=0; j>=-1 ; j--) { kor(i+a,j)->quoi = 's'; kor(i+a,j)->sucre = nb_sucre; } } a = rand() % 15 + 2; for (i=0; i>=-1 ; i--) { for (j=0; j<=1 ; j++) { kor(i,j+a)->quoi = 's'; kor(i,j+a)->sucre = nb_sucre; } } }
// it is furntion for Message handler bool xing::nativeEvent(const QByteArray & eventType, void * message, long * result) { char * wresult; char * lresult; char cresult; char iresult; QString results_str; MSG* msg = reinterpret_cast<MSG*>(message); switch (msg->message) { case WM_USER+XM_LOGIN: wresult = (char *)msg->wParam; results_str = QString::fromLocal8Bit(wresult); qDebug()<<"XM_LOGIN"+results_str; if(results_str.compare("\"0000\"")){ qDebug()<<kor("접속되었습니다."); } break; case WM_USER+XM_RECEIVE_DATA: cresult = msg->wParam; //results_str = QString::fromLocal8Bit(wresult); if(cresult == REQUEST_DATA){ //TR의Data를받았을때발생 RECV_PACKET 의Memory 주소 LPRECV_PACKET pRpData = (LPRECV_PACKET)msg->lParam; if(strcmp(pRpData->szBlockName,NAME_t1452OutBlock)==0){ func_t1452outblock(pRpData); }else if( strcmp( pRpData->szBlockName, NAME_t1452OutBlock1 ) == 0 ){ func_t1452outblock1(pRpData); }else if(strcmp( pRpData->szBlockName, NAME_t1833OutBlock)==0){ func_t1833outblock(pRpData); }else if(strcmp( pRpData->szBlockName, NAME_t1833OutBlock1)==0){ func_t1833outblock1(pRpData); }else if(strcmp( pRpData->szBlockName, NAME_CSPAT00600OutBlock2)==0){ func_CSPAT00600OutBlock2(pRpData); }else if(strcmp(pRpData->szTrCode,"CSPAQ12300") == 0){ func_CSPAT12300OutBlock3(pRpData); }else if(strcmp(pRpData->szTrCode, "t0424") == 0){ func_t0424OutBlock1(pRpData); }else if(strcmp( pRpData->szBlockName, NAME_t1101OutBlock)==0){ func_t1101outblock(pRpData); }else if(strcmp(pRpData->szTrCode, "t0425") == 0){ func_t0425OutBlock1(pRpData); } }else if(cresult == MESSAGE_DATA){ //Message를받았을때발생 MSG_PACKET 의Memory 주소 LPMSG_PACKET pMsg = (LPMSG_PACKET)msg->lParam; //bug config memory---------------------------------------- // unsigned int src = (unsigned int)&(pMsg->nMsgLength)-2; // unsigned int dst = (unsigned int)&(pMsg->nMsgLength); // memmove((void *)dst,(void *)src,8); //--------------------------------------------------------- //qDebug()<<QString("XM_RECEIVE_DATA case 2 lParam = %1").arg(lresult); ETK_ReleaseMessageData(msg->lParam); }else if(cresult == SYSTEM_ERROR_DATA){ //Error가발생 MSG_PACKET 의Memory 주소 LPMSG_PACKET pMsg = (LPMSG_PACKET)msg->lParam; ETK_ReleaseMessageData(msg->lParam); }else if(cresult == RELEASE_DATA){ //TR이끝났을때발생 정수로Request ID를의미 //iresult = msg->lParam; ETK_ReleaseRequestData((int)msg->lParam); //qDebug()<<QString("XM_RECEIVE_DATA case 4 lParam = %1").arg(iresult); } break; default: break; } return false; }
/* retourne VRAI si et seulement si une case contient une pheromone * de sucre (valeur non nulle) */ static int sur_une_piste(int a, int b) { return kor(a,b)->ph_sucre; }
/* retourne VRAI si une case ne contient rien FAUX sinon */ static int vide(int a, int b) { return (kor(a,b)->quoi == 'r'); }
/* Si il y a une fourmi qui porte du sucre sur (a,b), * elle se dirige vers le nid tout en posant une * pheromone de sucre. */ static int achemine(int a, int b) { int i, j; if (!rentre(a,b)) { return 0; } /* elle pose la pheromone */ kor(a,b)->ph_sucre = 255; /* on cherche ou elle va aller */ /* Pour des raisons graphiques, on trouve plus interessant * qu'elles favorisent les directions nord, sud, est, ouest */ for (i=-1; i<=1; i++) { /* on ignore la case (a,b) elle-meme */ if (!i) { continue; } if (plus_proche_nid(a,b,a+i,b)) { depf(a, b, a+i, b); return 1; } } for (j=-1; j<=1; j++) { /* on ignore la case (a,b) elle-meme */ if (!i) { continue; } if (plus_proche_nid(a,b,a,b+j)) { depf(a, b, a, b+j); return 1; } } i=-1; j=-1; if (plus_proche_nid(a,b,a+i,b+j)) { depf(a, b, a+i, b+j); return 1; } i=1; j=-1; if (plus_proche_nid(a,b,a+i,b+j)) { depf(a, b, a+i, b+j); return 1; } i=-1; j=1; if (plus_proche_nid(a,b,a+i,b+j)) { depf(a, b, a+i, b+j); return 1; } i=1; j=1; if (plus_proche_nid(a,b,a+i,b+j)) { depf(a, b, a+i, b+j); return 1; } /* elle n'a pas trouve ou aller... */ return 0; }
/* retourne VRAI si une case est un element du nid FAUX sinon */ static int nid(int a, int b) { return (kor(a,b)->quoi == 'n'); }
/* retourne VRAI si une case contient du sucre FAUX sinon */ static int sucre(int a, int b) { return (kor(a,b)->quoi == 's'); }
/* retourne VRAI si une case contient une fourmi qui * cherche du sucre FAUX sinon */ static int cherche(int a, int b) { return (kor(a,b)->quoi == 'f'); }
/* retourne VRAI si et seulement si la case (a,b) * contient une fourmi */ static int fourmi(int a, int b) { return (kor(a,b)->quoi == 'F' || kor(a,b)->quoi == 'f'); }
/* retourne VRAI si une case contient une fourmi qui * rentre au nid FAUX sinon */ static int rentre(int a, int b) { return (kor(a,b)->quoi == 'F'); }