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

@@ -6,6 +6,7 @@ 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 {

View File

@@ -321,8 +321,51 @@ public class BitboardReversi extends BitboardGame {
else if (blackCount > whiteCount){
return 0;
}
else{
else {
return 1;
}
}
@Override
public float rateMove(long move) {
final long corners = 0x8100000000000081L;
if ((move & corners) != 0L) {
return 0.4f;
}
final long xSquares = 0x0042000000004200L;
if ((move & xSquares) != 0) {
return -0.4f;
}
final long cSquares = 0x4281000000008142L;
if ((move & cSquares) != 0) {
return -0.1f;
}
return 0.0f;
}
@Override
public long heuristicMove(long legalMoves) {
long bestMove = 0L;
float bestMoveRate = Float.NEGATIVE_INFINITY;
while (legalMoves != 0L) {
final long move = legalMoves & -legalMoves;
final float moveRate = rateMove(move);
if (moveRate > bestMoveRate) {
bestMove = move;
bestMoveRate = moveRate;
}
legalMoves &= ~move;
}
return bestMove;
}
}

View File

@@ -110,4 +110,14 @@ public class BitboardTicTacToe extends BitboardGame {
public BitboardTicTacToe deepCopy() {
return new BitboardTicTacToe(this);
}
@Override
public float rateMove(long move) {
return 0.0f;
}
@Override
public long heuristicMove(long legalMoves) {
return legalMoves;
}
}

View File

@@ -57,4 +57,8 @@ public class ArtificialPlayer extends AbstractPlayer {
public ArtificialPlayer deepCopy() {
return new ArtificialPlayer(this);
}
public AI getAi() {
return ai;
}
}

View File

@@ -13,4 +13,7 @@ public interface TurnBasedGame extends DeepCopyable<TurnBasedGame> {
PlayResult play(long move);
PlayResult getState();
boolean isTerminal();
float rateMove(long move);
long heuristicMove(long legalMoves);
}