Esempio n. 1
0
        public ActionResult AddNew(HurricaneViewModel NewHurricane)
        {
            if (ModelState.IsValid)
            {
                Hurricane newHurricane = (Hurricane)NewHurricane;
                newHurricane.AffectedCounties.Clear();
                _context.Hurricanes.Add(newHurricane);
                foreach (int countyId in NewHurricane.AffectedCountiesId)
                {
                    newHurricane.AffectedCounties.Add(_context.Counties.Find(countyId));
                }

                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                IEnumerable <CountyViewModel> availableCounties = _context.Counties
                                                                  .ToArray()
                                                                  .Select(county => (CountyViewModel)county)
                                                                  .ToArray();

                HurricanesIndexViewModel viewModel = new HurricanesIndexViewModel(availableCounties)
                {
                    Hurricanes = _context.Hurricanes
                                 .Include(h => h.AffectedCounties)
                                 .ToArray()
                                 .Select(h => (HurricaneViewModel)h)
                                 .ToArray(),
                    NewHurricane = NewHurricane
                };
                return(View("Index", viewModel));
            }
        }
Esempio n. 2
0
            public void Print(StreamWriter text, bool withAveLCS)
            {
                // Print id of cluster and number of hurricanes in the cluster
                string line = "id=" + id.ToString().PadLeft(5) + " cnt=" + set.Count.ToString().PadLeft(5);

                if (withAveLCS)
                {
                    double aveLCS = AveLCS();
                    line = line + " aveLCS=" + aveLCS.ToString().PadLeft(15) + ": ";
                }
                else
                {
                    line = line + ": ";
                }
                foreach (Hurricane i in set)
                {
                    line = line + i.id.ToString() + ",";
                }

                // If only two go ahead and print LCS
                if (set.Count == 2)
                {   // Get hurricanes
                    Hurricane a = set[0];
                    Hurricane b = set[1];
                    // Get LCS
                    string lcsMatch;
                    a.LCS(b, out lcsMatch);
                    line = line + " LCS:" + lcsMatch;
                }

                text.WriteLine(line);
            }
Esempio n. 3
0
        public void HurricaneTest()
        {
            Card   hur1   = new Hurricane();
            string name   = "Hurricane";
            string actual = hur1.GetCardName();

            Assert.AreEqual(name, actual);
        }
Esempio n. 4
0
    public override void ReleaseSpell()
    {
        GameObject hurricane = poolManager.GetGameObject("Hurricane");
        Hurricane  a         = hurricane.GetComponent <Hurricane>();

        a.SetThrower(player);

        //根据风瞄准镜设置生成位置
        a.SetStartPosition(windAbility.GetSightHeadPosition());
    }
