package net.woodyfolsom.msproj.tree;

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<T extends GameTreeNodeProperties> {
	private GameState gameState;
	private GameTreeNode<T> parent;
	private Map<Action, GameTreeNode<T>> children = new HashMap<Action, GameTreeNode<T>>();
	private T properties;

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

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

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

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

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

	public GameState getGameState() {
		return gameState;
	}

	public GameTreeNode<T> getParent() {
		return parent;
	}

	public T getProperties() {
		return properties;
	}

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

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