update mcts, incremental merge (#311)

* mcts v1, v2, v3, v4 done. v5 wip

* update mcts

* mcts v1, v2, v3, v4 done. v5 wip

* update mcts

* Merge changes on dev

* update mcts

---------

Co-authored-by: ramollia <>
This commit is contained in:
Bas Antonius de Jong
2026-01-17 04:05:11 +01:00
committed by GitHub
parent d078a70950
commit a6b2356a5e
15 changed files with 616 additions and 612 deletions

View File

@@ -1,53 +1,68 @@
package org.toop;
import org.toop.app.App;
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.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class Main {
static void main(String[] args) {
App.run(args);
// testMCTS(10);
// final ExecutorService executor = Executors.newFixedThreadPool(1);
// executor.execute(() -> testAIs(25));
}
// Voor onderzoek
// private static void testMCTS(int games) {
// var random = new ArtificialPlayer<>(new RandomAI<BitboardReversi>(), "Random AI");
// var v1 = new ArtificialPlayer<>(new MCTSAI<BitboardTicTacToe>(10), "MCTS V1 AI");
// var v2 = new ArtificialPlayer<>(new MCTSAI2<BitboardTicTacToe>(10), "MCTS V2 AI");
// var v2_2 = new ArtificialPlayer<>(new MCTSAI2<BitboardTicTacToe>(100), "MCTS V2_2 AI");
// var v3 = new ArtificialPlayer<>(new MCTSAI3<BitboardTicTacToe>(10), "MCTS V3 AI");
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");
// testAI(games, new Player[]{ v1, v2 });
// // testAI(games, new Player[]{ v1, v3 });
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;
// // testAI(games, new Player[]{ random, v3 });
// // testAI(games, new Player[]{ v2, v3 });
// testAI(games, new Player[]{ v2, v3 });
// // testAI(games, new Player[]{ v3, v2 });
// }
testAIVSAI(games, new ArtificialPlayer[] { versions[playerIndex1], versions[playerIndex2]});
}
}
}
// private static void testAI(int games, Player<BitboardReversi>[] ais) {
// int wins = 0;
// int ties = 0;
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(ais);
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);
while (!match.isTerminal()) {
final int currentAI = match.getCurrentTurn();
final long move = ais[currentAI].getMove(match);
// match.play(move);
// }
match.play(move);
}
// if (match.getWinner() < 0) {
// ties++;
// continue;
// }
if (match.getWinner() < 0) {
ties++;
continue;
}
// wins += match.getWinner() == 0? 1 : 0;
// }
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);
// }
}
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);
}
}

View File

@@ -20,8 +20,7 @@ import org.toop.framework.networking.connection.clients.TournamentNetworkingClie
import org.toop.framework.networking.connection.events.NetworkEvents;
import org.toop.framework.networking.connection.types.NetworkingConnector;
import org.toop.framework.networking.server.gateway.NettyGatewayServer;
import org.toop.framework.game.players.LocalPlayer;
import org.toop.game.players.ai.MCTSAI3;
import org.toop.game.players.ai.mcts.MCTSAI3;
import org.toop.local.AppContext;
import java.util.Arrays;
@@ -211,7 +210,7 @@ public final class Server {
Player[] players = new Player[2];
players[userStartingTurn] = new ArtificialPlayer(new MCTSAI3(1000), user);
players[userStartingTurn] = new ArtificialPlayer(new MCTSAI3(1000, Runtime.getRuntime().availableProcessors()), user);
players[opponentStartingTurn] = new OnlinePlayer(response.opponent());
switch (type) {

View File

@@ -4,6 +4,7 @@ import javafx.application.Platform;
import org.toop.app.GameInformation;
import org.toop.app.gameControllers.ReversiBitController;
import org.toop.app.gameControllers.TicTacToeBitController;
import org.toop.framework.game.players.LocalPlayer;
import org.toop.framework.gameFramework.controller.GameController;
import org.toop.framework.gameFramework.model.player.Player;
import org.toop.framework.game.players.ArtificialPlayer;
@@ -12,11 +13,10 @@ import org.toop.app.widget.complex.PlayerInfoWidget;
import org.toop.app.widget.complex.ViewWidget;
import org.toop.app.widget.popup.ErrorPopup;
import org.toop.app.widget.tutorial.*;
import org.toop.framework.game.players.LocalPlayer;
import org.toop.game.players.ai.MCTSAI;
import org.toop.game.players.ai.MCTSAI2;
import org.toop.game.players.ai.MCTSAI3;
import org.toop.game.players.ai.MiniMaxAI;
import org.toop.game.players.ai.mcts.MCTSAI1;
import org.toop.game.players.ai.mcts.MCTSAI3;
import org.toop.game.players.ai.mcts.MCTSAI4;
import org.toop.local.AppContext;
import javafx.geometry.Pos;
@@ -54,7 +54,7 @@ public class LocalMultiplayerView extends ViewWidget {
if (information.players[0].isHuman) {
players[0] = new LocalPlayer(information.players[0].name);
} else {
players[0] = new ArtificialPlayer(new MCTSAI(100), "MCTS AI");
players[0] = new ArtificialPlayer(new MCTSAI1(100), "MCTS AI");
}
if (information.players[1].isHuman) {
players[1] = new LocalPlayer(information.players[1].name);
@@ -83,12 +83,12 @@ public class LocalMultiplayerView extends ViewWidget {
players[0] = new LocalPlayer(information.players[0].name);
} else {
// players[0] = new ArtificialPlayer(new RandomAI<BitboardReversi>(), "Random AI");
players[0] = new ArtificialPlayer(new MCTSAI3(50), "MCTS V3 AI");
players[0] = new ArtificialPlayer(new MCTSAI4(500, 4), "MCTS V4 AI");
}
if (information.players[1].isHuman) {
players[1] = new LocalPlayer(information.players[1].name);
} else {
players[1] = new ArtificialPlayer(new MCTSAI(50), "MCTS V1 AI");
players[1] = new ArtificialPlayer(new MCTSAI1(500), "MCTS V1 AI");
}
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
new ShowEnableTutorialWidget(