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;

//import org.apache.log4j.Logger;

public class ValidMoveGenerator implements ActionGenerator {
	//private static final Logger LOGGER = Logger.getLogger(ValidMoveGenerator.class.getName());

	@Override
	public List<Action> getActions(GameConfig gameConfig, GameState gameState,
			Player color, int nMoves) {
		
		GameState gameStateCopy = new GameState(gameState);
		List<String> emptyCoordinates = gameStateCopy.getEmptyCoords();
		List<Action> validMoves = new ArrayList<Action>();

		while (emptyCoordinates.size() > 0) {
			Action nextMove = Action.getInstance(emptyCoordinates.remove(emptyCoordinates.size()-1));
			if (gameStateCopy.playStone(color, nextMove)) {
				validMoves.add(nextMove);
				gameStateCopy = new GameState(gameState); // play successful? regenerate copy of gameState
			}
		}

		//Passing is always a VALID move.  It may not be a GOOD move.
		if (validMoves.size() == 0) {
			validMoves.add(Action.PASS);
		}

		return validMoves;
	}
}
