mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Compare commits
7 Commits
e5ea838430
...
223-create
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e4a343c4e | ||
|
|
c4b9378128 | ||
|
|
95e96583ec | ||
|
|
d02c7bd095 | ||
|
|
4e22c01bde | ||
|
|
c54b2a19e2 | ||
|
|
a6f5f2c854 |
@@ -20,4 +20,49 @@ public final class Main {
|
||||
// final ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||
// executor.execute(() -> testAIs(25));
|
||||
}
|
||||
|
||||
private static void testAIs(int games) {
|
||||
var versions = new ArtificialPlayer[5];
|
||||
versions[0] = new ArtificialPlayer(new RandomAI(), "Random AI");
|
||||
versions[1] = new ArtificialPlayer(new MCTSAI1(1000), "MCTS V1 AI");
|
||||
versions[2] = new ArtificialPlayer(new MCTSAI2(1000), "MCTS V2 AI");
|
||||
versions[3] = new ArtificialPlayer(new MCTSAI3(10, 10), "MCTS V3 AI");
|
||||
versions[4] = new ArtificialPlayer(new MCTSAI4(10, 10), "MCTS V4 AI");
|
||||
|
||||
for (int i = 0; i < versions.length; i++) {
|
||||
for (int j = i + 1; j < versions.length; j++) {
|
||||
final int playerIndex1 = i % versions.length;
|
||||
final int playerIndex2 = j % versions.length;
|
||||
|
||||
testAIVSAI(games, new ArtificialPlayer[] { versions[playerIndex1], versions[playerIndex2]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testAIVSAI(int games, ArtificialPlayer[] ais) {
|
||||
int wins = 0;
|
||||
int ties = 0;
|
||||
|
||||
for (int i = 0; i < games; i++) {
|
||||
final BitboardReversi match = new BitboardReversi();
|
||||
match.init(ais);
|
||||
|
||||
while (!match.isTerminal()) {
|
||||
final int currentAI = match.getCurrentTurn();
|
||||
final long move = ais[currentAI].getMove(match);
|
||||
|
||||
match.play(move);
|
||||
}
|
||||
|
||||
if (match.getWinner() < 0) {
|
||||
ties++;
|
||||
continue;
|
||||
}
|
||||
|
||||
wins += match.getWinner() == 0? 1 : 0;
|
||||
}
|
||||
|
||||
System.out.printf("Out of %d games, %s won %d -- tied %d -- lost %d, games against %s\n", games, ais[0].getName(), wins, ties, games - wins - ties, ais[1].getName());
|
||||
System.out.printf("Average win rate was: %.2f\n\n", wins / (float)games);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.view.GameView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.gameFramework.model.game.threadBehaviour.SupportsOnlinePlay;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
@@ -159,14 +158,8 @@ public class GenericGameController implements GameController {
|
||||
canvas.redraw(gameCopy);
|
||||
String gameType = game.getClass().getSimpleName().replace("Bitboard","");
|
||||
gameView.nextPlayer(true, getCurrentPlayer().getName(), game.getPlayer(1-getCurrentPlayerIndex()).getName(),gameType);
|
||||
if (gameType.equals("Reversi")) {
|
||||
BitboardReversi reversiGame = (BitboardReversi) game;
|
||||
BitboardReversi.Score reversiScore = reversiGame.getScore();
|
||||
gameView.setPlayer1Score(reversiScore.black());
|
||||
gameView.setPlayer2Score(reversiScore.white());
|
||||
if (getCurrentPlayer() instanceof LocalPlayer) {
|
||||
((ReversiBitCanvas)canvas).drawLegalDots(gameCopy);
|
||||
}
|
||||
if (getCurrentPlayer() instanceof LocalPlayer && gameType.equals("Reversi")){
|
||||
((ReversiBitCanvas)canvas).drawLegalDots(gameCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,13 @@ import org.toop.framework.game.players.OnlinePlayer;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ReversiBitController extends GenericGameController {
|
||||
|
||||
private BitboardReversi game;
|
||||
|
||||
public ReversiBitController(Player[] players) {
|
||||
BitboardReversi game = new BitboardReversi();
|
||||
game.init(players);
|
||||
|
||||
ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
|
||||
new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
|
||||
|
||||
super(new ReversiBitCanvas(), game, thread, "Reversi");
|
||||
}
|
||||
|
||||
public BitboardReversi.Score getScore() {
|
||||
return game.getScore();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.toop.app.widget.complex.ConfirmWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
|
||||
public final class GameOverPopup extends PopupWidget {
|
||||
public GameOverPopup(boolean winOrTie, String winner) {
|
||||
@@ -16,6 +15,7 @@ public final class GameOverPopup extends PopupWidget {
|
||||
else{
|
||||
confirmWidget.setMessage("It was a tie!");
|
||||
}
|
||||
|
||||
confirmWidget.addButton("ok", this::hide);
|
||||
|
||||
add(Pos.CENTER, confirmWidget);
|
||||
|
||||
@@ -26,8 +26,6 @@ public final class GameView extends ViewWidget {
|
||||
private final Text player2Header;
|
||||
private Circle player1Icon;
|
||||
private Circle player2Icon;
|
||||
private final Text player1Score;
|
||||
private final Text player2Score;
|
||||
private final Button forfeitButton;
|
||||
private final Button exitButton;
|
||||
private final TextField chatInput;
|
||||
@@ -42,8 +40,6 @@ public final class GameView extends ViewWidget {
|
||||
player2Header = Primitive.header("");
|
||||
player1Icon = new Circle();
|
||||
player2Icon = new Circle();
|
||||
player1Score = Primitive.header("");
|
||||
player2Score = Primitive.header("");
|
||||
|
||||
if (onForfeit != null) {
|
||||
forfeitButton = Primitive.button("forfeit", () -> onForfeit.run(), false);
|
||||
@@ -157,16 +153,14 @@ public final class GameView extends ViewWidget {
|
||||
private void setPlayerInfoReversi() {
|
||||
var player1box = Primitive.hbox(
|
||||
player1Icon,
|
||||
player1Header,
|
||||
player1Score
|
||||
player1Header
|
||||
);
|
||||
|
||||
player1box.getStyleClass().add("hboxspacing");
|
||||
|
||||
var player2box = Primitive.hbox(
|
||||
player2Icon,
|
||||
player2Header,
|
||||
player2Score
|
||||
player2Header
|
||||
);
|
||||
|
||||
player2box.getStyleClass().add("hboxspacing");
|
||||
@@ -184,12 +178,4 @@ public final class GameView extends ViewWidget {
|
||||
player2Icon.setFill(Color.BLACK);
|
||||
add(Pos.TOP_RIGHT, playerInfo);
|
||||
}
|
||||
|
||||
public void setPlayer1Score(int score) {
|
||||
player1Score.setText("(" + Integer.toString(score) + ")");
|
||||
}
|
||||
|
||||
public void setPlayer2Score(int score) {
|
||||
player2Score.setText("(" + Integer.toString(score) + ")");
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,7 @@ import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
*/
|
||||
public class ArtificialPlayer extends AbstractPlayer {
|
||||
|
||||
/**
|
||||
* The AI instance used to calculate moves.
|
||||
*/
|
||||
/** The AI instance used to calculate moves. */
|
||||
private final AI ai;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
package research;
|
||||
|
||||
public class AIData {
|
||||
public String AI;
|
||||
public long gamesPlayed;
|
||||
public double winrate;
|
||||
public double averageIterations;
|
||||
public double averageIterations10;
|
||||
public double averageIterations20;
|
||||
public double averageIterations30;
|
||||
|
||||
public AIData(String AI, long gamesPlayed, double winrate, double averageIterations, double averageIterations10, double averageIterations20, double averageIterations30) {
|
||||
this.AI = AI;
|
||||
this.gamesPlayed = gamesPlayed;
|
||||
this.winrate = winrate;
|
||||
this.averageIterations = averageIterations;
|
||||
this.averageIterations10 = averageIterations10;
|
||||
this.averageIterations20 = averageIterations20;
|
||||
this.averageIterations30 = averageIterations30;
|
||||
}
|
||||
|
||||
public String getAI() {
|
||||
return AI;
|
||||
}
|
||||
|
||||
public void setAI(String AI) {
|
||||
this.AI = AI;
|
||||
}
|
||||
|
||||
public long getGamesPlayed() {
|
||||
return gamesPlayed;
|
||||
}
|
||||
|
||||
public void setGamesPlayed(long gamesPlayed) {
|
||||
this.gamesPlayed = gamesPlayed;
|
||||
}
|
||||
|
||||
public double getWinrate() {
|
||||
return winrate;
|
||||
}
|
||||
|
||||
public void setWinrate(double winrate) {
|
||||
this.winrate = winrate;
|
||||
}
|
||||
|
||||
public double getAverageIterations() {
|
||||
return averageIterations;
|
||||
}
|
||||
|
||||
public void setAverageIterations(double averageIterations) {
|
||||
this.averageIterations = averageIterations;
|
||||
}
|
||||
|
||||
public double getAverageIterations10() {
|
||||
return averageIterations10;
|
||||
}
|
||||
|
||||
public void setAverageIterations10(double averageIterations10) {
|
||||
this.averageIterations10 = averageIterations10;
|
||||
}
|
||||
|
||||
public double getAverageIterations20() {
|
||||
return averageIterations20;
|
||||
}
|
||||
|
||||
public void setAverageIterations20(double averageIterations20) {
|
||||
this.averageIterations20 = averageIterations20;
|
||||
}
|
||||
|
||||
public double getAverageIterations30() {
|
||||
return averageIterations30;
|
||||
}
|
||||
|
||||
public void setAverageIterations30(double averageIterations30) {
|
||||
this.averageIterations30 = averageIterations30;
|
||||
}
|
||||
}
|
||||
@@ -1,447 +0,0 @@
|
||||
package research;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.players.ArtificialPlayer;
|
||||
import org.toop.game.players.ai.MCTSAI;
|
||||
import org.toop.game.players.ai.RandomAI;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI1;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI2;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI3;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI4;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AITest {
|
||||
|
||||
private static List<Matchup> matchupList = new ArrayList<Matchup>();
|
||||
private static List<AIData> dataList = new ArrayList<AIData>();
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
|
||||
var versions = new ArtificialPlayer[4];
|
||||
versions[0] = new ArtificialPlayer(new MCTSAI1(100), "MCTS V1");
|
||||
versions[1] = new ArtificialPlayer(new MCTSAI2(100), "MCTS V2");
|
||||
versions[2] = new ArtificialPlayer(new MCTSAI3(100, 8), "MCTS V3");
|
||||
versions[3] = new ArtificialPlayer(new MCTSAI4(100, 8), "MCTS V4");
|
||||
for (int i = 0; i < versions.length; i++) {
|
||||
for (int j = i + 1; j < versions.length; j++) {
|
||||
final int playerIndex1 = i % versions.length;
|
||||
final int playerIndex2 = j % versions.length;
|
||||
addMatch(versions[playerIndex1], versions[playerIndex2]);
|
||||
addMatch(versions[playerIndex2], versions[playerIndex1]); // home vs away system
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addMatch(ArtificialPlayer v1, ArtificialPlayer v2) {
|
||||
matchupList.add(new Matchup(v1, v2));
|
||||
}
|
||||
|
||||
public void addData(AIData data) {
|
||||
dataList.add(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAIvsAI() {
|
||||
for (Matchup m : matchupList) {
|
||||
playGame(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void playGame(Matchup m) {
|
||||
List<Integer> iterationsAI1 = new ArrayList<>();
|
||||
List<Integer> iterationsAI2 = new ArrayList<>();
|
||||
final BitboardReversi match = new BitboardReversi();
|
||||
ArtificialPlayer[] players = new ArtificialPlayer[2];
|
||||
players[0] = m.getPlayer1();
|
||||
players[1] = m.getPlayer2();
|
||||
match.init(players);
|
||||
while (!match.isTerminal()) {
|
||||
final int currentAI = match.getCurrentTurn();
|
||||
final long move = players[currentAI].getMove(match);
|
||||
if (players[currentAI].getAi() instanceof MCTSAI) {
|
||||
final int lastIterations = ((MCTSAI) players[currentAI].getAi()).getLastIterations();
|
||||
if (currentAI == 0) {
|
||||
iterationsAI1.add(lastIterations);
|
||||
} else {
|
||||
iterationsAI2.add(lastIterations);
|
||||
}
|
||||
}
|
||||
match.play(move);
|
||||
}
|
||||
generateData(m, match, iterationsAI1, iterationsAI2);
|
||||
}
|
||||
|
||||
public void generateData(Matchup matchup, BitboardReversi match, List<Integer> iterationsAI1, List<Integer> iterationsAI2) {
|
||||
boolean matchup1Found = false;
|
||||
boolean matchup2Found = false;
|
||||
for (AIData aiData : dataList) {
|
||||
if (aiData.getAI().equals(matchup.getPlayer1().getName())) {
|
||||
matchup1Found = true;
|
||||
} if (aiData.getAI().equals(matchup.getPlayer2().getName())) {
|
||||
matchup2Found = true;
|
||||
}
|
||||
}
|
||||
if (!(matchup1Found)) {
|
||||
addData(new AIData(matchup.getPlayer1().getName(), 0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
if (!(matchup2Found)) {
|
||||
addData(new AIData(matchup.getPlayer2().getName(), 0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
for (AIData aiData : dataList) { // set data for player 1
|
||||
if (aiData.getAI().equals(matchup.getPlayer1().getName())) {
|
||||
aiData.setGamesPlayed(aiData.getGamesPlayed() + 1);
|
||||
aiData.setWinrate(calculateWinrate(0, aiData.getWinrate(), aiData.getGamesPlayed(), match.getWinner()));
|
||||
aiData.setAverageIterations(calculateAverageIterations(aiData.getAverageIterations(), iterationsAI1));
|
||||
aiData.setAverageIterations10(calculateAverageIterationsStartEnd(0, 10, aiData.getAverageIterations10(), iterationsAI1));
|
||||
aiData.setAverageIterations20(calculateAverageIterationsStartEnd(10, 20, aiData.getAverageIterations20(), iterationsAI1));
|
||||
aiData.setAverageIterations30(calculateAverageIterationsStartEnd(20, iterationsAI1.size(), aiData.getAverageIterations30(), iterationsAI1));
|
||||
}
|
||||
}
|
||||
|
||||
for (AIData aiData : dataList) {
|
||||
if (aiData.getAI().equals(matchup.getPlayer2().getName())) {
|
||||
aiData.setGamesPlayed(aiData.getGamesPlayed() + 1);
|
||||
aiData.setWinrate(calculateWinrate(1, aiData.getWinrate(), aiData.getGamesPlayed(), match.getWinner()));
|
||||
aiData.setAverageIterations(calculateAverageIterations(aiData.getAverageIterations(), iterationsAI2));
|
||||
aiData.setAverageIterations10(calculateAverageIterationsStartEnd(0, 10, aiData.getAverageIterations10(), iterationsAI2));
|
||||
aiData.setAverageIterations20(calculateAverageIterationsStartEnd(10, 20, aiData.getAverageIterations20(), iterationsAI2));
|
||||
aiData.setAverageIterations30(calculateAverageIterationsStartEnd(20, iterationsAI2.size(), aiData.getAverageIterations30(), iterationsAI2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double calculateWinrate(int player, double winrate, long gamesPlayed, int winner) {
|
||||
double result;
|
||||
if (winner == 0 && player == 0 || winner == 1 && player == 1) {
|
||||
return (winrate * (gamesPlayed - 1) + 1) / gamesPlayed;
|
||||
} else if (winner == 0 && player == 1 || winner == 1 && player == 0) {
|
||||
return (winrate * (gamesPlayed - 1) + 0) / gamesPlayed;
|
||||
}
|
||||
return (winrate * (gamesPlayed - 1) + 0) / gamesPlayed;
|
||||
}
|
||||
|
||||
public double calculateAverageIterations(double averageIterations, List<Integer> thisGameIterations) {
|
||||
double thisGameIterationsAverage = 0;
|
||||
for (int iterations = 0; iterations < thisGameIterations.size(); iterations += 1) {
|
||||
thisGameIterationsAverage += thisGameIterations.get(iterations);
|
||||
}
|
||||
thisGameIterationsAverage /= thisGameIterations.size();
|
||||
return (averageIterations + thisGameIterationsAverage) / 2;
|
||||
}
|
||||
|
||||
public double calculateAverageIterationsStartEnd(int start, int end, double averageIterations, List<Integer> thisGameIterations) {
|
||||
double thisGameIterationsAverage = 0;
|
||||
for (int iterations = start; iterations < end; iterations += 1) {
|
||||
thisGameIterationsAverage += thisGameIterations.get(iterations);
|
||||
}
|
||||
thisGameIterationsAverage /= (end - start);
|
||||
return (averageIterations + thisGameIterationsAverage) / 2;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void writeAfterTests() {
|
||||
try {
|
||||
writeToCsv("Data.csv", dataList);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToCsv(String filepath, List<AIData> dataList) throws IOException {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filepath))) {
|
||||
writer.write("AI Name,Games Played,Winrate,Average Iterations,Average Iterations 0-10, Average Iterations 11-20, Average Iterations 20-30");
|
||||
writer.newLine();
|
||||
for (AIData data : dataList) {
|
||||
writer.write(
|
||||
data.getAI() + "," +
|
||||
data.getGamesPlayed() + "," +
|
||||
data.getWinrate() + "," +
|
||||
Math.round(data.getAverageIterations()) + "," +
|
||||
Math.round(data.getAverageIterations10()) + "," +
|
||||
Math.round(data.getAverageIterations20()) + "," +
|
||||
Math.round(data.getAverageIterations30()));
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public class AITest {
|
||||
|
||||
// private static int games = 2;
|
||||
//
|
||||
// @BeforeAll
|
||||
// public static void setUp() {
|
||||
// var versions = new ArtificialPlayer[5];
|
||||
// versions[0] = new ArtificialPlayer(new RandomAI(), "Random AI");
|
||||
// versions[1] = new ArtificialPlayer(new MCTSAI1(20), "MCTS V1 AI");
|
||||
// versions[2] = new ArtificialPlayer(new org.toop.game.players.ai.mcts.MCTSAI2(20), "MCTS V2 AI");
|
||||
// versions[3] = new ArtificialPlayer(new org.toop.game.players.ai.mcts.MCTSAI3(20, 10), "MCTS V3 AI");
|
||||
// versions[4] = new ArtificialPlayer(new MCTSAI4(20, 10), "MCTS V4 AI");
|
||||
//
|
||||
// for (int i = 0; i < versions.length; i++) {
|
||||
// for (int j = i + 1; j < versions.length; j++) {
|
||||
// final int playerIndex1 = i % versions.length;
|
||||
// final int playerIndex2 = j % versions.length;
|
||||
// addMatchup(versions[playerIndex1], versions[playerIndex2]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @BeforeEach
|
||||
// public void setUpEach() {
|
||||
// matchupList = new ArrayList<>();
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testIterationsInRealGame() {
|
||||
// for (int i = 0; i < matchups.size(); i++) {
|
||||
// testAIVSAI(games, getMatchup(i));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void testAIVSAI(int games, ArtificialPlayer[] ais) {
|
||||
//
|
||||
// List<List<Integer>> gamesList = new ArrayList<>();
|
||||
// for (int i = 0; i < games; i++) {
|
||||
// final BitboardReversi match = new BitboardReversi();
|
||||
// match.init(ais);
|
||||
//
|
||||
// List<Integer> iterations1 = new ArrayList<>();
|
||||
// List<Integer> iterations2 = new ArrayList<>();
|
||||
//
|
||||
// while (!match.isTerminal()) {
|
||||
// final int currentAI = match.getCurrentTurn();
|
||||
// final long move = ais[currentAI].getMove(match);
|
||||
// if (ais[currentAI].getAi() instanceof MCTSAI) {
|
||||
// final int lastIterations = ((MCTSAI) ais[currentAI].getAi()).getLastIterations();
|
||||
// if (currentAI == 0) {
|
||||
// iterations1.add(lastIterations);
|
||||
// } else if (currentAI == 1) {
|
||||
// iterations2.add(lastIterations);
|
||||
// }
|
||||
// }
|
||||
// match.play(move);
|
||||
// }
|
||||
// int winner = match.getWinner();
|
||||
// iterations1.addFirst(winner);
|
||||
//// iterations1.add(-999);
|
||||
// iterations1.addAll(iterations2);
|
||||
//
|
||||
// gamesList.add(iterations1);
|
||||
// }
|
||||
// matchupList.add(gamesList);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testIterationsAtFixedMove() {
|
||||
// for (ArtificialPlayer[] matchup : matchups) {
|
||||
// List<List<Integer>> gamesList = new ArrayList<>();
|
||||
// for (int j = 0; j < games; j++) {
|
||||
// final BitboardReversi match = new BitboardReversi();
|
||||
// match.init(matchup);
|
||||
//
|
||||
// List<Integer> iterations = new ArrayList<>();
|
||||
//
|
||||
// for (Long move : fixedMoveSet) {
|
||||
// match.play(move);
|
||||
// if (move == 32L) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//// iterations.add(-999);
|
||||
// var player = matchup[match.getCurrentTurn()];
|
||||
// for (int k = 0; k < 10; k++) {
|
||||
// player.getMove(match);
|
||||
// if (player.getAi() instanceof MCTSAI) {
|
||||
// iterations.add(((MCTSAI) player.getAi()).getLastIterations());
|
||||
// }
|
||||
// }
|
||||
// gamesList.add(iterations);
|
||||
// }
|
||||
// matchupList.add(gamesList);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void testIterationsInFixedGame() {
|
||||
// for (ArtificialPlayer[] matchup : matchups) {
|
||||
// List<List<Integer>> gamesList = new ArrayList<>();
|
||||
// for (int j = 0; j < games; j++) {
|
||||
// final BitboardReversi match = new BitboardReversi();
|
||||
// match.init(matchup);
|
||||
//
|
||||
// List<Integer> iterations = new ArrayList<>();
|
||||
//
|
||||
// iterations.add(-999);
|
||||
//
|
||||
// for (Long move : fixedMoveSet) {
|
||||
// var player = matchup[match.getCurrentTurn()];
|
||||
// player.getMove(match);
|
||||
// if (player.getAi() instanceof MCTSAI) {
|
||||
// iterations.add(((MCTSAI) player.getAi()).getLastIterations());
|
||||
// }
|
||||
// match.play(move);
|
||||
// }
|
||||
//
|
||||
// gamesList.add(iterations);
|
||||
// }
|
||||
// matchupList.add(gamesList);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @AfterEach
|
||||
// public void tearDown() {
|
||||
// data.add(matchupList);
|
||||
// }
|
||||
//
|
||||
// @AfterAll
|
||||
// public static void writeAfterTests() {
|
||||
// try {
|
||||
// writeToCsv("Data.csv", data);
|
||||
// } catch (IOException e) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void writeToCsv(String filepath, List<List<List<List<Integer>>>> data) throws IOException {
|
||||
// try (BufferedWriter writer = new BufferedWriter(new FileWriter(filepath))) {
|
||||
//
|
||||
// writer.write("TestID,Matchup,GameNr,Winner");
|
||||
// for (int i = 0; i < data.size(); i++) {
|
||||
// writer.write(",Iterations");
|
||||
// }
|
||||
//
|
||||
// writer.newLine();
|
||||
//
|
||||
// for (int TestID = 0; TestID < data.size(); TestID++) {
|
||||
// List<List<List<Integer>>> testCase = data.get(TestID);
|
||||
//
|
||||
// for (int matchupNr = 0; matchupNr < testCase.size(); matchupNr++) {
|
||||
// List<List<Integer>> matchup = testCase.get(matchupNr);
|
||||
//
|
||||
// for (int gameNr = 0; gameNr < matchup.size(); gameNr++) {
|
||||
// List<Integer> game = matchup.get(gameNr);
|
||||
// writer.write((TestID + 1) + "," + (getMatchupName(matchupNr)) + "," + (gameNr + 1));
|
||||
// for (int i = 0; i < game.size(); i++) {
|
||||
// if (i == 0) {
|
||||
// writer.write("," + getWinnerFromMatchup(game.get(i), matchupNr));
|
||||
// } else {
|
||||
// writer.write("," + game.get(i));
|
||||
// }
|
||||
// }
|
||||
// writer.newLine();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static final List<List<List<List<Integer>>>> data = new ArrayList<>();
|
||||
// private List<List<List<Integer>>> matchupList = new ArrayList<>();
|
||||
// private static final List<String> matchupNames = new ArrayList<>();
|
||||
// private static final List<ArtificialPlayer[]> matchups = new ArrayList<>();
|
||||
//
|
||||
// private static String getMatchupName(int matchupNr) {
|
||||
// return matchupNames.get(matchupNr);
|
||||
// }
|
||||
//
|
||||
// private static ArtificialPlayer[] getMatchup(int matchupNr) {
|
||||
// return matchups.get(matchupNr);
|
||||
// }
|
||||
//
|
||||
// private static String getWinnerFromMatchup(Integer winner, int matchupNr) {
|
||||
// String matchup = matchupNames.get(matchupNr);
|
||||
//
|
||||
// String[] parts = matchup.split(" vs ");
|
||||
//
|
||||
// if (parts.length != 2) {
|
||||
// return "Invalid matchup formatting.";
|
||||
// }
|
||||
//
|
||||
// return winner == 0 ? parts[0] : winner == 1 ? parts[1] : winner == -999 ? "NVT" : "Tie";
|
||||
// }
|
||||
//
|
||||
// private static void addMatchup(ArtificialPlayer player1, ArtificialPlayer player2) {
|
||||
// matchups.add(new ArtificialPlayer[]{player1, player2});
|
||||
// matchupNames.add(player1.getName() + " vs " + player2.getName());
|
||||
// }
|
||||
//}
|
||||
|
||||
// private final Long[] fixedMoveSet = new Long[]{17592186044416L,
|
||||
// 35184372088832L,
|
||||
// 67108864L,
|
||||
// 8796093022208L,
|
||||
// 2251799813685248L,
|
||||
// 288230376151711744L,
|
||||
// 70368744177664L,
|
||||
// 1125899906842624L,
|
||||
// 137438953472L,
|
||||
// 140737488355328L,
|
||||
// 4503599627370496L,
|
||||
// 2305843009213693952L,
|
||||
// 18014398509481984L,
|
||||
// 274877906944L,
|
||||
// 576460752303423488L,
|
||||
// -9223372036854775808L,
|
||||
// 549755813888L,
|
||||
// 1152921504606846976L,
|
||||
// 144115188075855872L,
|
||||
// 72057594037927936L,
|
||||
// 36028797018963968L,
|
||||
// 17179869184L,
|
||||
// 2199023255552L,
|
||||
// 1048576L,
|
||||
// 4398046511104L,
|
||||
// 281474976710656L,
|
||||
// 9007199254740992L,
|
||||
// 2147483648L,
|
||||
// 1073741824L,
|
||||
// 33554432L,
|
||||
// 262144L,
|
||||
// 8388608L,
|
||||
// 8192L,
|
||||
// 4611686018427387904L,
|
||||
// 4294967296L,
|
||||
// 524288L,
|
||||
// 4096L,
|
||||
// 16777216L,
|
||||
// 65536L,
|
||||
// 32L,
|
||||
// 2048L,
|
||||
// 8L,
|
||||
// 4L,
|
||||
// 8589934592L,
|
||||
// 16L,
|
||||
// 2097152L,
|
||||
// 4194304L,
|
||||
// 1024L,
|
||||
// 512L,
|
||||
// 16384L,
|
||||
// 536870912L,
|
||||
// 1099511627776L,
|
||||
// 64L,
|
||||
// 562949953421312L,
|
||||
// 128L,
|
||||
// 1L,
|
||||
// 32768L,
|
||||
// 2L,
|
||||
// 256L,
|
||||
// 131072L};
|
||||
// }
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package research;
|
||||
|
||||
import org.toop.framework.game.players.ArtificialPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Matchup {
|
||||
public ArtificialPlayer player1;
|
||||
public ArtificialPlayer player2;
|
||||
|
||||
public Matchup(ArtificialPlayer player1, ArtificialPlayer player2) {
|
||||
this.player1 = player1;
|
||||
this.player2 = player2;
|
||||
}
|
||||
|
||||
public Matchup() {}
|
||||
|
||||
public String toString() {
|
||||
return player1.toString() + " VS " + player2.toString();
|
||||
}
|
||||
|
||||
public ArtificialPlayer getPlayer1() {
|
||||
return player1;
|
||||
}
|
||||
|
||||
public ArtificialPlayer getPlayer2() {
|
||||
return player2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user