예제 #1
0
    /*
     * public static string GetPath()
     * {
     *  int[] overfield = { 0, 0, 0, 0, 0, 0, 0, 0 };//场地的第23~30行
     *  int[] field = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     *                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     *                      0b1110000000, 0b1111000110, 0b1111110110 };//场地0~22行,从后往前
     *  int field_w = 10;            //宽度
     *  int field_h = 22;           //高度
     *  int b2b = 0;                //b2b数
     *  int combo = 0;              //连击数
     *  char[] next = { 'O', 'T' };  //Next序列
     *  char hold = 'T';            //Hold
     *  bool curCanHold = true;     //当前hold
     *  char active = 'T';          //当前块
     *  int x = 5;                  //x
     *  int y = 20;                 //y
     *  int spin = 1;               //朝向
     *  bool canhold = true;        //允许hold
     *  bool can180spin = false;    //允许180
     *  int upcomeAtt = 0;          //攻击等待条
     *  int[] comboTable = { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, -1 };//连击表,以-1结尾
     *  int maxDepth = 2;           //next数组的长度
     *  int level = 1;              //这是啥
     *  int player = 1;             //玩家数量?
     *
     *  IntPtr AIPath = zzzdll.TetrisAI(overfield, field, field_w, field_h, b2b, combo, next, hold, curCanHold, active, x, y, spin, canhold, can180spin, upcomeAtt, comboTable, maxDepth, level, player);
     *
     *  string result = Marshal.PtrToStringAnsi(AIPath);
     *  return result;
     * }*/
    public static string GetPath(Field _field, int _minoId, int[] _next, int _hold, int _b2b, int _combo, bool _curCanHold, int _upcomeAtt, int depth)
    {
        int[] overfield = new int[8];  //场地的第23~30行
        int[] field     = new int[24]; //【场地】0~22行,从后往前
        int[] binArr    = _field.BinaryArray();
        for (int i = 0; i < 23; i++)   //不这么写unity会炸
        {
            field[i] = binArr[i];
        }
        int    field_w = 10;     //宽度
        int    field_h = 22;     //高度
        int    b2b     = _b2b;   //【b2b数】
        int    combo   = _combo; //【连击数】
        string next    = "";     //【Next序列】

        for (int i = 0; i < 8; i++)
        {
            next += Mino.IdToName(_next[i]);
        }
        char hold       = Mino.IdToName(_hold);                              //【Hold】
        bool curCanHold = _curCanHold;                                       //当前hold
        char active     = Mino.IdToName(_minoId);                            //当前块
        int  x          = 3;                                                 //x
        int  y          = 1;                                                 //y
        int  spin       = 0;                                                 //朝向
        bool canhold    = true;                                              //允许hold
        bool can180spin = false;                                             //允许180
        int  upcomeAtt  = _upcomeAtt;                                        //【攻击等待条】

        int[] comboTable = { 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, -1 }; //连击表,以-1结尾
        //int[] comboTable =   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 };//连击表,以-1结尾
        //int[] comboTable = { 0, -1 };//连击表,以-1结尾
        int    maxDepth = 8;        //【AI最大深度,next数组的长度】
        int    level    = depth;    //AI深度
        int    player   = 0;        //bot id
        IntPtr AIPath   = zzzdll.TetrisAI(overfield, field, field_w, field_h, b2b, combo,
                                          next, hold, curCanHold, active, x, y, spin, canhold, can180spin, upcomeAtt, comboTable, maxDepth, level, player);

        string result = Marshal.PtrToStringAnsi(AIPath);

        return(result);
    }