예제 #1
0
        protected Dictionary <FaceMap, long> ProcessCrossProduct(Dictionary <FaceMap, long> startingPool, Dictionary <FaceMap, long> additionalPool)
        {
            if (startingPool.Count == 0)
            {
                return(additionalPool);
            }

            Dictionary <FaceMap, long> bulkPool = new Dictionary <FaceMap, long>();

            foreach (FaceMap startingMap in startingPool.Keys)
            {
                foreach (FaceMap addingMap in additionalPool.Keys)
                {
                    FaceMap node = startingMap.Merge(addingMap);
                    long    combinedFrequency = startingPool[startingMap] * additionalPool[addingMap];

                    try
                    {
                        bulkPool[node] = bulkPool[node] + combinedFrequency;
                    }
                    catch
                    {
                        bulkPool.Add(node, combinedFrequency);
                    }
                }
            }

            return(bulkPool);
        }
예제 #2
0
        /// <summary>
        /// Searches a pool of dice for a specific outcome and returns the number of rolls of that outcome
        /// </summary>
        /// <param name="outcomePool"></param>
        /// <param name="requiredQuery"></param>
        /// <returns></returns>
        protected long ProcessBreakdownPool(Dictionary <FaceMap, long> outcomePool, FaceMap requiredQuery)
        {
            //todo: This needs to be reconfigured to have a the ability to search for more than one field at a time
            string format = "| {0,9:#0} | {1,11} | {2}";

            Console.Write(string.Format("{0} ", requiredQuery.ToString()));

            //initialize the frequency for this requirement and the threshold for match
            long frequency       = 0;
            int  searchThreshold = requiredQuery.faces.Sum(x => x.Value);

            //expand the search to include the superior versions of the requirement
            if (requiredQuery.faces.ContainsKey(Face.advantage))
            {
                //requiredQuery.faces.Add(Face.triumph, requiredQuery.faces[Face.advantage]);
            }
            else if (requiredQuery.faces.ContainsKey(Face.success))
            {
                //requiredQuery.faces.Add(Face.advantage, requiredQuery.faces[Face.success]);
                requiredQuery.faces.Add(Face.triumph, requiredQuery.faces[Face.success]);
            }

            if (requiredQuery.faces.ContainsKey(Face.threat))
            {
                //requiredQuery.faces.Add(Face.dispair, requiredQuery.faces[Face.threat]);
            }
            else if (requiredQuery.faces.ContainsKey(Face.failure))
            {
                //requiredQuery.faces.Add(Face.threat, requiredQuery.faces[Face.failure]);
                requiredQuery.faces.Add(Face.despair, requiredQuery.faces[Face.failure]);
            }

            //loop through the simple pool to find matches
            foreach (FaceMap map in outcomePool.Keys)
            {
                int threshold = 0;

                foreach (Face face in requiredQuery.faces.Keys)
                {
                    //if it finds a matching key increase the threshold
                    if (map.faces.ContainsKey(face))
                    {
                        threshold += map.faces[face];
                    }
                }

                //if the found threshold is the same as the required threshold add the frequency and display the roll result
                if (threshold == searchThreshold)
                {
                    frequency += outcomePool[map];
                    //Console.WriteLine(string.Format(format, outcomePool[map], (outcomePool[map] / totalCount).ToString("#0.0%"), map.ToString()));
                }
            }

            Console.WriteLine(string.Format("Total {0:n0} ({1}) ", frequency, (frequency / totalCount).ToString("#0.000%")));

            return(frequency);
        }
예제 #3
0
        public HttpResponseMessage GetFace(string clientIp)
        {
            if (String.IsNullOrEmpty(clientIp))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            HttpResponseMessage response     = new HttpResponseMessage(HttpStatusCode.OK);
            MemoryStream        memoryStream = new MemoryStream();

            FaceMap.GetResult(clientIp).Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            response.Content = new StreamContent(memoryStream);
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = "face.jpg";
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

            return(response);
        }
예제 #4
0
        public static FaceMap Make(short map)
        {
            FaceMap newMap = new FaceMap {
                Map = new Vector3[4]
            };

            map <<= 1;

            for (int i = 0; i < 4; i++)
            {
                float x = ((map >>= 1) & 0x1) == 0x1 ? 1.0f : 0.0f;
                float y = ((map >>= 1) & 0x1) == 0x1 ? 1.0f : 0.0f;
                float z = ((map >>= 1) & 0x1) == 0x1 ? 1.0f : 0.0f;

                newMap.Map[i] = new Vector3(x, y, z);
            }

            return(newMap);
        }
예제 #5
0
        public async Task <IHttpActionResult> Upload()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            foreach (var file in provider.Contents)
            {
                var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
                var buffer   = await file.ReadAsByteArrayAsync();

                Bitmap inputBitmap;

                using (var ms = new MemoryStream(buffer))
                {
                    inputBitmap = new Bitmap(ms);
                    IEnumerable <string> headerValues = Request.Headers.GetValues("MyCustomID");
                    var            id        = "aa";
                    string         clientIp  = Request.Headers.Referrer.Authority;
                    FaceCacheModel cacheItem = new FaceCacheModel();
                    cacheItem.Image     = new Image <Bgr, byte>(inputBitmap);
                    cacheItem.GrayImage = cacheItem.Image.Convert <Gray, byte>();
                    try
                    {
                        cacheItem.Model = Labrator.GetFaceModel(cacheItem.Image, cacheItem.GrayImage);
                        FaceMap.Add(clientIp, cacheItem);
                        Bitmap result = Labrator.Process(cacheItem);
                        FaceMap.SetResult(clientIp, result);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("");
                    }
                }
            }
            return(Ok());
        }
