- Reorganized packages so that the computer agents are inside the model package.

- Added support for the player model inside Referee.java; high scores should now persist over a single execution of the program.
- Refactored PlayerModel.java to support game logging. All games are now logged so that we can track overall progress.
- Added scaffolding to allow saving and importing of PlayerModel.java. It is not yet functional, but it will be with two function implementations and then the appropriate calls.
This commit is contained in:
Marshall
2012-04-28 19:18:28 -04:00
parent 1a4c6d865b
commit a6af6df132
18 changed files with 123 additions and 52 deletions

View File

@@ -0,0 +1,57 @@
package model.comPlayer;
import java.util.Random;
import model.Board;
import model.CellPointer;
import model.Move;
import model.Board.TileColor;
public class MonteCarloComPlayer implements Player {
private final Random rand = new Random();
@Override
public Move getMove(Board board) {
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(new CellPointer(r, c), tile);
}
@Override
public void denyMove() {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public boolean isReady() {
return true; // always ready to play a random valid move
}
}