mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
bitboard fix & mcts v2 & mcts v3. v3 still in progress and v4 coming soon
This commit is contained in:
@@ -1,9 +1,61 @@
|
||||
package org.toop;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.gameFramework.model.player.AbstractPlayer;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.game.games.reversi.BitboardReversi;
|
||||
import org.toop.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.game.players.ArtificialPlayer;
|
||||
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.RandomAI;
|
||||
|
||||
public final class Main {
|
||||
static void main(String[] args) {
|
||||
App.run(args);
|
||||
// App.run(args);
|
||||
testMCTS(10);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
testAI(games, new Player[]{ v1, v2 });
|
||||
// testAI(games, new Player[]{ v1, v3 });
|
||||
|
||||
// testAI(games, new Player[]{ random, v3 });
|
||||
// testAI(games, new Player[]{ v2, v3 });
|
||||
testAI(games, new Player[]{ v2, v3 });
|
||||
// testAI(games, new Player[]{ v3, v2 });
|
||||
}
|
||||
|
||||
private static void testAI(int games, Player<BitboardReversi>[] ais) {
|
||||
int wins = 0;
|
||||
int ties = 0;
|
||||
|
||||
for (int i = 0; i < games; i++) {
|
||||
final BitboardReversi match = new BitboardReversi(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.tutorial.*;
|
||||
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.RandomAI;
|
||||
import org.toop.local.AppContext;
|
||||
@@ -55,7 +57,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 RandomAI<BitboardTicTacToe>(), "Random AI");
|
||||
players[0] = new ArtificialPlayer<>(new MCTSAI<BitboardTicTacToe>(100), "MCTS AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer<>(information.players[1].name);
|
||||
@@ -83,12 +85,13 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
if (information.players[0].isHuman) {
|
||||
players[0] = new LocalPlayer<>(information.players[0].name);
|
||||
} else {
|
||||
players[0] = new ArtificialPlayer<>(new RandomAI<BitboardReversi>(), "Random AI");
|
||||
// players[0] = new ArtificialPlayer<>(new RandomAI<BitboardReversi>(), "Random AI");
|
||||
players[0] = new ArtificialPlayer<>(new MCTSAI3<BitboardReversi>(50), "MCTS V3 AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer<>(information.players[1].name);
|
||||
} else {
|
||||
players[1] = new ArtificialPlayer<>(new MCTSAI<BitboardReversi>(1000), "MCTS AI");
|
||||
players[1] = new ArtificialPlayer<>(new MCTSAI2<BitboardReversi>(50), "MCTS V2 AI");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
|
||||
Reference in New Issue
Block a user