package net.woodyfolsom.msproj;

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

public class Action {
	private static final Map<String, Action> actionMap = new HashMap<String,Action>();
	
	private char column = 'x';
	private int row = 0;
	
	//private Player player;
	private String move;
	
	public static final Action NONE = new Action("NONE", /*Player.NONE,*/ 'x', 0);
	public static final Action PASS = new Action("PASS", /*Player.NONE,*/ 'x', 0);
	
	private Action(String move, /*Player player,*/ char column, int row) {
		this.move = move;
		//this.player = player;
		this.column = column;
		this.row = row;
	}
	
	public static final Action getInstance(/*String playerName,*/ String move) {
		if (move == null || "NONE".equals(move) || "PASS".equals(move)) {
			throw new IllegalArgumentException("Illegal move: " + move);
		}
		
		if (actionMap.containsKey(move)) {
			return actionMap.get(move);
		}
		
		/*
		Player player;
		if ("b".equals(playerName)) {
			player = Player.BLACK;
		} else if ("w".equals(playerName)) {
			player = Player.WHITE;
		} else {
			return Action.NONE;
		}*/
		
		char col = move.charAt(0);
		int row = Integer.valueOf(move.substring(1));
		
		Action action = new Action(move, col, row);
		actionMap.put(move, action);
		
		return action;
	}
	
	public char getColumn() {
		return column;
	}
	
	public int getRow() {
		return row;
	}
	
	public boolean isNone() {
		return this == Action.NONE;
	}
	
	public boolean isPass() {
		return this == Action.PASS;
	}
	
	@Override
	public String toString() {
		return move;
	}
}