package net.woodyfolsom.msproj.policy;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import net.woodyfolsom.msproj.Action;
import net.woodyfolsom.msproj.GameState;

public class GameTreeNode {
	private GameState gameState;
	private GameTreeNode parent;
	private int numVisits;
	private int numWins;
	private Map<Action, GameTreeNode> children = new HashMap<Action, GameTreeNode>();

	public GameTreeNode(GameState gameState) {
		this.gameState = gameState;
	}

	public void addChild(Action action, GameTreeNode child) {
		children.put(action, child);
		child.parent = this;
	}

	public Set<Action> getActions() {
		return children.keySet();
	}

	public GameTreeNode getChild(Action action) {
		return children.get(action);
	}

	public int getNumChildren() {
		return children.size();
	}

	public GameState getGameState() {
		return gameState;
	}

	public int getNumVisits() {
		return numVisits;
	}

	public int getNumWins() {
		return numWins;
	}
	
	public GameTreeNode getParent() {
		return parent;
	}

	public boolean isRoot() {
		return parent == null;
	}

	public boolean isTerminal() {
		return children.size() == 0;
	}

	public void incrementVisits() {
		numVisits++;
	}

	public void incrementWins() {
		numWins++;
	}
}