예제 #6
0
        void addBrickFace(string face, byte block, int x, int y, int z)
        {
            int     vertexIndex = vertices.Count;
            FaceMap faceMap     = WorldBehaviour.meshMap[face];
            Color   color;

            switch (face)
            {
            case "top":
                color = topColor;
                break;

            case "bottom":
                color = bottomColor;
                break;

            case "front":
            case "back":
                color = firstSideColor;
                break;

            case "left":
            case "right":
                color = secondSideColor;
                break;

            default:
                throw new System.Exception("wrong face name: " + face);
            }

            // temporal | testing
            Vector2 xt = new Vector2(0, 0);
            Vector2 zt = new Vector2(0, 0);

            foreach (Vector3 vertice in faceMap.vertices)
            {
                if (vertice.x > xt.x)
                {
                    xt.x = vertice.x;
                }
                else if (vertice.x < xt.y)
                {
                    xt.y = vertice.x;
                }
                if (vertice.z > zt.x)
                {
                    zt.x = vertice.z;
                }
                else if (vertice.x < zt.y)
                {
                    zt.y = vertice.z;
                }
            }

            foreach (Vector3 vertice in faceMap.vertices)
            {
                Vector3 pos = new Vector3(
                    vertice.x + (x * Server.brickWidth),
                    vertice.y + (y * Server.brickHeight),
                    vertice.z + (z * Server.brickWidth)
                    );
                vertices.Add(pos);
                colors.Add(color);

                // temporal | testing | dunno what im doing here
                if (face == "top" || face == "bottom")
                {
                    Rect coords = BlockUVs.GetUVFromTypeAndFace((BlockType)block, face == "top" ? BlockFace.Top : BlockFace.Bottom);

                    float yMax = coords.y + coords.height;
                    float xMax = coords.x + coords.width;
                    float xMin = coords.x;
                    float yMin = coords.y;
                    uvs.Add(new Vector2(vertice.x < xt.x ? xMin : xMax, vertice.z < zt.x ? yMin : yMax));
                }
            }
            if (face != "top" && face != "bottom")
            {
                Rect coords = BlockUVs.GetUVFromTypeAndFace((BlockType)block, BlockFace.Side);

                float yMax = coords.y + coords.height;
                float xMax = coords.x + coords.width;
                float xMin = coords.x;
                float yMin = coords.y;

                uvs.Add(new Vector2(xMin, yMin));
                uvs.Add(new Vector2(xMin, yMax));
                uvs.Add(new Vector2(xMax, yMax));
                uvs.Add(new Vector2(xMax, yMin));
            }
            foreach (int index in faceMap.triangles)
            {
                triangles.Add(index + vertexIndex);
            }

            // Mesh collider, it is way more simple than the normal mesh, as it hasn't the studs
            vertexIndex = colliderVertices.Count;
            FaceMap colliderFaceMap = WorldBehaviour.colliderMeshMap[face];

            foreach (Vector3 vertice in colliderFaceMap.vertices)
            {
                Vector3 pos = new Vector3(
                    vertice.x + (x * Server.brickWidth),
                    vertice.y + (y * Server.brickHeight),
                    vertice.z + (z * Server.brickWidth)
                    );
                colliderVertices.Add(pos);
            }
            foreach (int index in colliderFaceMap.triangles)
            {
                colliderTriangles.Add(index + vertexIndex);
            }
        }
예제 #7
0
        protected Dictionary <FaceMap, long> ProcessPartialDicePool(List <Die> partialDicePool)
        {
            int[] indexTracker = new int[partialDicePool.Count];
            for (int i = 0; i < partialDicePool.Count; i++)
            {
                indexTracker[i] = 0;
            }

            Dictionary <FaceMap, long> bulkPool = new Dictionary <FaceMap, long>();

            while (indexTracker[partialDicePool.Count - 1] < partialDicePool[partialDicePool.Count - 1].faceMaps.Count)
            {
                for (int i = 0; i < partialDicePool[0].faceMaps.Count; i++)
                {
                    //add the zero index to the mix
                    FaceMap node = partialDicePool[0].faceMaps[i];

                    for (int j = 1; j < partialDicePool.Count; j++)
                    {
                        node = node.Merge(partialDicePool[j].faceMaps[indexTracker[j]]);
                    }

                    //add the node to the mix
                    if (node.faces.Count > 0)
                    {
                        try
                        {
                            bulkPool[node] = bulkPool[node] + 1;
                        }
                        catch
                        {
                            bulkPool.Add(node, 1);
                        }
                    }
                }

                //manually update the next index
                if (partialDicePool.Count > 1)
                {
                    indexTracker[1]++;
                }
                else
                {
                    indexTracker[0] = partialDicePool[0].faceMaps.Count;
                }

                //update the indexes
                for (int i = 1; i < partialDicePool.Count; i++)
                {
                    if (indexTracker[i] >= partialDicePool[i].faceMaps.Count)
                    {
                        if (i < partialDicePool.Count - 1)
                        {
                            indexTracker[i] = 0;
                            indexTracker[i + 1]++;
                        }
                    }
                }
            }

            return(bulkPool);
        }