Refactoring in progress.

Player and Action classes are now singletons (factory pattern) rather than String values.
Implementing more general treesearch code for minimax, alpha-beta, monte carlo using simplified backup logic.
This commit is contained in:
cs6601
2012-08-30 08:41:03 -04:00
parent b44b666663
commit 2e40440838
26 changed files with 647 additions and 433 deletions

View File

@@ -3,8 +3,10 @@ package net.woodyfolsom.msproj.policy;
import java.util.ArrayList;
import java.util.List;
import net.woodyfolsom.msproj.Action;
import net.woodyfolsom.msproj.GameConfig;
import net.woodyfolsom.msproj.GameState;
import net.woodyfolsom.msproj.Player;
public class RandomMovePolicy implements Policy {
@@ -12,14 +14,15 @@ public class RandomMovePolicy implements Policy {
/**
* Does NOT modify the gameState.
*/
public String getAction(GameConfig gameConfig, GameState gameState,
String color) {
public Action getAction(GameConfig gameConfig, GameState gameState,
Player color) {
GameState gameStateCopy = new GameState(gameState);
List<String> emptyCoordinates = gameStateCopy.getEmptyCoords();
while (emptyCoordinates.size() > 0) {
String randomMove = emptyCoordinates
.get((int) (Math.random() * emptyCoordinates.size()));
Action randomMove = Action.getInstance(emptyCoordinates
.get((int) (Math.random() * emptyCoordinates.size())));
if (gameStateCopy.playStone(color, randomMove)) {
return randomMove;
} else {
@@ -27,7 +30,7 @@ public class RandomMovePolicy implements Policy {
}
}
return PASS;
return Action.PASS;
}
/**
@@ -42,15 +45,15 @@ public class RandomMovePolicy implements Policy {
*
* @return
*/
public List<String> genMoves(GameConfig gameConfig, GameState gameState,
String color, int nMoves) {
public List<Action> genMoves(GameConfig gameConfig, GameState gameState,
Player color, int nMoves) {
GameState gameStateCopy = new GameState(gameState);
List<String> emptyCoordinates = gameStateCopy.getEmptyCoords();
List<String> randomMoves = new ArrayList<String>();
List<Action> randomMoves = new ArrayList<Action>();
while (emptyCoordinates.size() > 0 && randomMoves.size() < nMoves) {
String randomMove = emptyCoordinates
.get((int) (Math.random() * emptyCoordinates.size()));
Action randomMove = Action.getInstance(emptyCoordinates
.get((int) (Math.random() * emptyCoordinates.size())));
if (gameStateCopy.playStone(color, randomMove)) {
randomMoves.add(randomMove);
}
@@ -58,7 +61,7 @@ public class RandomMovePolicy implements Policy {
}
if (randomMoves.size() == 0) {
randomMoves.add(PASS);
randomMoves.add(Action.PASS);
}
return randomMoves;