42 lines
1.1 KiB
Java
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;
|
|
}
|
|
|
|
}
|