Пример #1
0
    //TODO Move into HexHelp
    bool SurroundedHorzOrVert(int xIndex, int yIndex, int layerPos, HexType[,,] tiles)
    {
        bool leftAndRight = HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos, tiles) && HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos, tiles);
        bool topAndBottom = HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos, tiles) && HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos, tiles);

        return(leftAndRight || topAndBottom);
    }
Пример #2
0
        static Stratum.Response.MiningSubscribe MakeSubscribe(ReplicationData.Subscribe repl)
        {
            var nonce1   = HexHelp.DecodeHex(repl.extraNonce1);
            var nonce2sz = GoodNonce2SizeOrThrow(repl.nonce2sz);

            return(new Stratum.Response.MiningSubscribe("abcdef0123456789", nonce1, nonce2sz));
        }
Пример #3
0
    void GenerateBaseHexes()
    {
        int layerCount = iStats.layerStats.Count;

        for (int layerIndex = 0; layerIndex < layerCount; layerIndex++)
        {
            Vector2 point = HexHelp.GetCenter(rings);
            tiles[layerIndex, (int)point.y, (int)point.x] = HexType.Earth;
            for (int ring = 1; ring < rings; ring++)
            {
                point = HexHelp.MoveInDirection(point, HexDir.Up);
                for (int direction = 0; direction < 6; direction++)
                {
                    for (int distance = 0; distance < ring; distance++)
                    {
                        bool inThreshold = iStats.layerStats[layerIndex].GetAt((int)point.x, (int)point.y) > iStats.layerStats[layerIndex].threshold;
                        bool hasBelow    = HexHelp.CheckBelow((int)point.x, (int)point.y, layerIndex, tiles);
                        if ((layerIndex == 0 || hasBelow) && inThreshold)
                        {
                            tiles[layerIndex, (int)point.y, (int)point.x] = HexType.Earth;
                        }
                        point = HexHelp.MoveInDirection(point, (HexDir)direction);
                    }
                }
            }
        }
    }
Пример #4
0
 public void RemoveIfNoBottom(int layerPos, HexType[,,] tiles)
 {
     for (int yIndex = 0; yIndex < tiles.GetLength(1); yIndex += 1)
     {
         for (int xIndex = 0; xIndex < tiles.GetLength(2); xIndex += 1)
         {
             if (!HexHelp.CheckBelow(xIndex, yIndex, layerPos, tiles))
             {
                 if (tiles[layerPos, yIndex, xIndex] == HexType.StoneFoundation)
                 {
                     tiles[layerPos, yIndex, xIndex] = HexType.None;
                 }
                 else if (tiles[layerPos, yIndex, xIndex] == HexType.StoneConnectTemp)
                 {
                     if (SurroundedHorzOrVert(xIndex, yIndex, layerPos, tiles))
                     {
                         tiles[layerPos, yIndex, xIndex] = HexType.StoneFoundation;                            //TODO Fix this
                     }
                     else
                     {
                         tiles[layerPos, yIndex, xIndex] = HexType.None;
                     }
                 }
             }
             else if (tiles[layerPos, yIndex, xIndex] == HexType.StoneConnectTemp)
             {
                 tiles[layerPos, yIndex, xIndex] = HexType.StoneFoundation;
             }
         }
     }
 }
Пример #5
0
 public void UppercaseHexLettersAreBad()
 {
     for (var loop = 0; loop < 6; loop++)
     {
         var hex = (char)('A' + loop);
         Assert.Throws <BadParseException>(() => HexHelp.HexValue(hex));
     }
 }
Пример #6
0
 public void ConvertsLowercaseHexLetters()
 {
     for (var loop = 0; loop < 6; loop++)
     {
         var hex   = (char)('a' + loop);
         var value = HexHelp.HexValue(hex);
         Assert.Equal(10 + loop, value);
     }
 }
Пример #7
0
 public void ConvertsDigits()
 {
     for (var loop = 0; loop < 10; loop++)
     {
         var hex   = (char)('0' + loop);
         var value = HexHelp.HexValue(hex);
         Assert.Equal(loop, value);
     }
 }
Пример #8
0
    void AddSingleStair(int xIndex, int yIndex, int layerPos, HexType[,,] tiles)
    {
        if (tiles[layerPos, yIndex, xIndex] != HexType.None || layerPos % 2 == 1)
        {
            bool left     = HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos, tiles);
            bool right    = HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos, tiles);
            bool top      = HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos, tiles);
            bool bottom   = HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos, tiles);
            int  adjacent = 0;
            if (left)
            {
                adjacent++;
            }
            if (right)
            {
                adjacent++;
            }
            if (bottom)
            {
                adjacent++;
            }
            if (top)
            {
                adjacent++;
            }

            bool hasBelow = HexHelp.CheckBelow(xIndex, yIndex, layerPos, tiles);
            bool hasAbove = HexHelp.CheckAbove(xIndex, yIndex, layerPos, tiles);

            if (hasBelow && !hasAbove && adjacent == 1 && Random.value <= stairChance)
            {
                //
                if (top && HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs0;
                }

                else if (left && HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs90;
                }

                else if (bottom && HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs180;
                }

                else if (right && HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs270;
                }
            }
        }
    }
