int main (){ int i, j, sens; PP_Pos pos; PP_Unit u, select, tmp; bool attaque; float distance, dx, dy; PP_PendingCommands cmd; // ouverture du jeu PP_Open(); // determination de la direction de l'attaque if (PP_GetStartPosition().x < PP_GetMapSize().x/2) sens = 1; else sens = -1; // lancer la marche for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){ pos = PP_Unit_GetPosition(PP_GetUnitAt(MY_COALITION, i)); if (sens == -1) pos.x = 10; else pos.x = PP_GetMapSize().x - 10; PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos); } // attendre le départ de l'armée while (!mobile()) printf("Attente depart armee\n"); // ordonner d'attaquer les bytes ennemis while (!PP_IsGameOver()){ if (PP_GetNumUnits(ENEMY_COALITION) == 0){ // faire une recherche aléatoire for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){ u = PP_GetUnitAt(MY_COALITION, i); if (PP_Unit_GetPendingCommands(u, &cmd) != -1){ if (cmd.nbCmds == 0){ pos.x = rand() % (int)PP_GetMapSize().x + 1; pos.y = rand() % (int)PP_GetMapSize().y + 1; PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos); } } } } else{ // ordonner aux unités qui n'attaquent pas de cibler l'unité ennemie la plus proche d'elle for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){ printf(" %d", i); u = PP_GetUnitAt(MY_COALITION, i); if (PP_Unit_GetPendingCommands(u, &cmd) != -1){ attaque = false; if (cmd.nbCmds == 0) attaque = true; else if (cmd.nbCmds > 0) if (cmd.cmd[0].code != ATTACK) attaque = true; if (attaque){ pos = PP_Unit_GetPosition(u); // calcul de la distance max pour cette carte distance = PP_GetMapSize().x*PP_GetMapSize().x+PP_GetMapSize().y*PP_GetMapSize().y; select = -1; for (j = 0 ; j < PP_GetNumUnits(ENEMY_COALITION) ; j++){ tmp = PP_GetUnitAt(ENEMY_COALITION, j); dx = pos.x - PP_Unit_GetPosition(tmp).x; dy = pos.y - PP_Unit_GetPosition(tmp).y; if (dx*dx+dy*dy < distance){ distance = dx*dx+dy*dy; select = tmp; } } if (select != -1) PP_Unit_ActionOnUnit(u, ATTACK, select); } } else{ printf("%s", PP_GetError()); } } printf("\n"); } } // fermer le jeu PP_Close(); return 0; }
int main (){ int i, j, sens, distance; PP_Pos pos; PP_Unit u; Groupe armee; Groupe groupes [NB_GROUPES]; bool premierLancement, enFuite; // ouverture du jeu PP_Open(); // initialisation de l'armée initialiseBytes(&armee); // determination de la direction de l'attaque if (PP_GetStartPosition().x < PP_GetMapSize().x/2) sens = 1; else sens = -1; // lancer l'attaquer premierLancement = true; while (!PP_IsGameOver()){ traiterUnitesDetruites(&armee); printf(" Taille armee : %d\n", armee.nbMembres); // restructurer les groupes trierSelon(&armee, Y); affecterGroupes(armee, groupes, 8); printf(" Affichage des groupes : \n"); for (i = 0 ; i < NB_GROUPES ; i++) printf(" groupe %d : %d\n", i, groupes[i].nbMembres); if (PP_GetNumUnits(ENEMY_COALITION) == 0){ // rechercher l'adversaire if (premierLancement){ // si premier lancement, avancer en formation printf(" Lancer la marche\n"); distance = sens*PP_GetMapSize().x; progresser(armee, distance); premierLancement = false; // attendre que l'armée ai commence a bouger (rester vigilant quand à la // présence de l'ennemie) while (PP_GetNumUnits(ENEMY_COALITION) == 0 && !mobile(armee)) printf("Attente depart armee\n"); } else{ // rechercher aléatoirement l'adversaire for (i = 0 ; i < NB_GROUPES ; i++){ if (!mobile(groupes[i])){ pos.x = rand() % (int)PP_GetMapSize().x + 1; pos.y = rand() % (int)PP_GetMapSize().y + 1; for (j = 0 ; j < groupes[i].nbMembres ; j++) PP_Unit_ActionOnPosition(groupes[i].membres[j], MOVE, pos); } } } } else{ // Affecter une cible à chaque groupes for (i = 0 ; i < NB_GROUPES ; i++){ u = determinerCible(groupes[i]); printf(" Cible pour le groupe %d : %d\n", i, u); // pour chaque membre du groupe, donner l'ordre d'attaque si necessaire for (j = 0 ; j < groupes[i].nbMembres ; j++) if (!enAttaque(groupes[i].membres[j], u)) PP_Unit_ActionOnUnit(groupes[i].membres[j], ATTACK, u); } } } // fermer le jeu PP_Close(); return 0; }
/** \brief Superpose mob on ref Calculates a 4x4 transformation Matrix that should be applied on 'mob' in order to minimize RMSD between mob and ref. Algorithm taken from Sippl et Stegbuchner. Computers Chem. Vol 15, No. 1, p 73-78, 1991. */ Superpose_t superpose(const Rigidbody& ref, const Rigidbody& mob, int verbosity) { Rigidbody reference(ref); //copie de ref pour pouvoir centrer Rigidbody mobile(mob); // copie de mobile if (ref.Size()!=mob.Size()) {std::cout << "Error in superpose.cpp: \ the two AtomSelection objects must have\ the same size !" << std::endl; abort();}; Mat33 rot; Mat33 ident; for (uint i=0; i<3; i++) for(uint j=0; j<3; j++) if (i!=j) {ident[i][j]=0;} else {ident[i][j]=1;} ; //find the translational component Coord3D t0 = ref.FindCenter(); Coord3D t1 = mob.FindCenter(); //centre les deux objets: reference.CenterToOrigin(); mobile.CenterToOrigin(); Mat33 U; //mixed tensor MakeTensor(reference, mobile, U); for(uint i=0; i<35; i++) { double arg1,arg2; arg1 = U[2][1] - U[1][2] ; arg2 = U[1][1] + U[2][2]; double alpha = atan2(arg1 , arg2 ); XRotMatrix(-alpha, rot); Mat33xMat33(rot,ident,ident); //------------------------------------ Mat33xMat33(rot,U,U); arg1 = U[2][0]-U[0][2]; arg2 = U[0][0]+U[2][2]; double beta = atan2(arg1,arg2); YRotMatrix(beta,rot); Mat33xMat33(rot,ident,ident); //-------------------------------------- Mat33xMat33(rot,U,U); arg1 = U[1][0] - U[0][1]; arg2 = U[0][0] + U[1][1]; double gamma = atan2(arg1,arg2); ZRotMatrix(-gamma,rot); Mat33xMat33(rot,ident,ident); Mat33xMat33(rot,U,U); } //creates a 4x4 matrix that tracks transformations for mobile Mat44 tracker; MakeTranslationMat44(Coord3D()-t1,tracker); //copy the 3x3 matrix into a 4x4 matrix Mat44 rotation; MakeTranslationMat44(Coord3D(),rotation); //identity matrix; for (int i=0; i<3; i++) for (int j=0; j<3; j++) rotation[i][j]=ident[i][j]; mat44xmat44(rotation, tracker, tracker); MakeTranslationMat44(t0, rotation); mat44xmat44(rotation, tracker, tracker); Matrix output(4,4); for (int i=0; i<4; i++) for (int j=0; j<4;j++) output(i,j)=tracker[i][j]; Superpose_t sup; sup.matrix = output; Rigidbody probe(mob); probe.ApplyMatrix(output); sup.rmsd = Rmsd(ref,probe); return sup; // screw = MatTrans2screw(ident, t0, t1); // screw.point = screw.point + t1 ; /* if (verbosity==1) { Rigidbody newmob(mob); Rigidbody newref(ref); selref.setRigid(newref); selmob.setRigid(newmob); newmob.transform(screw); std::cout << "verif screw, rmsdca = " << rmsd(selmob && CA(newmob),selref && CA(newref)) << std::endl ; } */ // return screw; } }