Last active
June 8, 2018 15:14
-
-
Save delucas/f2bb66a4f637580319e4c1504d95d8af to your computer and use it in GitHub Desktop.
2018a - Desafío IA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unlam.ai; | |
public enum Forma { | |
PIEDRA, PAPEL, TIJERA; | |
public Resultado jugarCon(Forma otra) { | |
if (this.equals(otra)) return Resultado.EMPATE; | |
if (this.equals(PAPEL) && otra.equals(PIEDRA) || | |
this.equals(PIEDRA) && otra.equals(TIJERA) || | |
this.equals(TIJERA) && otra.equals(PAPEL)) { | |
return Resultado.GANADOR; | |
} | |
return Resultado.PERDEDOR; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unlam.ai; | |
/** | |
* Los participantes del torneo de Piedra/Papel/Tijera (PPT) deberán realizar un bot | |
* que implemente esta interfaz. Se explicará cada método en su correspondiente Javadoc. | |
* ¡Que tengan una buena y feliz competencia! | |
* | |
*/ | |
public interface Jugador { | |
/** | |
* Este es el primer método que se ejecutará. | |
* @return la forma que jugará. Devolver null en cualquier momento se penalizará con | |
* la pérdida automática de esa mano. | |
*/ | |
public Forma jugar(); | |
/** | |
* Este es el método de feedback. Gracias a éste el bot se enterará cómo le fue en la | |
* partida inmediatamente anterior. Ejemplo: si jugó PIEDRA, y el otro jugador jugó | |
* TIJERA, se le invocará al bot este método con los parámetros GANA, TIJERA. | |
* Se sugiere aprovechar este método para que el bot aprenda del rival. | |
* @param resultado cómo terminó la partida inmediata anterior | |
* @param formaDelOtro qué jugó el rival. PUEDE SER NULA | |
*/ | |
public void resultado(Resultado resultado, Forma formaDelOtro); | |
/** | |
* Este es el método que se invocará cuando cambie el rival. Queda bajo la | |
* responsabilidad de quien programe el bot si desea "borrarle la memoria", o | |
* mantener la información para algún fin. | |
* Se recuerda que distintos oponentes responden a distinta lógica, y salvo casos | |
* muy puntuales, no tiene sentido recordar la estrategia del rival anterior. | |
*/ | |
public void olvidar(); | |
/** | |
* Con este método se mostrará en la pantalla el bot. | |
* @return El nombre del bot jugador | |
*/ | |
public String toString(); | |
/** | |
* @return un array con los nombres completos e ids de | |
* los integrantes que desarrollaron el bot. | |
* Ejemplo: ["Lucas Videla (100)", "Federico Gasior (101)", "Julio Crispino (102)"] | |
*/ | |
public String[] integrantes(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unlam.ai; | |
public class JugadorDummy implements Jugador { | |
@Override | |
public Forma jugar() { | |
return Forma.PIEDRA; | |
} | |
@Override | |
public void resultado(Resultado resultado, Forma formaDelOtro) { | |
// La buena piedra nunca me fallará | |
} | |
@Override | |
public String toString() { | |
return "La Buena Piedra"; | |
} | |
@Override | |
public void olvidar() { | |
} | |
@Override | |
public String[] integrantes() { | |
return new String[]{"Bart Simpson"}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unlam.ai; | |
public enum Resultado { | |
GANADOR, PERDEDOR, EMPATE; | |
public Resultado contraria() { | |
if (this.equals(GANADOR)) return Resultado.PERDEDOR; | |
if (this.equals(PERDEDOR)) return Resultado.GANADOR; | |
return EMPATE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment