Пример #1
0
    private void CreateItemPool(PoolConfig config)
    {
        var spawnable = config.Object.GetComponent(typeof(ISpawnable)) as ISpawnable;

        config.Type = spawnable.GetType();

        if (spawnable != null)
        {
            var folder = new GameObject(spawnable.GetType().Name);
            folder.transform.parent = transform;

            if (!_pool.ContainsKey(spawnable.GetType()))
            {
                _pool[spawnable.GetType()] = (
                    Collection : new ObservableCollection <ISpawnable>(),
                    Config : config,
                    Folder : folder,
                    PoolEvents : new SpawnPoolEvents()
                    );
            }

            _pool[spawnable.GetType()].Collection.CollectionChanged += spawnable.OnChange;

            typeof(SpawnItemService).GetMethod("AddItems")
            .MakeGenericMethod(spawnable.GetType())
            .Invoke(ItemService, new object[] { config.Amount });
        }
        else
        {
            throw new Exception($"Pool item must have a Component that extends {nameof(Spawnable)} or implementes {nameof(ISpawnable)}");
        }
    }
Пример #2
0
        public static RuleMap Interpret()
        {
            var ruleMap    = new RuleMap();
            var toOrganize = new List <List <Rule> >();

            using (var reader = new StreamReader(Application.dataPath + "/Resources/Dialogue/csvtest.csv"))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    var fixtures = csv.GetRecords <RuleFixture>();

                    foreach (var fixture in fixtures)
                    {
                        var id       = fixture.Id;
                        var criteria = ParseCriteriaCodes(id, fixture.Criteria);
                        var remember = ParseRemembererCodes(id, fixture.Remember);

                        var ruleKey = (fixture.Concept, fixture.Who);
                        if (!ruleMap.ContainsKey(ruleKey))
                        {
                            ruleMap[ruleKey] = new List <Rule>();
                            toOrganize.Add(ruleMap[ruleKey]);
                        }

                        ruleMap[ruleKey].Add(new Rule(
                                                 id,
                                                 criteria,
                                                 remember,
                                                 fixture.Response,
                                                 fixture.Cooldown));
                    }
                }

            // Sort each collection of rules in decending number of criteria,
            // i.e. We want to take more specific rules first.
            foreach (var l in toOrganize)
            {
                l.Sort((x, y) => y.NumCriteria.CompareTo(x.NumCriteria));
            }

            return(ruleMap);
        }
Пример #3
0
    private void GetTddata2(HttpContext context)
    {
        string soapaddr = GetDCS();

        HttpRequest  req  = context.Request;
        HttpResponse resp = context.Response;

        string method    = req.QueryString["method"];
        string classpath = req.QueryString["classpath"];

        if (classpath == null)
        {
            classpath = req.Form["classpath"];
        }

        string filter = null;

        filter = req.QueryString["filter"];

        if (filter == null)
        {
            filter = req.Form["filter"];
        }

        //clear
        resp.Clear();
        resp.ClearHeaders();
        resp.ClearContent();

        //
        if (method.Equals("altitude"))
        {
            string path = MapHelper.GetAltitude(soapaddr, classpath, filter);
            if (path != null)
            {
                resp.StatusCode = 200;
                string isCompress = req.QueryString["Compress"];
                if (isCompress == "true")
                {
                    resp.ContentType = "zip";
                    MemoryStream ms    = new MemoryStream();
                    ZipFile      zFile = ZipFile.Create(ms);
                    zFile.BeginUpdate();
                    ZipDataSource ds = new ZipDataSource(path);
                    zFile.Add(ds, Path.GetFileName(path));
                    zFile.CommitUpdate();
                    zFile.Close();
                    ms.Close();

                    resp.OutputStream.Write(ms.ToArray(), 0, ms.ToArray().Length);
                }
                else
                {
                    byte[] buffer = File.ReadAllBytes(path);
                    resp.OutputStream.Write(buffer, 0, buffer.Length);
                }
            }
            else
            {
                resp.StatusCode = 404;
            }
        }
        else
        {
            try
            {
                byte[] tddata = MapHelper.GetTDData(soapaddr, method, classpath, filter);
                if (tddata != null)
                {
                    if (tddata.Length == 0)
                    {
                        resp.StatusCode = 200;
                    }
                    else
                    {
                        resp.ContentType = "text/xml";
                        resp.StatusCode  = 200;
                        resp.OutputStream.Write(tddata, 0, tddata.Length);
                    }
                }
                else
                {
                    resp.StatusCode = 404;
                }
            }
            catch (Exception tdata)
            {
                resp.StatusCode = 404;
            }

            if (method.Equals("FeatAttr2"))
            {
                string[] tmp = classpath.Split(';');
                if (tmp.Length == 3)
                {
                    string mapName = tmp[0] + "|" + tmp[1];
                    long   count   = 0;
                    try
                    {
                        if (dataDic.ContainsKey(mapName))
                        {
                            dataDic.TryGetValue(mapName, out count);
                            count++;
                        }
                        dataDic[mapName] = count;
                    }
                    catch (Exception countEx)
                    {
                        dataDic = new System.Collections.Generic.Dictionary <string, long>();
                        dataDic.Add(mapName, count);
                    }

                    string time        = DateTime.Now.ToString();
                    string respHead    = "本次连接状态:" + resp.StatusCode + " " + resp.StatusDescription;
                    string remoteIp    = req.UserHostAddress;
                    string requestData = "查询数据:" + mapName + "\r\n本次服务器开机该数据访问计数:" + count;
                    string info        = time + "\r\n远程用户:" + remoteIp + "\r\n" + requestData + "\r\n" + respHead;
                    try
                    {
                        TddataLog.WriteLine(info + "\r\n");
                    }
                    catch (Exception ioe)
                    {
                    }
                }
            }
        }
    }
Пример #4
0
 public static void Main(string[] args)
 {
     if (args.Length != 2)
     {
         Console.Error.WriteLine("Usage: SHS.WCC <leader> <store>");
     }
     else
     {
         var sw    = Stopwatch.StartNew();
         var store = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
         var roots = store.AllocateUidState <long>();
         roots.SetAll(x => x);
         var batch = new Batch <long>(10000);
         foreach (long u in store.Uids())
         {
             batch.Add(u);
             if (batch.Full || store.IsLastUid(u))
             {
                 long[]   uids = batch;
                 long[][] fwds = store.BatchedGetLinks(uids, Dir.Fwd);
                 var      map  = new UidMap(fwds);
                 map.Add(uids);
                 var xRoots = GetRoots(roots, map);
                 for (int i = 0; i < fwds.Length; i++)
                 {
                     uids[i] = xRoots[map[uids[i]]];
                     for (int j = 0; j < fwds[i].Length; j++)
                     {
                         fwds[i][j] = xRoots[map[fwds[i][j]]];
                     }
                 }
                 map = new UidMap(fwds);
                 map.Add(uids);
                 long[] reprs = roots.GetMany(map);
                 for (int i = 0; i < fwds.Length; i++)
                 {
                     long A = uids[i];
                     long a = map[A];
                     while (A != reprs[a])
                     {
                         A = reprs[a];
                         a = map[A];
                     }
                     for (int j = 0; j < fwds[i].Length; j++)
                     {
                         long B = fwds[i][j];
                         long b = map[B];
                         while (B != reprs[b])
                         {
                             B = reprs[b];
                             b = map[B];
                         }
                         if (reprs[a] < reprs[b])
                         {
                             reprs[b] = reprs[a];
                         }
                         else
                         {
                             reprs[a] = reprs[b];
                             a        = b;
                         }
                     }
                 }
                 roots.SetMany(map, reprs);
                 batch.Reset();
             }
         }
         batch = new Batch <long>(400000);
         foreach (long u in store.Uids())
         {
             batch.Add(u);
             if (batch.Full || store.IsLastUid(u))
             {
                 GetRoots(roots, batch);
                 batch.Reset();
             }
         }
         using (var sorter = new DiskSorter <UidVal <long> >(new Comparer(), Write, Read, 100000000)) {
             foreach (var uv in roots.GetAll())
             {
                 sorter.Add(uv);
             }
             sorter.Sort();
             using (var wccWr = new BinaryWriter(new BufferedStream(new FileStream("wcc-main.bin", FileMode.Create, FileAccess.Write)))) {
                 using (var idxWr = new BinaryWriter(new BufferedStream(new FileStream("wcc-index.bin", FileMode.Create, FileAccess.Write)))) {
                     long last     = 0;
                     long lastRoot = -1;
                     for (long i = 0; i < sorter.Total; i++)
                     {
                         var uv = sorter.Get();
                         wccWr.Write(uv.uid);
                         if (i == 0)
                         {
                             lastRoot = uv.val;
                         }
                         else if (uv.val != lastRoot)
                         {
                             idxWr.Write(i - last);
                             idxWr.Write(last);
                             last     = i;
                             lastRoot = uv.val;
                         }
                     }
                     Debug.Assert(sorter.AtEnd());
                     if (sorter.Total > 0)
                     {
                         idxWr.Write(sorter.Total - last);
                         idxWr.Write(last);
                     }
                 }
             }
         }
         var dict = new System.Collections.Generic.Dictionary <long, long>();
         using (var rd = new BinaryReader(new BufferedStream(new FileStream("wcc-index.bin", FileMode.Open, FileAccess.Read)))) {
             while (true)
             {
                 try {
                     long size = rd.ReadInt64();
                     long pos  = rd.ReadInt64();
                     if (!dict.ContainsKey(size))
                     {
                         dict[size] = 0;
                     }
                     dict[size]++;
                 } catch (EndOfStreamException) {
                     break;
                 }
             }
         }
         long maxSize = 0;
         long numWCCs = 0;
         foreach (var kv in dict)
         {
             if (kv.Key > maxSize)
             {
                 maxSize = kv.Key;
             }
             numWCCs += kv.Value;
         }
         Console.WriteLine("Done. {0} weakly connected components, largest has {1} nodes. Job took {2} seconds.", numWCCs, maxSize, 0.001 * sw.ElapsedMilliseconds);
     }
 }
Пример #5
0
    public static DataTable getAccessionDetailsExtended(String AccountNumber, String ChartNumber, String PetName, String owner, String TestCode, String DateFrom, String DateTo, String DoctorName, Int32 startIndex, Int32 noOfRecords, out String query, Boolean useSoundex, String pageName, Int32 timeout, out Boolean isError)
    {
        CACHEDAL.ConnectionClass cache = new CACHEDAL.ConnectionClass();
        #region Preparing Query
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("SELECT ");
        sb.Append("ACC_Accession,");
        sb.Append("ACC_OwnerLastName||', '||ACC_PetFirstName AS PATIENT,");
        sb.Append("ACC_TestsOrderedDisplayString AS TESTSORDERED,");
        sb.Append("ACC_ClientDR->CLF_CLNUM AS ACCOUNTNUM,");
        sb.Append("ACC_MiniLogDate As ORDERDATE,");
        sb.Append("ACC_MiniLogTime As ORDERTIME,");
        sb.Append("ACC_ReportStatus As ReportStatus,");
        sb.Append("ACC_IsStat As StatDesignation,");
        sb.Append("$$GETINQNOTE^XT11(ACC_Accession) As InqNotes ");
        sb.Append("FROM ");
        sb.Append("ORD_Accession ");
        sb.Append("WHERE ");
        sb.Append("1=1");
        //There is an index with Doctor & Account.
        //If Doctor is present as search criteria, then client has to be present in the search criteria
        if (DoctorName.Length > 0)
        {
            sb.Append(" AND ACC_RequestingPhysician %STARTSWITH '" + DoctorName + "'");

            if (AccountNumber.Length > 0)
            {
                sb.Append(" AND ACC_ClientDR->CLF_CLNUM ='" + AccountNumber + "'");
            }
            else if (DateFrom.Length == 0 && DateTo.Length == 0)    //SSM 03/11/2011 #Issue115786 Migrating Accession search Changes
            {
                sb.Append(" AND ACC_ClientDR->CLF_CLNUM <>''");
            }
        }
        else if (AccountNumber.Length > 0)
        {
            sb.Append(" AND ACC_ClientDR->CLF_CLNUM ='" + AccountNumber + "'");
        }
        if (ChartNumber.Length > 0)
        {
            sb.Append(" AND ACC_MedicalRecordsNumber ='" + ChartNumber + "'");
        }
        if (!useSoundex)
        {
            if (owner.Length > 0)
            {
                sb.Append(" AND ACC_OwnerLastName %STARTSWITH '" + owner + "'");
            }
            if (PetName.Length > 0)
            {
                sb.Append(" AND ACC_PetFirstName %STARTSWITH '" + PetName + "'");
            }
        }
        else
        {
            if (owner.Length > 0)
            {
                System.Collections.Generic.Dictionary <string, string> tmpCol = new System.Collections.Generic.Dictionary <string, string>();
                tmpCol.Add("OwnerName", owner);
                tmpCol.Add("PetName", String.Empty);
                //String SoundexString = cache.StoredProcedure("?=call SP2_getSoundex(?,?)", tmpCol).Value.ToString();
                String SoundexString = cache.StoredProcedure("?=call SP2_getSoundex(?,?)", tmpCol, pageName, timeout, out isError).Value.ToString();
                if (isError) // for Reset Search
                {
                    query = "";
                    return(null);
                }
                if (SoundexString.Length > 0)
                {
                    SoundexString = owner + "^#" + SoundexString;
                }
                else
                {
                    SoundexString = owner + "^";
                }
                if (SoundexString.Length > 0)
                {
                    String[] OwnerPet = SoundexString.Split('#');
                    tmpCol.Clear();
                    sb.Append(" AND (");
                    for (Int32 i = 0; i < OwnerPet.Length; i++)
                    {
                        String[] tmp = OwnerPet[i].Split('^');
                        if (!tmpCol.ContainsKey(tmp[0]) && tmp[0].Length > 0)
                        {
                            tmpCol.Add(tmp[0], String.Empty);
                            sb.Append(" (ACC_PetFirstName %STARTSWITH '" + PetName + "' AND ACC_OwnerLastName %STARTSWITH '" + tmp[0] + "') OR");
                            //// Note:  'ACC_PetFirstName' is for petName with tmp[1]
                            ////        'ACC_OwnerLastName' is for owner with tmp[0]
                        }
                    }
                    sb.Remove(sb.Length - 2, 2);
                    sb.Append(" )");
                }
            }
            else if (PetName.Length > 0)
            {
                System.Collections.Generic.Dictionary <string, string> tmpCol = new System.Collections.Generic.Dictionary <string, string>();
                tmpCol.Add("OwnerName", owner);
                tmpCol.Add("PetName", PetName);
                // String SoundexString = cache.StoredProcedure("?=call SP2_getSoundex(?,?)", tmpCol).Value.ToString();
                String SoundexString = cache.StoredProcedure("?=call SP2_getSoundex(?,?)", tmpCol, pageName, timeout, out isError).Value.ToString();
                if (isError) // for Reset Search
                {
                    query = "";
                    return(null);
                }

                if (SoundexString.Length > 0)
                {
                    SoundexString = "^" + PetName + "#" + SoundexString;
                }
                else
                {
                    SoundexString = "^" + PetName;
                }
                if (SoundexString.Length > 0)
                {
                    String[] OwnerPet = SoundexString.Split('#');
                    tmpCol.Clear();
                    sb.Append(" AND (");
                    for (Int32 i = 0; i < OwnerPet.Length; i++)
                    {
                        String[] tmp = OwnerPet[i].Split('^');
                        if (!tmpCol.ContainsKey(tmp[1]) && tmp[1].Length > 0)
                        {
                            tmpCol.Add(tmp[1], String.Empty);
                            sb.Append(" (ACC_PetFirstName %STARTSWITH '" + tmp[1] + "' AND ACC_OwnerLastName %STARTSWITH '') OR");
                            //// Note:  'ACC_PetFirstName' is for petName with tmp[1]
                            ////        'ACC_OwnerLastName' is for owner with tmp[0]
                        }
                    }
                    sb.Remove(sb.Length - 2, 2);
                    sb.Append(" )");
                }
            }
        }
        if (!String.IsNullOrEmpty(TestCode))
        {
            TestCode = TestCode.Replace("'", "''");
            sb.Append(" AND (ACC_TestsOrderedDisplayString ='" + TestCode + "' OR ACC_TestsOrderedDisplayString %STARTSWITH '" + TestCode + ",' OR ACC_TestsOrderedDisplayString LIKE '%, " + TestCode + "' OR ACC_TestsOrderedDisplayString LIKE '%, " + TestCode + ", %')");
        }
        if (!String.IsNullOrEmpty(DateFrom) && !String.IsNullOrEmpty(DateTo))
        {
            sb.Append(" AND ACC_MiniLogDate>= {d '" + DateTime.Parse(DateFrom).ToString("yyyy-MM-dd") + "'} AND ACC_MiniLogDate<={d '" + DateTime.Parse(DateTo).ToString("yyyy-MM-dd") + "'}");
        }
        if ((!String.IsNullOrEmpty(DateFrom) && !String.IsNullOrEmpty(DateTo)) || (!String.IsNullOrEmpty(AccountNumber)))
        {
            //sb.Append(" ORDER BY ACC_MiniLogDate DESC, ACC_OwnerLastName");
            sb.Append(" ORDER BY ACC_MiniLogDate DESC, ACC_MiniLogTime DESC");
        }
        else
        {
            //sb.Append(" ORDER BY ACC_OwnerLastName");
        }

        string selectStatement = sb.ToString();
        #endregion Preparing Query
        query = selectStatement;
        return(cache.FillCacheDataTable(selectStatement, startIndex, noOfRecords, pageName, timeout, out isError));
    }
    // $ANTLR end multExpr


    // $ANTLR start atom
    // H:\\KB\\AntLr\\AntLr\\AntLr\\SimpleCalc3.g:69:1: atom returns [int value] : ( INT | ID | LPAREN expr RPAREN );
    public int atom() // throws RecognitionException [1]
    {
        int value = 0;

        IToken INT4  = null;
        IToken ID5   = null;
        int    expr6 = 0;


        try
        {
            // H:\\KB\\AntLr\\AntLr\\AntLr\\SimpleCalc3.g:70:2: ( INT | ID | LPAREN expr RPAREN )
            int alt5 = 3;
            switch (input.LA(1))
            {
            case INT:
            {
                alt5 = 1;
            }
            break;

            case ID:
            {
                alt5 = 2;
            }
            break;

            case LPAREN:
            {
                alt5 = 3;
            }
            break;

            default:
                NoViableAltException nvae_d5s0 =
                    new NoViableAltException("69:1: atom returns [int value] : ( INT | ID | LPAREN expr RPAREN );", 5, 0, input);

                throw nvae_d5s0;
            }

            switch (alt5)
            {
            case 1:
                // H:\\KB\\AntLr\\AntLr\\AntLr\\SimpleCalc3.g:70:4: INT
            {
                INT4 = (IToken)input.LT(1);
                Match(input, INT, FOLLOW_INT_in_atom239);
                value = int.Parse(INT4.Text);
            }
            break;

            case 2:
                // H:\\KB\\AntLr\\AntLr\\AntLr\\SimpleCalc3.g:71:4: ID
            {
                ID5 = (IToken)input.LT(1);
                Match(input, ID, FOLLOW_ID_in_atom249);
                if (IDTable.ContainsKey(ID5.Text))
                {
                    value = IDTable[ID5.Text];
                }
                else
                {
                    System.Console.WriteLine("ID does not exist");
                }
            }
            break;

            case 3:
                // H:\\KB\\AntLr\\AntLr\\AntLr\\SimpleCalc3.g:72:4: LPAREN expr RPAREN
            {
                Match(input, LPAREN, FOLLOW_LPAREN_in_atom259);
                PushFollow(FOLLOW_expr_in_atom261);
                expr6 = expr();
                followingStackPointer_--;

                Match(input, RPAREN, FOLLOW_RPAREN_in_atom263);
                value = expr6;
            }
            break;
            }
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input, re);
        }
        finally
        {
        }
        return(value);
    }
Пример #7
0
 public static void Main(string[] args)
 {
     if (args.Length != 2)
     {
         Console.Error.WriteLine("Usage: SHS.SCC2 <leader> <store>");
     }
     else
     {
         var sw       = Stopwatch.StartNew();
         var shs      = new Service(args[0]).OpenStore(Guid.Parse(args[1]));
         var map      = shs.AllocateUidState <int>(); // Mapping from UID to local ID
         int numVerts = 0;                            // Number of core vertices
         var batch    = new Batch <long>(500000);
         foreach (long u in shs.Uids())
         {
             batch.Add(u);
             if (batch.Full || shs.IsLastUid(u))
             {
                 int[] fwdDegs  = shs.BatchedGetDegree(batch, Dir.Fwd);
                 int[] bwdDegs  = shs.BatchedGetDegree(batch, Dir.Bwd);
                 var   mapChunk = new int[batch.Count];
                 for (int i = 0; i < batch.Count; i++)
                 {
                     mapChunk[i] = fwdDegs[i] == 0 || bwdDegs[i] == 0 ? -1 : numVerts++;
                 }
                 map.SetMany(batch, mapChunk);
                 batch.Reset();
             }
         }
         uint numEdges = 0;
         foreach (var up in map.GetAll())
         {
             if (up.val != -1)
             {
                 batch.Add(up.uid);
             }
             if (batch.Full || shs.IsLastUid(up.uid))
             {
                 long[][] nbors       = shs.BatchedGetLinks(batch, Dir.Fwd);
                 int[]    mappedNbors = map.GetMany(Flatten(nbors));
                 int      q           = 0;
                 for (int i = 0; i < nbors.Length; i++)
                 {
                     for (int j = 0; j < nbors[i].Length; j++)
                     {
                         if (mappedNbors[q++] != -1)
                         {
                             numEdges++;
                         }
                     }
                 }
                 batch.Reset();
             }
         }
         uint[] pastLast = new uint[numVerts]; // one past last link of that page
         var    links    = new int[numEdges];
         int    p        = 0;
         uint   r        = 0;
         foreach (var up in map.GetAll())
         {
             if (up.val != -1)
             {
                 batch.Add(up.uid);
             }
             if (batch.Full || shs.IsLastUid(up.uid))
             {
                 long[][] nbors       = shs.BatchedGetLinks(batch, Dir.Fwd);
                 int[]    mappedNbors = map.GetMany(Flatten(nbors));
                 int      q           = 0;
                 for (int i = 0; i < nbors.Length; i++)
                 {
                     for (int j = 0; j < nbors[i].Length; j++)
                     {
                         int id = mappedNbors[q++];
                         if (id != -1)
                         {
                             links[r++] = id;
                         }
                     }
                     pastLast[p++] = r;
                 }
                 batch.Reset();
             }
         }
         var   bv     = new BitVector(numVerts); // All false at creation
         int[] stk    = new int[numVerts];
         int   stkPtr = stk.Length;
         for (int u = 0; u < numVerts; u++)
         {
             if (!bv[u])
             {
                 bv[u] = true;
                 Frame frame = new Frame(null, u, pastLast);
                 while (frame != null)
                 {
                     while (frame.ctr < pastLast[frame.id])
                     {
                         int v = links[frame.ctr++];
                         if (!bv[v])
                         {
                             bv[v] = true;
                             frame = new Frame(frame, v, pastLast);
                         }
                     }
                     stk[--stkPtr] = frame.id;
                     frame         = frame.parent;
                 }
             }
         }
         p = 0;
         r = 0;
         foreach (var up in map.GetAll())
         {
             if (up.val != -1)
             {
                 batch.Add(up.uid);
             }
             if (batch.Full || shs.IsLastUid(up.uid))
             {
                 long[][] nbors       = shs.BatchedGetLinks(batch, Dir.Bwd);
                 int[]    mappedNbors = map.GetMany(Flatten(nbors));
                 int      q           = 0;
                 for (int i = 0; i < nbors.Length; i++)
                 {
                     for (int j = 0; j < nbors[i].Length; j++)
                     {
                         int id = mappedNbors[q++];
                         if (id != -1)
                         {
                             links[r++] = id;
                         }
                     }
                     pastLast[p++] = r;
                 }
                 batch.Reset();
             }
         }
         var pam = new long[numVerts];
         p = 0;
         foreach (var up in map.GetAll())
         {
             if (up.val != -1)
             {
                 pam[p++] = up.uid;
             }
         }
         using (var sccWr = new BinaryWriter(new BufferedStream(new FileStream("scc-main.bin", FileMode.Create, FileAccess.Write)))) {
             using (var idxWr = new BinaryWriter(new BufferedStream(new FileStream("scc-index.bin", FileMode.Create, FileAccess.Write)))) {
                 long sccPos = 0;
                 bv.SetAll(false);
                 for (int i = 0; i < stk.Length; i++)
                 {
                     int u = stk[i];
                     if (!bv[u])
                     {
                         long sccSize = 0;
                         bv[u] = true;
                         Frame frame = new Frame(null, u, pastLast);
                         while (frame != null)
                         {
                             while (frame.ctr < pastLast[frame.id])
                             {
                                 int v = links[frame.ctr++];
                                 if (!bv[v])
                                 {
                                     bv[v] = true;
                                     frame = new Frame(frame, v, pastLast);
                                 }
                             }
                             sccWr.Write(pam[frame.id]);
                             sccSize++;
                             frame = frame.parent;
                         }
                         idxWr.Write(sccSize);
                         idxWr.Write(sccPos);
                         sccPos += sccSize;
                     }
                 }
                 foreach (var up in map.GetAll())
                 {
                     if (up.val == -1)
                     {
                         sccWr.Write(up.uid);
                         idxWr.Write(1L);
                         idxWr.Write(sccPos++);
                     }
                 }
             }
         }
         var dict = new System.Collections.Generic.Dictionary <long, long>();
         using (var ib = new BinaryReader(new BufferedStream(new FileStream("scc-index.bin", FileMode.Open, FileAccess.Read)))) {
             while (true)
             {
                 try {
                     long size = ib.ReadInt64();
                     long pos  = ib.ReadInt64();
                     if (!dict.ContainsKey(size))
                     {
                         dict[size] = 0;
                     }
                     dict[size]++;
                 } catch (EndOfStreamException) {
                     break;
                 }
             }
         }
         long maxSize = 0;
         long numSCCs = 0;
         foreach (var kv in dict)
         {
             if (kv.Key > maxSize)
             {
                 maxSize = kv.Key;
             }
             numSCCs += kv.Value;
         }
         Console.WriteLine("Done. Job took {0} seconds.", 0.001 * sw.ElapsedMilliseconds);
     }
 }
Пример #8
0
    private void Teleport(StateMachine st)
    {
        //Get a random starting spot.
        Location jumpPos = new Location(Random.Range(0, level.Map.GetLength(0)),
                                        Random.Range(0, level.Map.GetLength(1)));

        //Find the nearest free spot. Use depth-first level traversal.

        System.Collections.Generic.Stack <Location> searchSpace = new System.Collections.Generic.Stack <Location>();
        searchSpace.Push(jumpPos);
        System.Collections.Generic.Dictionary <Location, bool> searchedYet = new System.Collections.Generic.Dictionary <Location, bool>();
        searchedYet.Add(jumpPos, true);

        while (level.Map[jumpPos.X, jumpPos.Y])
        {
            //Use depth-first traversal.

            jumpPos = searchSpace.Pop();

            if (!level.Map[jumpPos.X, jumpPos.Y])
            {
                break;
            }
            else
            {
                //Add the four adjacent sides in random order.

                int      start = Random.Range(0, 4);
                Location loc   = new Location();

                for (int i = 0; i < 4; ++i)
                {
                    int index = (start + i) % 4;

                    switch (index)
                    {
                    case 0:
                        loc.X = jumpPos.X + 1;
                        loc.Y = jumpPos.Y;
                        break;

                    case 1:
                        loc.X = jumpPos.X - 1;
                        loc.Y = jumpPos.Y;
                        break;

                    case 2:
                        loc.X = jumpPos.X;
                        loc.Y = jumpPos.Y + 1;
                        break;

                    case 3:
                        loc.X = jumpPos.X;
                        loc.Y = jumpPos.Y - 1;
                        break;

                    default: throw new System.NotImplementedException();
                    }

                    if (loc.X >= 0 && loc.X < level.Map.GetLength(0) &&
                        loc.Y >= 0 && loc.Y < level.Map.GetLength(1) &&
                        !searchedYet.ContainsKey(loc))
                    {
                        searchSpace.Push(loc);
                        searchedYet[loc] = true;
                    }
                }
            }

            continue;
        }

        st.transform.position = new Vector3(jumpPos.X, jumpPos.Y, st.transform.position.z);
    }
Пример #9
0
    public void Create(System.Collections.Generic.Dictionary <string, object> eventDict)
    {
        Debug.Log("IgniteEvent:Create");

        if (eventDict.ContainsKey("id"))
        {
            this.Id = Convert.ToString(eventDict["id"]);
        }
        if (eventDict.ContainsKey("startTime"))
        {
            var  epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            long t     = Convert.ToInt64(eventDict["startTime"]);
            this.StartTime = epoch.AddSeconds(t);
        }
        if (eventDict.ContainsKey("authorized"))
        {
            this.Authorized = Convert.ToBoolean(eventDict["authorized"]);
        }
        if (eventDict.ContainsKey("eventId"))
        {
            this.EventId = Convert.ToString(eventDict["eventId"]);
        }
        if (eventDict.ContainsKey("state"))
        {
            this.State = Convert.ToString(eventDict["state"]);
        }
        if (eventDict.ContainsKey("score"))
        {
            this.Score = (float)Convert.ToDouble(eventDict["score"]);
        }
        if (eventDict.ContainsKey("type"))
        {
            this.Type = (IgniteEventType)Enum.Parse(typeof(IgniteEventType), Convert.ToString(eventDict["type"]));
        }
        if (eventDict.ContainsKey("endTime"))
        {
            var  epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            long t     = Convert.ToInt64(eventDict["endTime"]);
            this.EndTime = epoch.AddSeconds(t);
        }
        if (eventDict.ContainsKey("metadata"))
        {
            System.Collections.Generic.Dictionary <string, object> eventMetadataDict = eventDict["metadata"] as System.Collections.Generic.Dictionary <string, object>;
            EventMetadata eventMetadata = new EventMetadata();
            if (eventMetadataDict.ContainsKey("imageUrl"))
            {
                eventMetadata.imageUrl = Convert.ToString(eventMetadataDict["imageUrl"]);
            }
            if (eventMetadataDict.ContainsKey("name"))
            {
                eventMetadata.Name = Convert.ToString(eventMetadataDict["name"]);
            }
            if (eventMetadataDict.ContainsKey("gamedata"))
            {
                eventMetadata.GameData = Convert.ToString(eventMetadataDict["gamedata"]);
            }
            this.Metadata = eventMetadata;
        }

        switch (this.Type)
        {
        case IgniteEventType.leaderBoard:
            FuelSDKGroovePlanetIntegration.Instance.GetLeaderBoard(this.Id);
            activity = new IgniteLeaderBoard();
            break;

        case IgniteEventType.mission:
            FuelSDKGroovePlanetIntegration.Instance.GetMission(this.Id);
            activity = new IgniteMission();
            break;

        case IgniteEventType.quest:
            FuelSDKGroovePlanetIntegration.Instance.GetQuest(this.Id);
            activity = new IgniteQuest();
            break;

        default:
            break;
        }
    }