So this assignment is to implement an AI agent that can play checkers. Please, r
ID: 3814064 • Letter: S
Question
So this assignment is to implement an AI agent that can play checkers. Please, read carefully. You'll need to create a playing environment in which both the human and AI can make moves.
You do not need to implement any GUI for this. A simple command prompt based menu will work.
The checkers rules that your agent will use:
1. a jumping/taking move is forced. If a player has several jumping/taking moves, all of them are possible moves the player can take
2. a queen gains only the ability to move backwards
Here's an online game that uses these rules: http://www.247checkers.com
The parts of this assignment are as follows:
1. A simple turn-based game, where both the human and AI make moves on a checkers board. The program should output a very simple text-based representation of the board.
2. When it's the human's turn, the human types the coordinates of "from cell" and the "to cell". Each coordinate is of the form< columnindex><rowindex>: ex: "45" goes to "56".
3. When it's the AI's turn, it will run the minmax algorithm, which outputs the suggested move. For this, you'll need to implement the minmax algorithm, whose pseudo-code is provided. Each state in the algorithm corresponds to a state in the game. One way to represent the state is with a 8x8 array. Each cell is either 0 (blank), 1 (white piece), 2(white queen), -1(black piece), -2(black queen).
4. Implement the heuristic evaluation that is used to evaluate the states at a certain depth (say depth 4). Come up with 2-3 simple heuristic features.
Explanation / Answer
public static class Board
{
private JFrame boardFrame = new JFrame();
//outside frame
private JPanel gameBoard = new JPanel(new GridLayout(9,9));
//actual game board
private JPanel backPanel = new JPanel(new BorderLayout());
//panel to hold game board and done button
private boardSquare selected;
//piece currently selected to move
private boolean pieceSelected = false;
//is a piece currently selected?
private Map<Position,boardSquare> grid = new HashMap<Position,boardSquare>();
//Map keying positions to squares on the board
private boolean serverTurn = true;
//is it the Servers turn to move?
private BufferedWriter bw;
//data to client
Board(Socket sock) throws IOException
{
boardFrame.setSize(1000,1000);
backPanel.setPreferredSize(new Dimension(1000, 1000));
boardFrame.add(backPanel);
backPanel.add(gameBoard, BorderLayout.WEST);
boardFrame.setTitle("Checkers");
boardFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
boardFrame.setVisible(true);
gameBoard.setVisible(true);
gameBoard.setPreferredSize(new Dimension(900, 650));
backPanel.setVisible(true);
JButton doneButton = new JButton("Done");
doneListener s = new doneListener();
doneButton.addActionListener(s);
doneButton.setBackground(Color.GREEN);
doneButton.setOpaque(true);
backPanel.add(doneButton,BorderLayout.EAST);
/*Then some loops for populating the gameBoard with objects of this type, see full code below for details if interested*
/ private class boardSquare extends JComponent
{
private boolean isBlack = false;
//is there a black chip on this square?
private boolean isRed = false;
//is there a red chip on this square?
private boolean colored = false;
//is the square itself colored?
private Position pos = null;
//location of the square in the board
public boardSquare(String type, boolean c, Position p)
{
if (type.equals("Black"))
{
isBlack = true;
isRed = false;
}
else if (type.equals("Red"))
{
isRed = true;
isBlack = false;
}
else if (type.equals("Blank"))
{
isBlack = false;
isRed = false;
}
colored = c;
pos = p;
}
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
setPreferredSize(new Dimension(100, 100));
Rectangle box = new Rectangle(0,0,100,100);
g2.draw(box);
if(colored)
{
g2.setPaint(Color.BLUE);
g2.fill(box);
}
if(isBlack)
{
g2.setColor(Color.black);
g2.fillOval(13, 1,70 ,70 );
}
else if(isRed)
{
g2.setColor(Color.red);
g2.fillOval(13, 1,70 ,70);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.