コード例 #1
0
ファイル: Placing.cs プロジェクト: swordbreaker/Algd2MillGame
        public override bool Equals(Object o)
        {
            if (o != null && o is Placing)
            {
                Placing a = (Placing)o;

                return(a.m_color == m_color && a.m_to == m_to);
            }
            return(false);
        }
コード例 #2
0
ファイル: Action.cs プロジェクト: swordbreaker/Algd2MillGame
        public static Action Readln(String[] token)
        {
            if (token[0].Equals("PLACE"))
            {
                // my opponent placed a stone
                if (token.Length != 3)
                {
                    throw new Exception();
                }
                var color = sbyte.Parse(token[1]);
                int pos   = int.Parse(token[2]);
                // create place action and play it
                return(new Placing(color, pos));
            }
            else if (token[0].Equals("MOVE"))
            {
                // my opponent moved a stone
                if (token.Length != 4)
                {
                    throw new Exception();
                }
                sbyte color = sbyte.Parse(token[1]);
                int   from  = int.Parse(token[2]);
                int   to    = int.Parse(token[3]);
                // create move action and play it
                return(new Moving(color, from, to));
            }
            else if (token[0].Equals("TAKE"))
            {
                // my opponent
                if (token.Length <= 1)
                {
                    throw new Exception();
                }
                if (token[1].Equals("PLACE"))
                {
                    // my opponent placed a stone
                    if (token.Length != 5)
                    {
                        throw new Exception();
                    }
                    sbyte color = sbyte.Parse(token[2]);
                    int   pos   = int.Parse(token[3]);
                    // create place action
                    ActionPM a = new Placing(color, pos);

                    int takepos = int.Parse(token[4]);
                    // create take and play it
                    return(new Taking(a, takepos));
                }
                else if (token[1].Equals("MOVE"))
                {
                    // my opponent moved a stone
                    if (token.Length != 6)
                    {
                        throw new Exception();
                    }
                    sbyte color = sbyte.Parse(token[2]);
                    int   from  = int.Parse(token[3]);
                    int   to    = int.Parse(token[4]);
                    // create move action
                    ActionPM a = new Moving(color, from, to);

                    int takepos = int.Parse(token[5]);
                    // create take and play it
                    return(new Taking(a, takepos));
                }
            }
            return(null);
        }