mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
implement solved
This commit is contained in:
@@ -14,9 +14,11 @@ 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.MiniMaxAI;
|
||||
import org.toop.game.players.ai.RandomAI;
|
||||
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.game.players.ai.mcts.OPMCTSAI;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
@@ -82,13 +84,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 MCTSAI4(500, 4), "MCTS V4 AI");
|
||||
players[0] = new ArtificialPlayer(new RandomAI(), "Random 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 MCTSAI1(500), "MCTS V1 AI");
|
||||
players[1] = new ArtificialPlayer(new OPMCTSAI(500), "OP MCTS AI");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
// There is AI performance to be gained by getting rid of non-primitives and thus speeding up deepCopy
|
||||
public abstract class BitboardGame implements TurnBasedGame {
|
||||
@@ -18,8 +17,8 @@ public abstract class BitboardGame implements TurnBasedGame {
|
||||
private Player[] players;
|
||||
|
||||
// long is 64 bits. Every game has a limit of 64 cells maximum.
|
||||
private final long[] playerBitboard;
|
||||
private int currentTurn = 0;
|
||||
protected final long[] playerBitboard;
|
||||
protected int currentTurn = 0;
|
||||
private final int playerCount;
|
||||
|
||||
public BitboardGame(int columnSize, int rowSize, int playerCount) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.toop.framework.game.games.reversi;
|
||||
import org.toop.framework.game.BitboardGame;
|
||||
import org.toop.framework.gameFramework.GameState;
|
||||
import org.toop.framework.gameFramework.model.game.PlayResult;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.game.BitboardGame;
|
||||
|
||||
@@ -368,4 +369,11 @@ public class BitboardReversi extends BitboardGame {
|
||||
|
||||
return bestMove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrom(long player1, long player2, int turn) {
|
||||
this.playerBitboard[0] = player1;
|
||||
this.playerBitboard[1] = player2;
|
||||
this.currentTurn = turn;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package org.toop.framework.game.games.tictactoe;
|
||||
|
||||
import org.toop.framework.gameFramework.GameState;
|
||||
import org.toop.framework.gameFramework.model.game.PlayResult;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.game.BitboardGame;
|
||||
|
||||
@@ -120,4 +121,8 @@ public class BitboardTicTacToe extends BitboardGame {
|
||||
public long heuristicMove(long legalMoves) {
|
||||
return legalMoves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrom(long player1, long player2, int turn) {
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,6 @@ public interface TurnBasedGame extends DeepCopyable<TurnBasedGame> {
|
||||
|
||||
float rateMove(long move);
|
||||
long heuristicMove(long legalMoves);
|
||||
|
||||
void setFrom(long player1, long player2, int turn);
|
||||
}
|
||||
|
||||
@@ -107,8 +107,7 @@ public abstract class MCTSAI extends AbstractAI {
|
||||
}
|
||||
|
||||
protected Node selection(Node root) {
|
||||
// while (Float.isNaN(root.solved) && root.isFullyExpanded() && !root.state.isTerminal()) {
|
||||
while (root.isFullyExpanded() && !root.state.isTerminal()) {
|
||||
while (Float.isNaN(root.solved) && root.isFullyExpanded() && !root.state.isTerminal()) {
|
||||
root = root.bestUCTChild();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ public class MCTSAI1 extends MCTSAI {
|
||||
|
||||
final long endTime = System.nanoTime() + milliseconds * 1_000_000L;
|
||||
|
||||
// while (Float.isNaN(root.solved) && System.nanoTime() < endTime) {
|
||||
while (System.nanoTime() < endTime) {
|
||||
while (Float.isNaN(root.solved) && System.nanoTime() < endTime) {
|
||||
Node leaf = selection(root);
|
||||
leaf = expansion(leaf);
|
||||
final float value = simulation(leaf);
|
||||
|
||||
@@ -29,8 +29,7 @@ public class MCTSAI2 extends MCTSAI {
|
||||
|
||||
final long endTime = System.nanoTime() + milliseconds * 1_000_000L;
|
||||
|
||||
// while (Float.isNaN(root.solved) && System.nanoTime() < endTime) {
|
||||
while (System.nanoTime() < endTime) {
|
||||
while (Float.isNaN(root.solved) && System.nanoTime() < endTime) {
|
||||
Node leaf = selection(root);
|
||||
leaf = expansion(leaf);
|
||||
final float value = simulation(leaf);
|
||||
|
||||
@@ -41,8 +41,7 @@ public class MCTSAI3 extends MCTSAI {
|
||||
tasks.add(() -> {
|
||||
final Node localRoot = new Node(game.deepCopy());
|
||||
|
||||
// while (Float.isNaN(localRoot.solved) && System.nanoTime() < endTime) {
|
||||
while (System.nanoTime() < endTime) {
|
||||
while (Float.isNaN(localRoot.solved) && System.nanoTime() < endTime) {
|
||||
Node leaf = selection(localRoot);
|
||||
leaf = expansion(leaf);
|
||||
final float value = simulation(leaf);
|
||||
|
||||
@@ -50,8 +50,7 @@ public class MCTSAI4 extends MCTSAI {
|
||||
tasks.add(() -> {
|
||||
final Node localRoot = threadRoots[threadIndex];
|
||||
|
||||
// while (Float.isNaN(localRoot.solved) && System.nanoTime() < endTime) {
|
||||
while (System.nanoTime() < endTime) {
|
||||
while (Float.isNaN(localRoot.solved) && System.nanoTime() < endTime) {
|
||||
Node leaf = selection(localRoot);
|
||||
leaf = expansion(leaf);
|
||||
final float value = simulation(leaf);
|
||||
|
||||
Reference in New Issue
Block a user