Skip to content

Commit

Permalink
ataque de bot estrategico
Browse files Browse the repository at this point in the history
  • Loading branch information
ander authored and ander committed May 14, 2023
1 parent daea370 commit dd3ead6
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Modelo/Agua.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public Agua(int i) {

@Override
public boolean recibeAtaqueEfectivo(String pTipo) {
return pTipo.equals("Fuego") || pTipo.equals("Roca");
return pTipo.equals("Fuego") || pTipo.equals("Roca") || pTipo.equals("Tierra");
}

@Override
public boolean recibeAtaquePocoEfectivo(String pTipo) {
return pTipo.equals("Electrico");
return pTipo.equals("Electrico") || pTipo.equals("Dragon");
}

}
35 changes: 29 additions & 6 deletions src/Modelo/Bot.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package Modelo;

import java.util.ArrayList;
import java.util.stream.Collectors;

public class Bot extends Jugador {

private boolean turno;
Expand All @@ -11,7 +14,7 @@ public Bot(int pNumPoke, int id) {
}

@SuppressWarnings("deprecation")
public void setTurno(boolean pTurno, int longitud) {
public void setTurno(boolean pTurno) {
this.turno = pTurno;

setChanged();
Expand All @@ -20,8 +23,8 @@ public void setTurno(boolean pTurno, int longitud) {

//System.out.println("Ha cambiado el turno a" + pTurno);
if (this.turno) {
ataquedeBot(longitud);

//ataquedeBot();
ataquedeBotInteligente();
// atacarBot elige atacante aleatorio que no sea this
ListaJugadores.getListaJugadores().asignarTurnoAleatoriamente();

Expand All @@ -31,13 +34,13 @@ public void setTurno(boolean pTurno, int longitud) {

}

private void ataquedeBot(int longitud){
private void ataquedeBot(){
{
for(int i=1;i<=this.tamainoLista();i++) {
Pokemon pokAtaque= this.getPokemon(i);
/*int numJug = ListaJugadores.getListaJugadores().tamainoLista();
int jugadorAtac = (int)(Math.random()*(numJug));*/
int jugadorAtacado = (int)(Math.random()*(longitud)); // aki tendríamos que hacer una adjudicación con random && !bot
int jugadorAtacado = (int)(Math.random()*(ListaJugadores.getListaJugadores().tamainoLista())); // aki tendríamos que hacer una adjudicación con random && !bot
int numPok = this.tamainoLista();
int pokAtacado = (int)(Math.random()*(numPok));
pokAtacado++;
Expand All @@ -57,6 +60,26 @@ private void ataquedeBot(int longitud){
}
}
}


private void ataquedeBotInteligente(){
ArrayList<String> tipos = (ArrayList<String>) (this.getListaPok().stream().map(p -> p.getTipo()).collect(Collectors.toList()));
int idJug = ListaJugadores.getListaJugadores().pokemonEfectivo(tipos);
System.out.println("Soy el jugador: " + this.getId());
System.out.println("El id del jugador al que ataco es: " + idJug + " y el número de Pokemons efectivos q tiene es: " + ListaJugadores.getListaJugadores().buscarJugador(idJug).numPokEfectivos(tipos) );
if (idJug != this.getId()) {
for (int i=1;i<=this.tamainoLista();i++) {
Pokemon pokAtaque = this.getPokemon(i);
Pokemon pokDefensa = ListaJugadores.getListaJugadores().buscarJugador(idJug).getPokemon(i);
if (!pokDefensa.seHaDebilitado() && !pokAtaque.seHaDebilitado()) {
CampoDeBatalla.getCampoBatalla().realizarAtaques(pokAtaque,pokDefensa);
}
if (pokAtaque.estaEuforico()) {
pokAtaque.cambiarEstado(new EstadoNormal());
pokDefensa.quitarEstadoEuforia(pokAtaque);
pokAtaque.setAquesEuforiaAcumulados(0);
}
CampoDeBatalla.getCampoBatalla().eliminarBatalla();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Modelo/Electrico.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public boolean recibeAtaqueEfectivo(String pTipo){

@Override
public boolean recibeAtaquePocoEfectivo(String pTipo) {
return pTipo.equals("Planta");
return pTipo.equals("Planta") || pTipo.equals("Tierra");
}

}
4 changes: 2 additions & 2 deletions src/Modelo/Fuego.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public Fuego(int i) {

@Override
public boolean recibeAtaqueEfectivo(String pTipo) {
return pTipo.equals("Planta") || pTipo.equals("Bicho");
return pTipo.equals("Planta") || pTipo.equals("Bicho") || pTipo.equals("Hielo") || pTipo.equals("Acero");
}

@Override
public boolean recibeAtaquePocoEfectivo(String pTipo) {
return pTipo.equals("Agua") || pTipo.equals("Roca");
return pTipo.equals("Agua") || pTipo.equals("Roca") || pTipo.equals("Tierra") || pTipo.equals("Dragon");
}

}
20 changes: 19 additions & 1 deletion src/Modelo/Jugador.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package Modelo;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Queue;
import java.util.stream.Collectors;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -50,7 +52,7 @@ public int getId() {
return this.id;
}

public void setTurno(boolean pTurno, int longitud) {
public void setTurno(boolean pTurno) {
this.turno = pTurno;
setChanged();
notifyObservers(new Object[] {pTurno});
Expand Down Expand Up @@ -142,5 +144,21 @@ public void eliminarPokemon() {
public int tamainoLista () {
return lPokemon.size();
}

public int numPokEfectivos (ArrayList<String> tipos) {
int num = 0;
for (String t: tipos) {
for (Pokemon p: lPokemon) {
if (p.recibeAtaquePocoEfectivo(t) && !p.seHaDebilitado()) {
num++;
}
}
}
return num;
}

protected ArrayList<Pokemon> getListaPok(){
return this.lPokemon;
}

}
19 changes: 17 additions & 2 deletions src/Modelo/ListaJugadores.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Modelo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Observable;
import java.util.function.Consumer;
Expand Down Expand Up @@ -98,12 +99,12 @@ public int jugadorGanador() {
while (itr.hasNext())
{
jug = itr.next();
jug.setTurno(false, this.tamainoLista());
jug.setTurno(false);
jug.resetearPokemon();
}
//Finalmente, elegimos un jugador al azar y le ponemos el turno a true
jug = this.buscarJugador(turno);
jug.setTurno(true, this.tamainoLista());
jug.setTurno(true);
}
//setChanged();
//notifyObservers(new Object[] {jug});
Expand Down Expand Up @@ -136,4 +137,18 @@ public void terminarTurno() {
public int tamainoLista() {
return lJugadores.size();
}

public int pokemonEfectivo(ArrayList<String> tipos){ /*Mejor hacerlo con Java8*/
int max = 0;
int idMax = 0;
int num = 0;
for (Jugador j: lJugadores) {
num = j.numPokEfectivos(tipos);
if (num> max) {
idMax = j.getId();
max = num;
}
}
return idMax;
}
}
4 changes: 4 additions & 0 deletions src/Modelo/Pokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void setAquesEuforiaAcumulados(int pAtaque) {
ataquesEuforiaAcumulados = pAtaque;
}

public String getTipo () {
return this.tipo;
}

public void setHaAtacadoEuforico(boolean pHaAtacadoEuforico) {
this.haAtacadoEuforico = pHaAtacadoEuforico;
}
Expand Down

0 comments on commit dd3ead6

Please sign in to comment.