

package ictk.boardgame.chess.net.ics;

import ictk.util.Log;

public class ICSResult {
   public static final int UNDECIDED = 0,
   			   WHITE_WIN = 1,
			   DRAW      = 2,
			   BLACK_WIN = 3;

   protected int result;
   protected String desc;

   public ICSResult () {
      result = UNDECIDED;
   }

   public ICSResult (String s) {
      this();
      setResultCode(s);
   }

   public int getResultCode () { return result; }
   public void setResultCode (int res) { result = res; }

   public void setResultCode (String s) {
      if ("*".equals(s))
         result = UNDECIDED;
      else if ("1-0".equals(s))
         result = WHITE_WIN;
      else if ("1/2-1/2".equals(s))
         result = DRAW;
      else if ("0-1".equals(s))
         result = BLACK_WIN;
      else {
         Log.error(Log.PROG_WARNING, 
	    "ICSResult received '" + s + "' as a result.");
	 result = UNDECIDED;
      }
   }

   public String getReadableResult () {
      String s = null;

      switch (result) {
         case UNDECIDED: s = "*"; break;
	 case WHITE_WIN: s = "1-0"; break;
	 case DRAW:      s = "1/2-1/2"; break;
	 case BLACK_WIN: s = "0-1"; break;
	 default:
      }
      return s;
   }

   public String getDescription () { return desc; }
   public void setDescription (String s) { desc = s; }

   public String toString () {
      return getReadableResult();
   }


}
