Reviewed-on: #5 Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-committed-by: Persson-dev <sim16.prib@gmail.com>
37 lines
985 B
Java
37 lines
985 B
Java
package chess.ai.minimax;
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
import chess.controller.CommandExecutor;
|
|
import chess.model.Color;
|
|
import chess.model.Move;
|
|
|
|
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(Move 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;
|
|
}
|
|
|
|
}
|