Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Player.hh"
- #include <queue>
- #include <list>
- using namespace std;
- /**
- * Escriu el nom * del teu jugador i guarda
- * aquest fitxer amb el nom AI*.cc
- */
- #define PLAYER_NAME Jonator
- /**
- * Podeu declarar constants aquÃ
- */
- const int CAOTIC = 1;
- const int CICLIC = 2;
- const int X[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- const int Y[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
- struct PLAYER_NAME : public Player {
- /**
- * Factory: retorna una nova instà ncia d'aquesta classe.
- * No toqueu aquesta funció.
- */
- static Player* factory () {
- return new PLAYER_NAME;
- }
- /**
- * Els atributs dels vostres jugadors es poden definir aquÃ.
- */
- typedef vector<int> VE;
- typedef map<int, int> MEE;
- typedef MEE::iterator MI;
- typedef vector<vector<P> > G;
- typedef vector<VE> VVE;
- typedef vector<bool> VB;
- typedef vector<VB> VVB;
- typedef vector<vector<bool> > Graf;
- typedef vector<vector<Posicio> > Graf2;
- //MEE personalitat; // Guarda la personalitat dels soldats entre torns.
- Posicio bfs(int i, int j) {
- bool primer = true;
- queue< Posicio > q;
- q.push(Posicio(i, j));
- Graf g (60, vector<bool> (60, false));
- Graf2 gg (60, vector<Posicio> (60));
- while (not q.empty()) {
- Posicio pos = q.front(); q.pop();
- if (quin_soldat(pos.x,pos.y) > 0) {return gg[pos.x][pos.y];}
- if (valor_post(pos.x,pos.y) > 0) {return gg[pos.x][pos.y];}
- g[pos.x][pos.y] = true;
- if (primer) {
- for(int i=0; i<8; ++i)
- {
- int a = pos.x+X[i], b = pos.y+Y[i];
- if(valid(a, b) and not g[a][b] and (que(a,b) == GESPA or que(a,b) == BOSC)) {
- q.push(Posicio(a, b));
- gg[a][b].x = a;
- gg[a][b].y = b;
- }
- }
- primer = false;
- } else {
- for(int i=0; i<8; ++i)
- {
- int a = pos.x+X[i], b = pos.y+Y[i];
- if(valid(a, b) and not g[a][b] and (que(a,b) == GESPA or que(a,b) == BOSC)) {
- q.push(Posicio(a, b));
- gg[a][b].x = gg[pos.x][pos.y].x;
- gg[a][b].y = gg[pos.x][pos.y].y;
- }
- }
- }
- }
- return Posicio(i,j);
- }
- void juga_soldat(int equip, int id) {
- Info in = dades(id);
- int x = in.pos.x;
- int y = in.pos.y;
- Posicio p = bfs(x,y);
- //if (xx >= 0 and xx < MAX and yy >= 0 and yy < MAX)
- ordena_soldat(id, p.x, p.y);
- }
- /* void juga_soldat(int equip, int id) {
- MI p = personalitat.find(id);
- // Els soldats que encara no estan decidits, els fem cÃclics
- // amb probabilitat 0.4, i caòtics altrament.
- if (p == personalitat.end())
- //personalitat[id] = (probabilitat(0.4) ? CICLIC : CAOTIC);
- personalitat[id] = CICLIC;
- int pers = personalitat[id];
- Info in = dades(id);
- int x = in.pos.x;
- int y = in.pos.y;
- for (int i = 0; i < 8; ++i) {
- int xx = x + X[i];
- int yy = y + Y[i];
- if (xx >= 0 and xx < MAX and yy >= 0 and yy < MAX) {
- int id2 = quin_soldat(xx, yy);
- // Si tenim un enemic al costat, l'ataquem.
- if (id2 and dades(id2).equip != equip) {
- ordena_soldat(id, xx, yy);
- return;
- }
- }
- }
- //P pos = BFS();
- //if (xx >= 0 and xx < MAX and yy >= 0 and yy < MAX)
- //ordena_soldat(id, xx, yy);
- }
- */
- void juga_heli(int equip, int id) {
- Info in = dades(id);
- int x = in.pos.x;
- int y = in.pos.y;
- int suma = 0;
- for (int i = -ABAST; i <= ABAST; ++i)
- for (int j = -ABAST; j <= ABAST; ++j) {
- int xx = x + i;
- int yy = y + j;
- if (xx >= 0 and xx < MAX and yy >= 0 and yy < MAX) {
- int id2 = quin_soldat(xx, yy);
- if (id2 and dades(id2).equip != equip) ++suma;
- }
- }
- // Si tenim 3 o més enemics a sota, intentem llençar napalm.
- if (suma >= 3 and dades(id).napalm == 0) {
- ordena_helicopter(id, NAPALM);
- return;
- }
- // Amb probabilitat 20% girem en el sentit contrari de les agulles del rellotge,
- // altrament intentem avançar dos passos.
- int c = uniforme(1, 5);
- ordena_helicopter(id, c == 1 ? CONTRA_RELLOTGE : AVANCA2);
- }
- void llenca_paracaigudista(int heli_id) {
- // Obtenim les dades de l'helicòpter...
- Info in = dades(heli_id);
- // ... i intentem llencar un paracaigudista, sense ni mirar el terreny.
- /*int xx = in.pos.x + uniforme(-2, 2);
- int yy = in.pos.y + uniforme(-2, 2);
- if (xx >= 0 and xx < MAX and yy >= 0 and yy < MAX)
- ordena_paracaigudista(xx, yy);*/
- int xx = in.pos.x;
- int yy = in.pos.y;
- }
- /**
- * Mètode play.
- *
- * Aquest mètode serà invocat una vegada cada torn.
- */
- virtual void play () {
- int equip = qui_soc();
- VE H = helis(equip); // helicòpters del meu equip
- VE S = soldats(equip); // soldats del meu equip
- // si en un helicòpter escollit a l'atzar tinc paracaigudistes, en llenço un.
- for (int i = 0; i < (int)H.size(); ++i) {
- int heli_id = H[i];
- if (not dades(heli_id).paraca.empty()) llenca_paracaigudista(heli_id);
- }
- //if (not dades(heli_id).paraca.empty()) llenca_paracaigudista(heli_id);
- for (int i = 0; i < (int)H.size(); ++i) juga_heli(equip, H[i]);
- for (int i = 0; i < (int)S.size(); ++i) juga_soldat(equip, S[i]);
- }
- };
- /**
- * No toqueu aquesta lÃnia.
- */
- RegisterPlayer(PLAYER_NAME);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement