Files
3DChess/app/src/main/java/chess/ai/alphabeta/AlphaBetaThreadCreator.java
fl.du.pr Grens 97950403a5
All checks were successful
Linux arm64 / Build (push) Successful in 33s
class documentation - a shitload of it
2025-05-18 20:08:22 +02:00

42 lines
1.1 KiB
Java

package chess.ai.alphabeta;
import java.util.concurrent.ThreadFactory;
import chess.ai.GameSimulation;
import chess.ai.actions.AIAction;
import chess.controller.CommandExecutor;
import chess.model.Color;
/**
* Create the threads for an alpha-beta bot.
* @see AlphaBetaAI
*/
public class AlphaBetaThreadCreator implements ThreadFactory{
private final Color color;
private final GameSimulation simulations[];
private int currentThread = 0;
public AlphaBetaThreadCreator(CommandExecutor commandExecutor, Color color, int threadCount) {
this.color = color;
simulations = new GameSimulation[threadCount];
for (int i = 0; i < threadCount; i++) {
simulations[i] = new GameSimulation();
commandExecutor.addListener(simulations[i]);
}
}
public static float getMoveValue(AIAction move, int searchDepth) {
AlphaBetaThread t = (AlphaBetaThread) Thread.currentThread();
return t.getMoveValue(move, searchDepth);
}
@Override
public Thread newThread(Runnable r) {
AlphaBetaThread t = new AlphaBetaThread(r, simulations[currentThread], color);
currentThread++;
return t;
}
}