Fixing things

This commit is contained in:
Malte Tammena 2017-10-18 23:13:29 +02:00
parent 8ed7093d2d
commit 5df378e315
4 changed files with 18 additions and 8 deletions

View file

@ -4,6 +4,7 @@ import java.util.Random;
import player.Player; import player.Player;
import player.maurizio.MaurizioAI; import player.maurizio.MaurizioAI;
import player.malte.MalteAI;
/** /**
* Represents a game of Connect Four. * Represents a game of Connect Four.
@ -76,8 +77,8 @@ public class Game {
* @param runs The number of games to simulate. * @param runs The number of games to simulate.
*/ */
public static void simulate(int runs) { public static void simulate(int runs) {
Player p1 = new MaurizioAI(); Player p1 = new MaurizioAI("Maurizio");
Player p2 = new MalteAI(); Player p2 = new MalteAI("Malte");
// 0 - Draw // 0 - Draw
// 1 - p1 wins // 1 - p1 wins
// 2 - p2 wins // 2 - p2 wins
@ -88,13 +89,13 @@ public class Game {
statistic[result]++; statistic[result]++;
} }
System.out.println("Draws : " + statistic[0]); System.out.println("Draws : " + statistic[0]);
System.out.println("Maurizio: " + statistic[1] + " wins"); System.out.println(p1.getName() + ": " + statistic[1] + " wins");
System.out.println("Malte : " + statistic[2] + " wins"); System.out.println(p2.getName() + ": " + statistic[2] + " wins");
System.out.println("PERCENTAGE:"); System.out.println("PERCENTAGE:");
System.out.println("Draws : " + (statistic[0] / runs * 100.0) + "%"); System.out.println("Draws : " + (statistic[0] / runs * 100.0) + "%");
System.out.println("Maurizio: " + (statistic[1] / runs * 100.0) + "% wins"); System.out.println(p1.getName() + ": " + (statistic[1] / runs * 100.0) + "% wins");
System.out.println("Malte : " + (statistic[2] / runs * 100.0) + "% wins"); System.out.println(p2.getName() + ": " + (statistic[2] / runs * 100.0) + "% wins");
} }

View file

@ -4,5 +4,5 @@ public interface Player {
public int move(int[][] game); public int move(int[][] game);
public String getName(); public String getName();
public setPlayerID(int id); public void setPlayerID(int id);
} }

View file

@ -11,13 +11,17 @@ public class MalteAI implements Player{
private String name; private String name;
private Random ran; private Random ran;
private int id = 2; private int id;
public MalteAI(String name){ public MalteAI(String name){
this.name = name; this.name = name;
this.ran = new Random(); this.ran = new Random();
} }
public void setPlayerID(int id) {
this.id = id;
}
public int move(int[][] board){ public int move(int[][] board){
Set<Integer> options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6)); Set<Integer> options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6));
for (Integer i: copySet(options)) { for (Integer i: copySet(options)) {

View file

@ -8,12 +8,17 @@ public class MaurizioAI implements Player {
private String name; private String name;
private Random ran; private Random ran;
private int id;
public MaurizioAI(String name){ public MaurizioAI(String name){
this.name = name; this.name = name;
this.ran = new Random(); this.ran = new Random();
} }
public void setPlayerID(int id) {
this.id = id;
}
public int move(int[][] board){ public int move(int[][] board){
int choice = ran.nextInt(7); int choice = ran.nextInt(7);
while (board[choice][0] != 0) { while (board[choice][0] != 0) {