/* La fourmi sur (a,b) n'est pas sur une piste et cherche * du sucre, si une case adjacente est sur une piste * la fourmi va sur cette case */ static int retourve(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++) { if (!i && !j) { continue; } if (vide(a+i, b+j) && sur_une_piste(a+i, b+j)) { depf(a, b, a+i, b+j); return 1; } } } return 0; }
bool TTransFile::Exists(char* In) { unsigned char* c = (unsigned char*) In; if (!In) return true; while(*c != '\0') { int iaux; const char *r = (const char*) cherche(c, &iaux); if((iaux == 0) || (r == NULL)) { return false; } else { /* on a trouve une correspondance */ c+=iaux; } } return true; }
/* Si la fourmi sur (a,b) est sur une piste, * alors on la deplace sur la piste (si possible) * la ou la pheromone de nid est la plus faible */ static int remonte(int a, int b) { int i,j; if (!cherche(a,b) || !sur_une_piste(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 (vide(a+i,b+j) && plus_loin_nid(a,b,a+i,b+j) && sur_une_piste(a+i,b+j)) { depf(a, b, a+i, b+j); 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; }
/////////////////////////////////////////////////////////////////////////////// // // Transcode // // Cette methode transcode une chaine de caractere en une autre, conformement // a la table chargee - inspire de ttrans.cc // /////////////////////////////////////////////////////////////////////////////// bool TTransFile::Transcode(const char* In, typestr &Out, const char *Notice, const char *Field) { const unsigned char *c = (const unsigned char*) In; const char *r = NULL; Out.str(""); if (!In) return true; bool res = true; while(*c != '\0') { int iaux; r = (const char*) cherche(c, &iaux); if((iaux == 0) || (r == NULL)) { if (itsDefaultCopy) { Out.append_char(*c); ++c; continue; } else if (itsDefaultValueValid) { Out.append(itsDefaultValue.str()); ++c; continue; } // aucune chaine de sustitution n'a ete trouvee, on conserve la valeur // en signalant l'erreur typestr tmp; char c_hex[30]; sprintf(c_hex, "%x", *c); if (Notice && Field) { tmp = "Notice '"; tmp += Notice; tmp += "' : field '"; tmp += Field; tmp += "' ( Unknown character '"; tmp += *c; tmp += "' (\\"; tmp += c_hex; tmp += ") ) : table '"; tmp += itsFileInfo; tmp += '\''; } else { tmp = "( Unknown character '"; tmp += *c; tmp += "' (\\"; tmp += c_hex; tmp += ") ) : table '"; tmp += itsFileInfo; tmp += '\''; } mStateManager->SetErrorD(3001, ERROR, tmp.str()); Out.append_char(*c); c++; res = false; } else { /* on a trouve une correspondance */ Out.append(r); c+=iaux; } } return res; }