06-22-2022, 03:24 PM
yes, I tested it for chess! I just add some code to RandomAI.java to show the chess moves, as below:
// RandomAI.java ---------------------------------------------------------------------------------
package random;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.swing.plaf.synth.Region;
import game.Game;
import main.collections.FastArrayList;
import other.AI;
import other.context.Context;
import other.location.Location;
import other.move.Move;
import other.move.MoveSequence;
import other.state.State;
import other.state.container.ContainerState;
import other.state.owned.Owned;
import other.trial.Trial;
import utils.AIUtils;
/**
* Example third-party implementation of a random AI for Ludii
*
* @author Dennis Soemers
*/
public class RandomAI extends AI
{
//-------------------------------------------------------------------------
/** Our player index */
protected int player = -1;
//-------------------------------------------------------------------------
/**
* Constructor
*/
public RandomAI()
{
this.friendlyName = "Random AI";
}
//-------------------------------------------------------------------------
@Override
public Move selectAction
(
final Game game,
final Context context,
final double maxSeconds,
final int maxIterations,
final int maxDepth
)
{
System.out.println("maxSeconds = " + maxSeconds
+ ", maxIterations = " + maxIterations + ", maxDepth = " + maxDepth);
final Trial trial = context.trial();
System.out.println("trail move number = " + trial.moveNumber());
State state = context.state();
System.out.println("trail mover = " + state.mover());
for(int i = 0; i < trial.moveNumber(); i++)
{
Move move = trial.getMove(i);
int from = move.fromNonDecision();
int to = move.toNonDecision();
System.out.println("(" + from + "," + to + ")");
}
Move move = trial.lastMove();
int from = move.fromNonDecision();
int to = move.toNonDecision();
System.out.println("lastMove (" + from + "," + to + ")");
FastArrayList<Move> legalMoves = game.moves(context).moves();
//System.out.println("Legal Moves = " + legalMoves);
final int r = ThreadLocalRandom.current().nextInt(legalMoves.size());
return legalMoves.get®;
}
@Override
public void initAI(final Game game, final int playerID)
{
this.player = playerID;
}
//-------------------------------------------------------------------------
}
// RandomAI.java ---------------------------------------------------------------------------------
package random;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.swing.plaf.synth.Region;
import game.Game;
import main.collections.FastArrayList;
import other.AI;
import other.context.Context;
import other.location.Location;
import other.move.Move;
import other.move.MoveSequence;
import other.state.State;
import other.state.container.ContainerState;
import other.state.owned.Owned;
import other.trial.Trial;
import utils.AIUtils;
/**
* Example third-party implementation of a random AI for Ludii
*
* @author Dennis Soemers
*/
public class RandomAI extends AI
{
//-------------------------------------------------------------------------
/** Our player index */
protected int player = -1;
//-------------------------------------------------------------------------
/**
* Constructor
*/
public RandomAI()
{
this.friendlyName = "Random AI";
}
//-------------------------------------------------------------------------
@Override
public Move selectAction
(
final Game game,
final Context context,
final double maxSeconds,
final int maxIterations,
final int maxDepth
)
{
System.out.println("maxSeconds = " + maxSeconds
+ ", maxIterations = " + maxIterations + ", maxDepth = " + maxDepth);
final Trial trial = context.trial();
System.out.println("trail move number = " + trial.moveNumber());
State state = context.state();
System.out.println("trail mover = " + state.mover());
for(int i = 0; i < trial.moveNumber(); i++)
{
Move move = trial.getMove(i);
int from = move.fromNonDecision();
int to = move.toNonDecision();
System.out.println("(" + from + "," + to + ")");
}
Move move = trial.lastMove();
int from = move.fromNonDecision();
int to = move.toNonDecision();
System.out.println("lastMove (" + from + "," + to + ")");
FastArrayList<Move> legalMoves = game.moves(context).moves();
//System.out.println("Legal Moves = " + legalMoves);
final int r = ThreadLocalRandom.current().nextInt(legalMoves.size());
return legalMoves.get®;
}
@Override
public void initAI(final Game game, final int playerID)
{
this.player = playerID;
}
//-------------------------------------------------------------------------
}