Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Player.hh"
- /**
- * Write the name of your player and save this file
- * with the same name and .cc extension.
- */
- #define PLAYER_NAME Eomer
- struct PLAYER_NAME : public Player {
- /**
- * Factory: returns a new instance of this class.
- * Do not modify this function.
- */
- static Player* factory () {
- return new PLAYER_NAME;
- }
- typedef vector<bool> Row;
- typedef vector<Row> Matriu;
- typedef vector<int> VE;
- struct Pos_info{
- Dir direction;
- Pos position;
- };
- /**
- * Types and attributes for your player can be defined here.
- */
- bool me_gusta_farmer(Pos pos_actual){
- if(cell(pos_actual).owner != 0) return puedo_ir_farmer(pos_actual); //No es mia
- else return false;
- }
- bool me_gusta_knight(Pos pos_actual){
- if((unit(cell(pos_actual)).type == Knight) or (unit(cell(pos_actual)).type == Farmer)) return puedo_ir_knight(pos_actual);
- else return false;
- }
- bool puedo_ir_farmer(Pos pos_destino){
- if((pos_destino.i < 37 and pos_destino.j < 37) and (pos_destino.i > 0 and pos_destino.j > 0)){
- if(cell(pos_destino).haunted or cell(pos_destino).type == Wall) return false; //embrujada o muro
- else if(cell(pos_destino).id != -1) return false; //alguien dentro
- return true;
- }
- return false;
- }
- bool puedo_ir_knight(Pos pos_destino){
- if((pos_destino.i < 37 and pos_destino.j < 37) and (pos_destino.i > 0 and pos_destino.j > 0)){
- if(cell(pos_destino).haunted or cell(pos_destino).type == Wall) return false; //embrujada o muro
- else if(unit(cell(pos_destino).id).player != 0) return false; //Quizas modificar
- return true;
- }
- return false;
- }
- void farmer(int id){
- bool trobat = false;
- Pos_info pos_actual;
- pos_actual.position = unit(id).pos;
- pos_actual.direction = None;
- Matriu posicions_visit(37, Row(37,false));
- queue<Pos_info> alvaro; //Elementos que quedan por visitar
- alvaro.push(pos_actual);
- while (not trobat and not alvaro.empty()){
- Pos aux = alvaro.front().position;
- Dir auxd = alvaro.front().direction;
- alvaro.pop();
- if (not posicions_visit[aux.i][aux.j]){
- posicions_visit[aux.i][aux.j] = true;
- if (me_gusta_farmer(aux)){
- Dir dire = auxd;
- trobat = true;
- }
- else{
- if(puedo_ir_farmer(Pos(aux.i, aux.j+1)) ){
- pos_actual pushaux;
- pushaux.position = Pos(aux.i, aux.j+1);
- pushaux.direction = auxd;
- if (pushaux.direction == None) pushaux.direction = Right;
- alvaro.push(pushaux);
- }
- if(puedo_ir_farmer(Pos(aux.i+1, aux.j))){
- pos_actual pushaux;
- pushaux.position = Pos(aux.i+1, aux.j);
- pushaux.direction = auxd;
- if (pushaux.direction == None) pushaux.direction = Right;
- alvaro.push(pushaux);
- }
- if(puedo_ir_farmer(Pos(aux.i, aux.j-1))){
- pos_actual pushaux;
- pushaux.position = Pos(aux.i, aux.j-1);
- pushaux.direction = auxd;
- if (pushaux.direction == None) pushaux.direction = Right;
- alvaro.push(pushaux);
- }
- if(puedo_ir_farmer(Pos(aux.i-1, aux.j))){
- pos_actual pushaux;
- pushaux.position = Pos(aux.i-1, aux.j);
- pushaux.direction = auxd;
- if (pushaux.direction == None) pushaux.direction = Right;
- alvaro.push(pushaux);
- }
- }
- }
- } command(id, dire);//OCULTA
- }
- void witch(int id){ //FALTA
- }
- void move_knight(int id, Pos pos_destino){
- int rando = random(0,1);
- Pos pos_actual = unit(id).pos;
- if(pos_actual.i == pos_destino.i){
- if(pos_actual.j == pos_destino.j) command(id,None);
- if(pos_actual.j < pos_destino.j){
- if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j+1))) command(id, Right);
- else if(puedo_ir_farmer(Pos(pos_actual.i+1,pos_actual.j))) command(id,Bottom);
- else if(puedo_ir_farmer(Pos(pos_actual.i-1,pos_actual.j))) command(id,Top);
- else if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j-1))) command(id,Left);
- else command(id,None);
- }
- else if(pos_actual.j > pos_destino.j){
- if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j-1))) command(id,Left);
- else if(puedo_ir_farmer(Pos(pos_actual.i+1,pos_actual.j))) command(id,Bottom);
- else if(puedo_ir_farmer(Pos(pos_actual.i-1,pos_actual.j))) command(id,Top);
- else if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j+1))) command(id, Right);
- else command(id,None);
- }
- }
- else if(pos_actual.i > pos_destino.i){
- if(pos_actual.j == pos_destino.j) command(id,Top);
- else if(pos_actual.j < pos_destino.j) command(id, Right);
- else if(pos_actual.j > pos_destino.j) command(id, Left);
- }
- else if(pos_actual.i < pos_destino.i){
- if(pos_actual.j == pos_destino.j) command(id,Bottom);
- else if(pos_actual.j < pos_destino.j) command(id, Right);
- else if(pos_actual.j > pos_destino.j) command(id, Left);
- }
- }
- void knight(int id){
- bool trobat = false;
- Pos pos_actual = unit(id).pos;
- Matriu posicions_visit(37, Row(37,false));
- queue<Pos> alvaro; //Elementos que quedan por visitar
- alvaro.push(pos_actual);
- while (not trobat and not alvaro.empty()){
- Pos aux = alvaro.front();
- alvaro.pop();
- if (not posicions_visit[aux.i][aux.j]){
- posicions_visit[aux.i][aux.j] = true;
- if (me_gusta_knight(aux)){
- move_knight(id,aux);
- trobat = true;
- }
- else{
- if(puedo_ir_knight(Pos(aux.i+1, aux.j+1))) alvaro.push(Pos(aux.i+1, aux.j+1)); //Abajo derecha
- if(puedo_ir_knight(Pos(aux.i, aux.j+1))) alvaro.push(Pos(aux.i, aux.j+1)); //Derecha
- if(puedo_ir_knight(Pos(aux.i+1, aux.j))) alvaro.push(Pos(aux.i+1, aux.j)); //Abajo
- if(puedo_ir_knight(Pos(aux.i-1, aux.j+1))) alvaro.push(Pos(aux.i-1, aux.j+1)); //Arriba derecha
- if(puedo_ir_knight(Pos(aux.i+1, aux.j-1))) alvaro.push(Pos(aux.i+1, aux.j-1)); //Abajo izquierda
- if(puedo_ir_knight(Pos(aux.i, aux.j-1))) alvaro.push(Pos(aux.i, aux.j-1)); //Izquierda
- if(puedo_ir_knight(Pos(aux.i-1, aux.j))) alvaro.push(Pos(aux.i-1, aux.j)); //Arriba
- if(puedo_ir_knight(Pos(aux.i-1, aux.j-1))) alvaro.push(Pos(aux.i-1, aux.j-1)); //Arriba izquierda
- }
- }
- }
- }
- /**
- * Play method, invoked once per each round.
- */
- virtual void play () {
- VE f = farmers(0);
- VE k = knights(0);
- VE w = witches(0);
- for (int id : f) {
- //cout << "Soy el farmer con id: " << id << endl;
- farmer(id); //movimiento farmer
- }
- for (int id : k) {
- //cout << "Soy el farmer con id: " << id << endl;
- knight(id); //movimiento knight
- }
- for (int id : w) {
- //cout << "Soy el farmer con id: " << id << endl;
- witch(id); //movimiento witches
- }
- }
- };
- /**
- * Do not modify the following line.
- */
- RegisterPlayer(PLAYER_NAME);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement