package net.woodyfolsom.msproj.policy;

import java.util.ArrayList;
import java.util.List;

import net.woodyfolsom.msproj.GameConfig;
import net.woodyfolsom.msproj.GameState;

//import org.apache.log4j.Logger;

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

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

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

		if (validMoves.size() == 0) {
			validMoves.add(Policy.PASS);
		}

		return validMoves;
	}
}
