コード例 #1
0
        public Uri SaveFile(string folder, FileBase64 file)
        {
            CloudBlobContainer CandidateContainer;
            CloudBlockBlob     blob;
            Uri result = null;

            CandidateContainer = BlobClient.GetContainerReference(folder);

            if (!CandidateContainer.Exists())
            {
                CandidateContainer.Create();
                CandidateContainer.SetPermissions(
                    new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }

            byte[] Image = Convert.FromBase64String(file.Base64);
            using (MemoryStream stream = new MemoryStream(Image))
            {
                blob = CandidateContainer.GetBlockBlobReference(
                    string.Format("{0}.{1}", file.Name, file.Format)
                    );

                blob.UploadFromStream(stream);
                result = blob.Uri;
            }
            return(result);
        }
コード例 #2
0
    public static CandidateContainer Load(string path)
    {
        TextAsset          _xml       = Resources.Load <TextAsset>(path);
        XmlSerializer      serializer = new XmlSerializer(typeof(CandidateContainer));
        StringReader       reader     = new StringReader(_xml.text);
        CandidateContainer candidates = serializer.Deserialize(reader) as CandidateContainer;

        reader.Close();
        return(candidates);
    }
コード例 #3
0
        // Constructor

        public GridGenerator(int rowsNumber, int columnsNumber, int itemsPerContainer, int initialIncorrectContainersNumber,
                             DistanceTypes distanceType)
        {
            RowsNumber        = rowsNumber;
            ColumnsNumber     = columnsNumber;
            ItemsPerContainer = itemsPerContainer;

            InitialIncorrectContainersNumber = initialIncorrectContainersNumber;
            IncorrectContainersNumber        = 0;

            AverageDistance = 0;
            DistanceType    = distanceType;

            containersNumber = RowsNumber * ColumnsNumber;

            // Compute the itemId of each container.
            // Start with alphabetical ordering ...
            List <int> containersItemValues = new List <int>();

            for (int itemId = 0; itemId < containersNumber; ++itemId)
            {
                containersItemValues.Add(itemId);
            }
            // ... and then randomly permute
            ShuffleList.Shuffle(containersItemValues);

            // Now fill the containers with items of the appropriate itemId.
            // In each container, the first few items will be of the correct itemId,
            // and the last item will be empty.
            // Later on, the last item of some containers will be permuted.
            Containers = new Container[RowsNumber, ColumnsNumber];
            for (int row = 0; row < RowsNumber; ++row)
            {
                for (int col = 0; col < ColumnsNumber; ++col)
                {
                    Containers[row, col]       = new Container();
                    Containers[row, col].items = new int[ItemsPerContainer];

                    for (int i = 0; i < ItemsPerContainer; ++i)
                    {
                        Containers[row, col].items[i] = containersItemValues[row * ColumnsNumber + col];
                    }
                }
            }

            // BEGIN: We now want to permute the last items of *some* of the containers.
            // InitiallyIncorrectContainersFraction tells us in how many containers to do this.

            // We first build a list of containers, shuffle it, and then choose a fraction
            // of the containers in that list on which to do more work.
            // To make it easier to identify each container in the list,
            // rather than storing the (row, column) of each container in the list,
            // we store a single (containerID), where containerID == (row*NumberColumns + column)
            // uniquely identifies each container.
            List <int> containerIds = new List <int>();

            for (int i = 0; i < containersNumber; ++i)
            {
                containerIds.Add(i);
            }
            // randomly permute
            ShuffleList.Shuffle(containerIds);

            // Now imagine the list of containerIDs having length N,
            // and imagine splitting this list into two sublists
            // with indices [0..(k-1)] and [k..N]
            // where N = NumberRows * NumberColumns,
            // and k = initialIncorrectContainersNumber.
            // The first sublist is the one where we want to permute the last items
            // of the containers.
            // The second sublist is the one where the containers should remain correct.
            // Since no further work is required on the containers of the second sublist,
            // forget about it, and just store the first sublist.
            containerIds.RemoveRange(initialIncorrectContainersNumber, containerIds.Count - initialIncorrectContainersNumber);

            // Iterate over the containers in the list (now containing only the first sublist),
            // and set their last items to be empty.
            for (int j = 0; j < containerIds.Count; ++j)
            {
                int r = containerIds[j] / ColumnsNumber;
                int c = containerIds[j] % ColumnsNumber;
                Containers[r, c].items[ItemsPerContainer - 1] = EMPTY_ITEM_ID;
            }

            // Now, for each (source) container remaining in the list containerIDs,
            // we build a list of candidate target containers to which the
            // original last item of the source could be moved.
            // We randomly select among the candidate targets and put the item there.
            for (int i_source = 0; i_source < containerIds.Count; ++i_source)
            {
                int r_source = containerIds[i_source] / ColumnsNumber;
                int c_source = containerIds[i_source] % ColumnsNumber;

                List <CandidateContainer> candidates = new List <CandidateContainer>();
                for (int i_target = 0; i_target < containerIds.Count; ++i_target)
                {
                    if (i_target == i_source)
                    {
                        continue;
                    }

                    CandidateContainer cc = new CandidateContainer();
                    cc.containerId = containerIds[i_target];
                    cc.row         = cc.containerId / ColumnsNumber;
                    cc.column      = cc.containerId % ColumnsNumber;

                    if (Containers[cc.row, cc.column].items[ItemsPerContainer - 1] != EMPTY_ITEM_ID)
                    {
                        continue;
                    }

                    float dx = (cc.column - c_source) * horizontalSpacingBetweenContainers;
                    float dy = (cc.row - r_source) * verticalSpacingBetweenContainers;
                    cc.distance = (float)Math.Sqrt(dx * dx + dy * dy);

                    candidates.Add(cc);
                }

                if (candidates.Count == 0)
                {
                    // there are no other containers to move the item
                    Containers[r_source, c_source].items[ItemsPerContainer - 1] = containersItemValues[containerIds[i_source]];
                }
                else
                {
                    // sort the candidates by increasing distance
                    candidates = candidates.OrderBy(cc => cc.distance).ToList();

                    // Now choose one candidate at random.
                    int i = 0;
                    if (DistanceType == DistanceTypes.Medium)
                    {
                        i = random.Next(0, candidates.Count);
                    }
                    else if (DistanceType == DistanceTypes.Short)
                    {
                        // i = random.Next( 0, 1 + random.Next(0,candidates.Count) );
                        i = random.Next(0, Math.Max(1, candidates.Count / 3));
                    }
                    else if (DistanceType == DistanceTypes.Long)
                    {
                        // i = random.Next( random.Next(0,candidates.Count), candidates.Count );
                        i = random.Next(2 * candidates.Count / 3, candidates.Count);
                    }

                    // Now move the original item to the chosen candidate.
                    CandidateContainer chosen = candidates[i];
                    Containers[chosen.row, chosen.column].items[ItemsPerContainer - 1] = containersItemValues[containerIds[i_source]];
                    AverageDistance += candidates[i].distance;
                    IncorrectContainersNumber++;
                }
            }

            AverageDistance /= IncorrectContainersNumber;
        }
コード例 #4
0
    void Start()
    {
        ic = CandidateContainer.Load(path);

        while (true)
        {
            randCandidateA = findValidCandidate("A");
            if (randCandidateA != -1)
            {
                availableCandidates[randCandidateA] = -1;
                randAMoral = ic.candidates[randCandidateA].moral;
                break;
            }
        }
        while (true)
        {
            randCandidateB = findValidCandidate("B");
            if (randCandidateB != -1)
            {
                availableCandidates[randCandidateB] = -1;
                break;
            }
        }

        GameObject player = GameObject.Find("Player");

        CandidateAssociations cAssociations = FindObjectOfType <CandidateAssociations>();

        Vector3[] townSpawn = { new Vector3(-105.9f, -220.2f, 0), new Vector3(-109, -194.4f, 0), new Vector3(-102.8f, -162.2f, 0), new Vector3(-90, -194, 0), new Vector3(-77.2f, -210, 0), new Vector3(-70.6f, -191, 0), new Vector3(-61.5f, -200.5f, 0), new Vector3(-48.2f, -162, 0), new Vector3(-32, -213, 0), new Vector3(-23, -181.2f, 0), new Vector3(-19.7f, -162.4f, 0) };
        cAssociations.locations.Add(new Locations.Location(new Vector3(-48, -220, 0), "Town Square", townSpawn));

        foreach (CandidateXML candidate in ic.candidates)
        {
            if (candidate.id.Equals(randCandidateA.ToString()))
            {
                candidateA = transform.Find("First Candidate Profile");

                try {
                    candidateAController           = candidateA.GetComponent <CandidateAController>();
                    candidateAController.sprite    = sprites[randCandidateA];
                    candidateAController.fullname  = candidate.fullname;
                    cAssociations.CandidateAName   = candidate.fullname.Split(' ')[0];
                    candidateAController.moral     = candidate.moral;
                    candidateAController.goodArray = candidate.goodArray;
                    candidateAController.badArray  = candidate.badArray;
                    candidateAController.houseSize = candidate.houseSize;
                    Locations locations = player.GetComponent <Locations>();
                    for (int i = 0; i < locations.locations.Count; i++)
                    {
                        Locations.Location loco = (Locations.Location)locations.locations[i];
                        if (candidateAController.houseSize.Equals(loco.size))
                        {
                            cAssociations.houseA = loco;
                            cAssociations.locations.Add(loco);
                            locations.locations.RemoveAt(i);
                            break;
                        }
                    }
                    cAssociations.npcNameA = candidate.npcName;
                    cAssociations.itemNamesA.Add(candidate.itemName1);
                    cAssociations.itemNamesA.Add(candidate.itemName2);
                    candidateAController.birthdate   = candidate.birthdate;
                    candidateAController.ethnicity   = candidate.ethnicity;
                    candidateAController.occupation  = candidate.occupation;
                    candidateAController.skills      = candidate.skills;
                    candidateAController.description = candidate.description;
                    candidateAController.traits      = candidate.traits;
                } catch (NullReferenceException) {
                    print("stupid exception");
                }
            }
            else if (candidate.id.Equals(randCandidateB.ToString()))
            {
                candidateB = transform.Find("Second Candidate Profile");

                try {
                    candidateBController           = candidateB.GetComponent <CandidateBController>();
                    candidateBController.sprite    = sprites[randCandidateB];
                    candidateBController.fullname  = candidate.fullname;
                    cAssociations.CandidateBName   = candidate.fullname.Split(' ')[0];
                    candidateBController.moral     = candidate.moral;
                    candidateBController.goodArray = candidate.goodArray;
                    candidateBController.badArray  = candidate.badArray;
                    candidateBController.houseSize = candidate.houseSize;
                    Locations locations = player.GetComponent <Locations>();
                    for (int i = 0; i < locations.locations.Count; i++)
                    {
                        Locations.Location loco = (Locations.Location)locations.locations[i];
                        if (candidateBController.houseSize.Equals(loco.size))
                        {
                            cAssociations.houseB = loco;
                            cAssociations.locations.Add(loco);
                            locations.locations.RemoveAt(i);
                            break;
                        }
                    }
                    cAssociations.npcNameB = candidate.npcName;
                    cAssociations.itemNamesB.Add(candidate.itemName1);
                    cAssociations.itemNamesB.Add(candidate.itemName2);
                    candidateBController.birthdate   = candidate.birthdate;
                    candidateBController.ethnicity   = candidate.ethnicity;
                    candidateBController.occupation  = candidate.occupation;
                    candidateBController.skills      = candidate.skills;
                    candidateBController.description = candidate.description;
                    candidateBController.traits      = candidate.traits;
                } catch (NullReferenceException) {
                    print("stupid exception");
                }
            }
        }

        FindObjectOfType <ObjectSpawning>().spawnItems();
    }