Added configurable computer player - use 'com=random', 'com=minimax' etc as cmd-line args.

Default is AlphaBeta.
Updated ActionListener for UserChooserFrame so that selecting from the list (or typing a new name and pressing RETURN) also triggers the action.
Added the player and computer algorithm names to the title bar e.g. "Bob vs. Alpha-Beta".
This commit is contained in:
Woody Folsom
2012-04-29 10:18:15 -04:00
parent 15ed56134e
commit c53ff75ea4
10 changed files with 132 additions and 38 deletions

View File

@@ -1,7 +1,6 @@
package model;
import model.Board.TileColor;
import model.comPlayer.AlphaBetaComPlayer;
import model.comPlayer.HumanPlayer;
import model.comPlayer.Player;
import model.playerModel.PlayerModel;
@@ -14,7 +13,6 @@ import view.MainFrame;
import view.ScorePanel;
public class Referee implements Runnable {
public static final String COM_TURN = "Waiting for the computer's move.";
public static final String GAME_OVER = "Game over!";
public static final Logger LOGGER = Logger.getLogger(Referee.class
@@ -30,7 +28,7 @@ public class Referee implements Runnable {
private final MainFrame mf;
private PlayerModel playerModel = null;
public Referee(MainFrame mnFrm, String player) {
public Referee(MainFrame mnFrm, String player, Player computerPlayer) {
if (PlayerModel.exists(player)) {
PlayerModel.getPlayerPath(player);
playerModel = PlayerModel.load(PlayerModel.getPlayerPath(player));
@@ -41,6 +39,7 @@ public class Referee implements Runnable {
}
mf = mnFrm;
this.computerPlayer = computerPlayer;
initGame();
}
@@ -144,7 +143,6 @@ public class Referee implements Runnable {
private void initGame() {
board = new Board();
computerPlayer = new AlphaBetaComPlayer();
}
private void play() {

View File

@@ -22,4 +22,9 @@ public class AlphaBetaComPlayer implements Player {
public boolean isReady() {
return true; // always ready to play a random valid move
}
@Override
public String toString() {
return "Alpha-Beta ComPlayer";
}
}

View File

@@ -8,6 +8,10 @@ import model.comPlayer.generator.MoveGenerator;
public class MinimaxComPlayer implements Player{
private MoveGenerator moveGenerator = new MinimaxMoveGenerator();
public MinimaxComPlayer() {
super();
}
@Override
public Move getMove(Board board) {
return moveGenerator.genMove(board, false);
@@ -22,4 +26,9 @@ public class MinimaxComPlayer implements Player{
public boolean isReady() {
return true; // always ready to play a random valid move
}
@Override
public String toString() {
return "Minimax ComPlayer";
}
}

View File

@@ -54,4 +54,9 @@ public class MonteCarloComPlayer implements Player {
public boolean isReady() {
return true; // always ready to play a random valid move
}
@Override
public String toString() {
return "Monte Carlo ComPlayer";
}
}

View File

@@ -50,4 +50,9 @@ public class RandomComPlayer implements Player {
public boolean isReady() {
return true; // always ready to play a random valid move
}
@Override
public String toString() {
return "Random ComPlayer";
}
}