static public String toString( CondExprElement ele )
    {
        switch( ele.type )
        {
        case CondExprElemntType.Dir: return toString( (CondDir)ele.meta );
        case CondExprElemntType.WallName: return toString( (WallName)ele.meta );
        case CondExprElemntType.Color: return toString((ColorId)ele.meta);
        case CondExprElemntType.Object: return toString((ObjectId)ele.meta);
        case CondExprElemntType.IntValue: return ele.meta.ToString();
        case CondExprElemntType.FaceFront:
                if (ele.meta == 0)
                    return "背對";
                return "面向";
        }

        return "Error Cond Element";
    }
    public override void generateVaild(System.Random rand, WorldCondition worldCond)
    {
        List<int> props = new List<int>();
        for (int i = 0; i < (int)ValueProperty.Num; ++i )
        {
            if ( ( (1 << i) & worldCond.valuePropertyFlag ) != 0 )
                props.Add(i);
        }
        elements = new CondExprElement[1];
        elements[0].type = CondExprElemntType.IntValue;
        elements[0].meta = props[ rand.Next() % props.Count ];

    }
    public override void generateVaild(System.Random rand, WorldCondition worldCond)
    {
        elements = new CondExprElement[2];
        elements[0].type = CondExprElemntType.IntValue;
        elements[0].meta = rand.Next() % objectMap.Length;

        elements[1].type = CondExprElemntType.Color;
        elements[1].meta = (int)worldCond.getObjectColor(objectMap[elements[0].meta]);
    }
 public override void generate(System.Random rand)
 {
     elements = new CondExprElement[1];
     elements[0].type = CondExprElemntType.IntValue;
     elements[0].meta = rand.Next() % (int)ValueProperty.Num;
 }
    public override void generateVaild(System.Random rand, WorldCondition worldCond)
    {
        elements = new CondExprElement[2];
        elements[0].type = CondExprElemntType.Object;
        elements[0].meta = rand.Next() % (int)ObjectId.NumCondObject;

        elements[1].type = CondExprElemntType.IntValue;
        elements[1].meta = worldCond.getObjectNum((ObjectId)elements[0].meta);
    }
    public override void generate(System.Random rand)
    {
        elements = new CondExprElement[2];
        elements[0].type = CondExprElemntType.IntValue;
        elements[0].meta = rand.Next() % objectMap.Length;

        elements[1].type = CondExprElemntType.Color;
        elements[1].meta = rand.Next() % (int)ColorId.Num;
    }
    public override void generateVaild(System.Random rand, WorldCondition worldCond) 
    {
        //IdxContent = rand.Next() % 2;
        IdxContent = 0;
        if (IdxContent == 0)
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = rand.Next() % 4;

            int idx = worldCond.getWallIndex((WallName)elements[1].meta);
            idx = worldCond.getRelDirIndex(idx, CondDir.Front, elements[0].meta != 0);
            elements[2].type = CondExprElemntType.Color;
            elements[2].meta = (int)worldCond.wall[idx].color;
        }
        else
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = rand.Next() % 4;


            int idx = worldCond.getWallIndex((WallName)elements[1].meta);
            idx = worldCond.getRelDirIndex(idx, CondDir.Front, elements[0].meta != 0);

            elements[3].type = CondExprElemntType.Dir;
            if ( (rand.Next() % 2 ) == 0 )
                elements[3].meta = (int)CondDir.Left;
            else
                elements[3].meta = (int)CondDir.Right;

            elements[4].type = CondExprElemntType.IntValue;
            elements[4].meta = 1 + (rand.Next() % 3);

            elements[2].type = CondExprElemntType.Color;
            elements[2].meta = (int)worldCond.wall[idx].color;
        }
    }
    public override void generate(System.Random rand)
    {
        elements = new CondExprElement[2];
        elements[0].type = CondExprElemntType.Object;
        elements[0].meta = rand.Next() % (int)ObjectId.NumCondObject;

        elements[1].type = CondExprElemntType.IntValue;
        elements[1].meta = rand.Next() % 10;
    }
    public override void generate(System.Random rand)
    {
        //IdxContent = rand.Next() % 2;
        IdxContent = 0;
        if (IdxContent == 0)
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = rand.Next() % 4;

            elements[2].type = CondExprElemntType.Color;
            elements[2].meta = rand.Next() % (int)ColorId.Num;
        }
        else
        {
            elements = new CondExprElement[5];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = rand.Next() % 4;

            elements[2].type = CondExprElemntType.Color;
            elements[2].meta = rand.Next() % (int)ColorId.Num;

            elements[3].type = CondExprElemntType.Dir;
            if ( (rand.Next() % 2 ) == 0 )
                elements[3].meta = (int)CondDir.Left;
            else
                elements[3].meta = (int)CondDir.Right;

            elements[4].type = CondExprElemntType.IntValue;
            elements[4].meta = 1 + (rand.Next() % 3);
        }
    }
    public override void generateVaild(System.Random rand, WorldCondition worldCond)
    {
        IdxContent = rand.Next() % 2;

        if (IdxContent == 0)
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[2].type = CondExprElemntType.Dir;
            elements[2].meta = (int)dirMap[ rand.Next() % dirMap.Length ];

            List<int> idxLighting = new List<int>();
            for (int i = 0; i < 4; ++i )
            {
                if ( worldCond.isTopFireLighting(i) )
                {
                    idxLighting.Add(i);
                }
            }
            int idx = idxLighting[rand.Next() % idxLighting.Count];
            if (idx == 0)
                idx += 2;
            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = (int)worldCond.wall[ ( idx - elements[2].meta + 4 ) % 4 ].name;

        }
        else
        {
            elements = new CondExprElement[1];
            elements[0].type = CondExprElemntType.IntValue;
            elements[0].meta = worldCond.getTopFireLightingNum();
        }
    }
    public override void generate(System.Random rand)
    {
        IdxContent = rand.Next() % 2;

        if (IdxContent == 0)
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.FaceFront;
            elements[0].meta = rand.Next() % 2;

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = rand.Next() % 4;

            elements[2].type = CondExprElemntType.Dir;
            elements[2].meta = (int)dirMap[ rand.Next() % dirMap.Length ];
        }
        else
        {
            elements = new CondExprElement[1];
            elements[0].type = CondExprElemntType.IntValue;
            elements[0].meta = rand.Next() % 5;
        }
        
    }
    public override void generateVaild(System.Random rand ,  WorldCondition worldCond )
    {
        IdxContent = rand.Next() % 2;
        if (IdxContent == 0)
        {
            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.WallName;
            elements[0].meta = rand.Next()%4;

            elements[2].type = CondExprElemntType.Dir;
            elements[2].meta = (int)dirMap[rand.Next() % 2];

            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = (int)worldCond.getRelDirWall( (WallName)elements[0].meta , (CondDir)elements[2].meta );
        }
        else
        {
            elements = new CondExprElement[5];
            int idx = rand.Next() % 4;
            CondDir dir = dirMap[rand.Next() % 2];

            elements[4].type = CondExprElemntType.Dir;
            elements[4].meta = (int)dir;

            for( int i = 0 ; i < 4 ; ++i )
            {
                elements[i].type = CondExprElemntType.WallName;
                elements[i].meta = (int)worldCond.wall[idx].name;
                idx = worldCond.getRelDirWallIndex(idx, dir);
            }
        }
    }
    public override void generate(System.Random rand)
    {
        IdxContent = rand.Next() % 2;
        if (IdxContent == 0 )
        {
            int[] walllId = Utility.makeRandSeq( rand , (int)WallName.Num , 0 );

            elements = new CondExprElement[3];
            elements[0].type = CondExprElemntType.WallName;
            elements[0].meta = walllId[0];
    
            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = walllId[1];
  
            elements[2].type = CondExprElemntType.Dir;
            elements[2].meta = (int)dirMap[ rand.Next() % 2 ];
        }
        else
        {

            int[] walllId = Utility.makeRandSeq(rand, (int)WallName.Num, 0);

            elements = new CondExprElement[5];
            elements[0].type = CondExprElemntType.WallName;
            elements[0].meta = walllId[0];
            elements[1].type = CondExprElemntType.WallName;
            elements[1].meta = walllId[1];
            elements[2].type = CondExprElemntType.WallName;
            elements[2].meta = walllId[2];
            elements[3].type = CondExprElemntType.WallName;
            elements[3].meta = walllId[3];

            elements[4].type = CondExprElemntType.Dir;
            elements[4].meta = (int)dirMap[rand.Next() % 2];
        }
    }