Quick question, I have developed 3 A.I's each with a different depth.
Currently to choose what A.I you want to play against you have to go into the java file called Main.java and change it to whichever one you want. The line to change is:
chessGame.setPlayer(Piece.COLOR_BLACK, ai3);//Here A.I is assigned
I want to allow the user to have an option at the start of the game to choose the A.I. I was hoping for some help with the interface, I was thinking something something like a JOptionpane might work.
(I'm just not sure how to do one for the A.I selection)
Current A.I's
ai1 ai2 ai3
package chess;
import chess.ai.SimpleAiPlayerHandler;
import chess.gui.ChessGui;
import chess.logic.ChessGame;
import chess.logic.Piece;
public class Main {
public static void main(String[] args) {
// Creating the Game
ChessGame chessGame = new ChessGame();
// Creating the Human Player
//Human Player is the Object chessGui
ChessGui chessGui = new ChessGui(chessGame);
//Creating the A.I's
SimpleAiPlayerHandler ai1 = new SimpleAiPlayerHandler(chessGame);//Super Dumb
SimpleAiPlayerHandler ai2 = new SimpleAiPlayerHandler(chessGame);//Dumb
SimpleAiPlayerHandler ai3 = new SimpleAiPlayerHandler(chessGame);//Not So Dumb
// Set strength of AI, how far they can see ahead
ai1.maxDepth = 1;
ai1.maxDepth = 2;
ai3.maxDepth = 3;
//Assign the Human to White
chessGame.setPlayer(Piece.COLOR_WHITE, chessGui);
//Assign the not so dumb A.I to black
chessGame.setPlayer(Piece.COLOR_BLACK, ai3);
// in the end we start the game
new Thread(chessGame).start();
}
}
Thanks for any help.
You should probably use a JComboBox to allow the user to select among the 3 options available. If you make a splash JFrame with this JComboBox you can then create your main game frame afterward and pass it the value from the JComboBox.
For example, you could have the JComboBox give options of difficulty setting Easy, Medium, and Hard. Using an action listener on a JButton get the selected value from the JComboBox and convert it to int value appropriate for your minimax algorithm. That is, pass 1 for easy, 2 for medium, and 3 for hard.
Next change your ai class so that maxDepth is in the constructor. Then when you instantiate your ai, just give it the value that was passed forward from the previous frame and you will have created the only ai you need at the right difficulty setting.
EDIT:
It looks like you managed to get something similar working which is great! In case it helps you, I have included a brief example of how I would have done this below. Note that I also set it up such that your SimpleAiPlayerHandler constructor also takes an int value for instantiating the maxDepth variable. You'll need to add this. Since it uses classes I don't have, I can't compile it. However, if anyone else needs to do something similar, just remove everything in the DifficultyListener except the print statement and the line that get's the difficulty from the JComboBox and you'll see it working (and compiling).