package cs6601.p1.generator;

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

import org.apache.log4j.Logger;

import cs6601.p1.GameConfig;
import cs6601.p1.GameState;

public class ValidMoveGenerator implements MoveGenerator {
	private static final Logger LOGGER = Logger.getLogger(MinimaxMoveGenerator.class.getName());
	
	@Override
	public String genMove(GameConfig gameConfig, GameState gameState,
			String color) {
		LOGGER.info("ValidMoveGenerator genMove() stub returning PASS");
		return PASS;
	}

	@Override
	public List<String> genMoves(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(PASS);
		}

		return validMoves;
	}
}