Esempio n. 5
0
        public void AttackTest_Hurricane_Hransig()
        {
            Card hur1  = new Hurricane();
            Card hran1 = new Hransig();
            // 25 +10 - 20
            int expected = hran1.GetHP() - hur1.GetAP() + hran1.GetDP();
            int actual   = hur1.Attack(ref hran1).GetHP();


            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public async Task <ActionResult> Delete(int id)
        {
            Hurricane hurricane = await _context.Hurricanes.FindAsync(id);

            if (hurricane is null)
            {
                return(new HttpNotFoundResult("Unable to find the selected storm"));
            }
            else
            {
                _context.Hurricanes.Remove(hurricane);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 7
0
        public async Task <ActionResult> Edit(int id)
        {
            Hurricane hurricane = await _context.Hurricanes.FindAsync(id);

            if (hurricane is null)
            {
                return(new HttpNotFoundResult("Unable to find the selected storm"));
            }
            else
            {
                await _context.Entry(hurricane).Collection(h => h.AffectedCounties).LoadAsync();

                ViewData["AvailableCounties"] = _context.Counties
                                                .ToArray()
                                                .Select(county => (CountyViewModel)county)
                                                .ToArray();

                return(View((HurricaneViewModel)hurricane));
            }
        }
Esempio n. 8
0
            public int LCS(Hurricane b, out string lcsMatch)
            {
                // Try to find this LCS pair from cache for speed
                int lcs;

                if (cacheLCS.TryGetValue(b.id, out Pair <int, string> prev))
                {
                    // Found a match
                    lcsMatch = prev.Second;
                    lcs      = prev.First;
                }
                else
                {
                    // Not computed yet
                    lcs = findInt(bearing, b.bearing, out lcsMatch);
                    // Add computation
                    cacheLCS.Add(b.id, new Pair <int, string>(lcs, lcsMatch));
                }

                // Return new value
                return(lcs);
            }
Esempio n. 9
0
        public async Task <ActionResult> Edit(HurricaneViewModel hurricane)
        {
            if (ModelState.IsValid)
            {
                Hurricane h = await _context.Hurricanes.FindAsync(hurricane.Id);

                await _context.Entry(h).Collection(hu => hu.AffectedCounties).LoadAsync();

                h.Id               = hurricane.Id;
                h.Name             = hurricane.Name;
                h.SaffirSimpsonCat = hurricane.SaffirSimpsonCategory;
                h.LandfallDate     = hurricane.LandfallDate;

                foreach (int countyId in hurricane.AffectedCountiesId)
                {
                    if (!h.AffectedCounties.Any(county => county.Id == countyId))
                    {
                        h.AffectedCounties.Add(_context.Counties.Find(countyId));
                    }
                }

                foreach (County county in h.AffectedCounties.ToArray())
                {
                    if (!hurricane.AffectedCountiesId.Any(countyId => countyId == county.Id))
                    {
                        h.AffectedCounties.Remove(county);
                    }
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(hurricane));
            }
        }
Esempio n. 10
0
 public override void Init(Hurricane.Library.Data.Game row)
 {
     instance = this;
     this.id = row.guid;
     world = new World(this.id);
 }
Esempio n. 11
0
        public static void Main(String[] args)
        {
            //String A = "ACBDEA";
            //String B = "ABCDA";
            //int[] Aint = { 12, 17, 15, 11, 6, 1, 2, 5, 5, 7, 11, 10, 12, 12, 15, 15, 17, -17, -18, 17, 17, 16, 13, 9, 6, 4, 4, 7, 9, 9, 9, 8, 14, 9, -1, 9, -16, 3, 3, 8, -11, -8, 9, -10, 9, -3, -9, -1, 3, -8, 1 };
            //int[] Bint = { 11, 11, 10, 9, 7, 4, 4, 3, 3, 4, 4, 3, 4, 1, -3, -3, 1, 5, 10, 16, 17, -18, 14, 9, 0, -2, -3, -2, -1, -1, -1, 0, 0, 0, 1, 1, 1, 2, 3, 4, 6, 8, 10, 11, 10, 10, 10, 8, 10, 10, 8, 8, 9, 8, 6, 8, 9, -18, 14, -9 };



            //int tempResult = findInt(Aint, Bint);
            //UNNAMED_01_1851,0,-1,0,1,-1,0,0,2,4,7,9,9,10,16,


            List <SortedSet <string> > resultSet = new List <SortedSet <string> >();

            using (TextFieldParser parser = new TextFieldParser(@"C:\Users\User\Desktop\HurricaneProject\sequences.txt"))
            {
                parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                parser.SetDelimiters(",");

                Dictionary <string, int[]> sequenceDict = new Dictionary <string, int[]>();

                while (!parser.EndOfData)
                {
                                        //Process row
                                        string[] fields = parser.ReadFields();
                    string name   = fields[0];
                    int    length = fields.Length - 1;
                    while (fields[length] == "")
                    {
                        length--;
                    }
                    int[] tempInt = new int[length];
                    for (int i = 1; i <= length; i++)
                    {
                        tempInt[i - 1] = Int32.Parse(fields[i]);
                    }
                    sequenceDict.Add(name, tempInt);
                }

/*                int[] Aint = sequenceDict["UNNAMED_05_1864"];
 *              int[] Bint = sequenceDict["HUMBERTO_09_2007"];
 *
 *              string lcsMatch;
 *              int lcs = Hurricane.findInt(Aint, Bint, out lcsMatch);*/



                StreamWriter logFile = new StreamWriter("C:\\Users\\User\\Desktop\\HurricaneProject\\ClusterLog.txt", false);

                ClusterList fullSet = new ClusterList();

                // Build set of clusters
                for (int i = 0; i < sequenceDict.Keys.Count; i++)
                {
                    //if (i > 200) break;
                    string nameA = sequenceDict.Keys.ElementAt(i);
                    int[]  intA  = sequenceDict[sequenceDict.Keys.ElementAt(i)];

                    Hurricane hur = new Hurricane();
                    hur.id      = nameA;
                    hur.bearing = intA;

                    Cluster cluster = new Cluster();
                    cluster.id = i;
                    cluster.set.Add(hur);

                    fullSet.clusters.Add(cluster);
                }

                // Test print matrix
                Console.WriteLine("Iter 0 (full matrix)");
                logFile.WriteLine("Iter 0 (full matrix)");
                fullSet.Print(logFile);
                //fullSet.PrintMatrix(logFile);

                // Reqiured minimum clustering score
                int minScoreAllowed = 5;

                // Begin clustering on full list
                ClusterList curCluster = fullSet;
                // Iterate
                for (int i = 1; ; i++)
                {
                    // Try to find two clusters to combine
                    int         lcsScore;
                    ClusterList newCluster = curCluster.ConsolidateLCS(minScoreAllowed, out lcsScore);

                    // No more good clustering
                    if (newCluster == curCluster)
                    {   // No more clusters match to within minScoreAllowed
                        logFile.WriteLine("Clustering completed sorting by cluster size");
                        curCluster.SortByCount();
                        curCluster.Print(logFile, true);

                        // Write cluster groups
                        StreamWriter grpFile = new StreamWriter("C:\\Users\\User\\Desktop\\HurricaneProject\\ClusterGrps.txt", false);
                        curCluster.WriteIds(grpFile);
                        grpFile.Close();
                        break;
                    }
                    else
                    {   // Accept the new cluster as the current
                        curCluster = newCluster;
                    }

                    // Log progress
                    logFile.WriteLine("Iter " + i.ToString() + " clusters " + curCluster.ClusterCount().ToString() + " LCSscore=" + lcsScore.ToString());
                    Console.WriteLine("Iter " + i.ToString() + " clusters " + curCluster.ClusterCount().ToString() + " LCSscore=" + lcsScore.ToString());
                    curCluster.Print(logFile);

                    // Print if reasonable
                    // curCluster.PrintMatrix(logFile);
                }
                Console.WriteLine("Done");

                logFile.Close();
            }
        }