Files
cs8803p4/src/model/comPlayer/MonteCarloComPlayer.java
Marshall 60a842d729 - Reorganized the constructors in Move.java.
- Made the getBoardState method in Referee.java static.
- Created NeuralNetworkPlayer.java, though I don't know how to make the computer use it.
- Updated the Player interface to include passing the PlayerModel. Most of the current com agents ignore the data, but it is now available.
- Updated the train function in PlayerModel.java.
2012-04-29 14:19:10 -04:00

63 lines
1.2 KiB
Java

package model.comPlayer;
import java.util.Random;
import model.Board;
import model.Board.TileColor;
import model.CellPointer;
import model.Move;
import model.playerModel.PlayerModel;
public class MonteCarloComPlayer implements Player {
private final Random rand = new Random();
@Override
public void denyMove() {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public Move getMove(Board board, PlayerModel player) {
return getRandomMove(board, true);
}
public Move getRandomMove(Board board, boolean isCompTurn) {
TileColor tile = TileColor.BLUE;
int r = -1;
int c = -1;
while (tile != TileColor.NONE) {
r = rand.nextInt(Board.NUM_ROWS);
c = rand.nextInt(Board.NUM_COLS);
tile = board.getTile(r, c);
}
switch (rand.nextInt(4)) {
case 0:
tile = TileColor.BLUE;
break;
case 1:
tile = TileColor.GREEN;
break;
case 2:
tile = TileColor.RED;
break;
case 3:
tile = TileColor.YELLOW;
}
return new Move(tile, new CellPointer(r, c));
}
@Override
public boolean isReady() {
return true; // always ready to play a random valid move
}
@Override
public String toString() {
return "Monte Carlo ComPlayer";
}
}