Пример #9
0
    GameObject GenerateSingleHex(int x, int y, float height, int prefabNum)
    {
        GameObject temp = (GameObject)GameObject.Instantiate(hexagonPrefabs[prefabNum]);

        temp.transform.parent        = closeHolder;
        temp.transform.localRotation = Quaternion.identity;
        Vector2 toVec3 = HexHelp.GetRelativePosition(new Vector2(y, x), rings);

        temp.transform.localPosition = new Vector3(toVec3.x, height, toVec3.y);
        return(temp);
    }
Пример #10
0
 public void GenerateHuts(int layerPos, HexType[,,] tiles)
 {
     for (int yIndex = 0; yIndex < tiles.GetLength(1); yIndex += 2)
     {
         for (int xIndex = 0; xIndex < tiles.GetLength(2); xIndex += 2)
         {
             tiles[layerPos, yIndex, xIndex] = HexType.None;
             if (Random.value <= baseHutGenChance && HexHelp.CheckBelow(xIndex, yIndex, layerPos, tiles))
             {
                 tiles[layerPos, yIndex, xIndex] = HexType.StoneFoundation;
             }
         }
     }
 }
Пример #11
0
        static Stratum.Notification.NewJob MakeJob(ReplicationData.Job repl)
        {
            var jobid        = "abcd";
            var cbHead       = HexHelp.DecodeHex(repl.cbHead);
            var cbTail       = HexHelp.DecodeHex(repl.cbTail);
            var parsedMerkle = DecodeMerkles(repl.merkles);
            var bver         = HexHelp.DecodeHex(repl.blockVersion);
            var ndiff        = HexHelp.DecodeHex(repl.networkDiff);
            var ntime        = HexHelp.DecodeHex(repl.networkTime);
            var res          = new Stratum.Notification.NewJob(jobid, bver, null, cbHead, cbTail, ndiff, ntime, true);

            HexHelp.DecodeInto(res.prevBlock.blob, repl.prevHash);
            res.merkles.AddRange(parsedMerkle);
            return(res);
        }
Пример #12
0
        static List <Mining.Merkle> DecodeMerkles(string[]?merkles)
        {
            var res = new List <Mining.Merkle>();

            if (null == merkles)
            {
                return(res);
            }
            for (var loop = 0; loop < merkles.Length; loop++)
            {
                var gen = new Mining.Merkle();
                HexHelp.DecodeInto(gen.blob, merkles[loop]);
                res.Add(gen);
            }
            return(res);
        }
Пример #13
0
 public void RemoveSingleHuts(int layerPos, HexType[,,] tiles)
 {
     if (!singleHutsAllowed)
     {
         for (int yIndex = 0; yIndex < tiles.GetLength(1); yIndex += 2)
         {
             for (int xIndex = 0; xIndex < tiles.GetLength(2); xIndex += 2)
             {
                 bool hasOneSurrounding = HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos, tiles) ||
                                          HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos, tiles) ||
                                          HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos, tiles) ||
                                          HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos, tiles);
                 if (!hasOneSurrounding)
                 {
                     tiles [layerPos, yIndex, xIndex] = HexType.None;
                 }
             }
         }
     }
 }
Пример #14
0
    public Vector3 GetLegitSpot(float heightIncrease, bool localOffset)
    {
        while (true)
        {
            int  randX         = Random.Range(0, tiles.GetLength(2));
            int  randY         = Random.Range(0, tiles.GetLength(1));
            int  randLayer     = Random.Range(0, tiles.GetLength(0) - 1);
            bool badFoundation = tiles[randLayer, randY, randX] == HexType.None ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs0 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs90 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs180 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs270;

            if (!badFoundation && !HexHelp.CheckAboveMinusHuts(randX, randY, randLayer, tiles))
            {
                Vector2 toVec3 = HexHelp.GetRelativePosition(new Vector2(randY, randX), rings);
                //
                float height = baseHeightStats.GetAt(randX, randY) - baseHeightStats.GetAvgHeight();
                height += 2 * Mathf.Min(iStats.layerStats.Count, randLayer + 1);
                height += 4 * Mathf.Max(0, randLayer + 1 - iStats.layerStats.Count);
                height += heightIncrease;

                Vector3 toReturn = Vector3.zero;
                if (localOffset)
                {
                    toReturn = new Vector3(toVec3.x, height, toVec3.y);
                }
                else
                {
                    GameObject marker = new GameObject();
                    marker.transform.parent        = transform;
                    marker.transform.localPosition = new Vector3(toVec3.x, height, toVec3.y);
                    toReturn = marker.transform.position;
                    GameObject.Destroy(marker);
                }


                return(toReturn);
            }
        }
    }
Пример #15
0
 public void FillHoles(int layerPos, HexType[,,] tiles)
 {
     for (int index = 0; index < 3; index += 1)
     {
         for (int yIndex = 1; yIndex < tiles.GetLength(1); yIndex += 2)
         {
             for (int xIndex = 1; xIndex < tiles.GetLength(2); xIndex += 2)
             {
                 bool left   = HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos, tiles);
                 bool right  = HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos, tiles);
                 bool top    = HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos, tiles);
                 bool bottom = HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos, tiles);
                 if (left && right && top && bottom)
                 {
                     tiles [layerPos, yIndex, xIndex] = HexType.StoneFoundation;
                 }
                 else if (left && right && top)
                 {
                     tiles [layerPos, yIndex, xIndex]     = HexType.StoneFoundation;
                     tiles [layerPos, yIndex - 1, xIndex] = HexType.StoneFoundation;
                 }
                 else if (left && right && bottom)
                 {
                     tiles [layerPos, yIndex, xIndex]     = HexType.StoneFoundation;
                     tiles [layerPos, yIndex + 1, xIndex] = HexType.StoneFoundation;
                 }
                 else if (left && top && bottom)
                 {
                     tiles [layerPos, yIndex, xIndex]     = HexType.StoneFoundation;
                     tiles [layerPos, yIndex, xIndex + 1] = HexType.StoneFoundation;
                 }
                 else if (right && top && bottom)
                 {
                     tiles [layerPos, yIndex, xIndex]     = HexType.StoneFoundation;
                     tiles [layerPos, yIndex, xIndex - 1] = HexType.StoneFoundation;
                 }
             }
         }
     }
 }
Пример #16
0
    public void DeleteFramesAndDoors(GameObject ceiling, int cityLayer, int layerPos, int yIndex, int xIndex, HexType[,,] tiles)
    {
        Vector2 point = new Vector2(xIndex, yIndex + 1);

        for (int direction = 0; direction < 6; direction++)
        {
            bool fromStairs = (cityLayer > 0) && HexHelp.CheckForStairs((int)point.x, (int)point.y, layerPos, tiles);
            if (Random.value <= openDoorChance || fromStairs)
            {
                GameObject.DestroyImmediate(ceiling.transform.Find(doorFrameNames[direction]).GetChild(0).gameObject);
            }


            //Delete frames if neighboring
            if (HexHelp.CheckDirRaw((int)point.x, (int)point.y, layerPos, tiles) && !HexHelp.CheckForStairs((int)point.x, (int)point.y, layerPos, tiles))
            {
                GameObject.Destroy(ceiling.transform.Find(doorFrameNames[direction]).gameObject);
            }

            point = HexHelp.MoveInDirection(point, (HexDir)direction);
        }
    }
Пример #17
0
 public void GenerateConnections(int layerPos, HexType[,,] tiles)
 {
     for (int yIndex = 0; yIndex < tiles.GetLength(1); yIndex += 1)
     {
         for (int xIndex = (yIndex + 1) % 2; xIndex < tiles.GetLength(2); xIndex += 2)
         {
             tiles[layerPos, yIndex, xIndex] = HexType.None;
             bool canConnect = SurroundedHorzOrVert(xIndex, yIndex, layerPos, tiles);
             bool hasBelow   = HexHelp.CheckBelow(xIndex, yIndex, layerPos, tiles);
             if (canConnect && (hasBelow || !connectionRequiresLower) && Random.value <= connectionChance)
             {
                 if (connectionRequiresLower)
                 {
                     tiles[layerPos, yIndex, xIndex] = HexType.StoneFoundation;
                 }
                 else
                 {
                     tiles[layerPos, yIndex, xIndex] = HexType.StoneConnectTemp;
                 }
             }
         }
     }
 }
Пример #18
0
    void DrawBaseHexes()
    {
        int numLayers = iStats.layerStats.Count;

        //numLayers = Mathf.Min (iStats.layerStats.Count, 3);
        for (int layer = 0; layer < numLayers; layer++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    HexType thisType = tiles[layer, y, x];
                    if (thisType == HexType.Earth)
                    {
                        bool emptyBelow = !HexHelp.CheckBelow(x, y, layer, tiles);
                        bool emptyAbove = !HexHelp.CheckAbove(x, y, layer, tiles);
                        int  prefabNum  = (int)HexDraw.middle;
                        if (emptyBelow && emptyAbove)
                        {
                            prefabNum = (int)HexDraw.both;
                        }
                        else if (emptyBelow && !emptyAbove)
                        {
                            prefabNum = (int)HexDraw.bottom;
                        }
                        else if (emptyAbove && !emptyBelow)
                        {
                            prefabNum = (int)HexDraw.top;
                        }

                        float height = 2 * layer + baseHeightStats.GetAt(x, y) - baseHeightStats.GetAvgHeight();
                        GenerateSingleHex(x, y, height, prefabNum);
                    }
                }
            }
        }
    }
Пример #19
0
 public void BytesComeInStringOrder(string hex, byte[] expected)
 {
     Assert.Equal(expected, HexHelp.DecodeHex(hex));
 }
Пример #20
0
 public void HexStringsMustHaveEvenLength(string hex)
 {
     Assert.Throws <BadParseException>(() => HexHelp.DecodeHex(hex));
 }
Пример #21
0
 public void HexStringCannotBeEmpty()
 {
     Assert.Throws <BadParseException>(() => HexHelp.DecodeHex(""));
 }