コード例 #1
0
 public static List <AxialCoord> GetNeighbours(AxialCoord hex)
 {
     return(AxialDirections.Select(axialDirection =>
                                   new AxialCoord {
         Q = axialDirection.Q + hex.Q, R = axialDirection.R + hex.R
     }).ToList());
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: qazeh/advent17
        static int Solve2(string raw)
        {
            var input = Transform(raw);

            var lookup = new Dictionary <string, AxialCoord>();

            lookup["n"]  = AxialCoord.Right;
            lookup["ne"] = AxialCoord.DownRight;
            lookup["se"] = AxialCoord.DownLeft;
            lookup["s"]  = AxialCoord.Left;
            lookup["sw"] = AxialCoord.UpLeft;
            lookup["nw"] = AxialCoord.UpRight;

            var pos = new AxialCoord();
            int max = 0;

            foreach (var op in input)
            {
                pos += lookup[op];
                var dist = AxialCoord.Distance(pos, new AxialCoord());
                if (dist > max)
                {
                    max = dist;
                }
            }

            return(max);
        }
コード例 #3
0
        private void CreateBubblesInGrid()
        {
            var       boardSize        = _contexts.game.boardSize.Value;
            const int firstRowsCount   = 6;
            const int ceilingRowsCount = 4;
            var       ceilingCoords    = new HashSet <AxialCoord>();

            for (var r = 0; r < boardSize.y; r++)
            {
                var rOffset = r >> 1;
                for (var q = -rOffset; q < boardSize.x - rOffset; q++)
                {
                    if (boardSize.y - r <= firstRowsCount)
                    {
                        var axialCoord = new AxialCoord {
                            Q = q, R = r
                        };
                        BubbleCreatorService.CreateBoardBubble(axialCoord,
                                                               BubbleCreatorService.GenerateRandomBubbleNumber());
                    }

                    if (boardSize.y - r <= ceilingRowsCount)
                    {
                        ceilingCoords.Add(new AxialCoord {
                            Q = q, R = r
                        });
                    }
                }
            }

            _contexts.game.SetCeilingCoords(ceilingCoords);
        }
コード例 #4
0
        /// <summary>
        /// Calculates a walk distance between two hexes.
        /// </summary>
        public int Distance(AxialCoord from, AxialCoord to)
        {
            var current = AllPaths[from];

            Debug.Assert(current != null);
            return(current[to].Distance);
        }
コード例 #5
0
        public void PixelToHexTest()
        {
            AxialCoord h    = new AxialCoord(3, 4);
            Layout     flat = new Layout(Layout.flat, new Point(10.0, 15.0), new Point(35.0, 71.0));

            flat.PixelToHex(flat.HexToPixel(h)).Should().Be(h);
        }
コード例 #6
0
        public static CellInfo CreateCellInfo(AxialCoord coord)
        {
            var info = ScriptableObject.CreateInstance <CellInfo>();

            info.Coord = coord;
            return(info);
        }
コード例 #7
0
 public HexGridCell(AxialCoord axialCoord, TCellValue value)
 {
     AxialCoord = axialCoord;
     CubeCoord  = HexCoord.AxialToCube(axialCoord);
     Value      = value;
     CacheNeighbourCoords();
 }
コード例 #8
0
 public BoardSettings(int side)
 {
     this.side       = side;
     arraySize       = side * 2 - 1;
     cutThreshold    = side - 1;
     placementOffset = new AxialCoord(-cutThreshold, -cutThreshold);
 }
コード例 #9
0
        private void CreateInnerPart(AxialCoord coord)
        {
            var partObject = Instantiate(boardInnerPartPrefab, (coord + settings.placementOffset).ToWorld(), Quaternion.identity, boardContainer);

            partObject.name = $"Inner{coord}";
            partObject.transform.localPosition += new Vector3(0, Constants.boardOffsetY, 0);
        }
コード例 #10
0
ファイル: MergeSystem.cs プロジェクト: ahmetayrnc/BubblePopsC
        private List <AxialCoord> GetNeighboursWithBubbleNumber(AxialCoord testedBubbleCoord, int bubbleNumber)
        {
            var neighbourAxialCoords            = HexHelperService.GetNeighbours(testedBubbleCoord);
            var canBeMergedNeighbourAxialCoords = new List <AxialCoord>();

            foreach (var axialCoord in neighbourAxialCoords)
            {
                var arrayIndices = HexHelperService.GetArrayIndices(axialCoord);

                //bounds check
                if (arrayIndices.x >= _boardSize.x ||
                    arrayIndices.y >= _boardSize.y ||
                    arrayIndices.x < 0 ||
                    arrayIndices.y < 0)
                {
                    continue;
                }

                //null check
                if (_hexMap[arrayIndices.x, arrayIndices.y] == null)
                {
                    continue;
                }

                //number check
                if (_hexMap[arrayIndices.x, arrayIndices.y].bubbleNumber.Value != bubbleNumber)
                {
                    continue;
                }

                canBeMergedNeighbourAxialCoords.Add(axialCoord);
            }

            return(canBeMergedNeighbourAxialCoords);
        }
コード例 #11
0
        public void AxialAndOffsetEqual(int axialX, int axialY, int offsetX, int offsetY, bool expected)
        {
            var axial  = new AxialCoord(axialX, axialY);
            var offset = new OffsetCoord(offsetX, offsetY);

            Assert.True(axial == offset == expected);
        }
コード例 #12
0
        public void NeighborsVertexesAreEqual(
            [Random(-9999, 9999, 3)] int axialX,
            [Random(-9999, 9999, 3)] int axialY,
            [NUnit.Framework.Range(0, 5)] int vertexIndex,
            [Values(0, 1)] int neighborIndexOffset)
        {
            var axial               = new AxialCoord(axialX, axialY);
            var vertex              = new VertexCoord(axialX, axialY, vertexIndex);
            var neighborAxial       = axial.Neighbors[(vertexIndex - 1 + neighborIndexOffset + 6) % 6];
            var neighborVertexIndex = (vertexIndex + (2 - neighborIndexOffset * 4) + 6) % 6;
            var neighborVertexCoord = new VertexCoord(neighborAxial, neighborVertexIndex);

            Debug.Log(axial);
            Debug.Log(vertexIndex);
            Debug.Log(vertex);

            var strut = neighborIndexOffset.ToString();

            Debug.Log(neighborIndexOffset);
            Debug.Log(neighborAxial);
            Debug.Log(neighborVertexIndex);
            Debug.Log(neighborVertexCoord);

            Assert.True(vertex == neighborVertexCoord);
        }
コード例 #13
0
        public void GetRingWithWidthTest()
        {
            AxialCoord coord = new AxialCoord(0, 0);

            var ringCoords = coord.GetRingWithWidth(0, 3);

            ringCoords.Count().Should().Be(1 + 6 + 12);

            //ringCoords.Should().BeEquivalentTo(new AxialCoord[] { coord });

            //ringCoords = coord.GetRing(1);
            //ringCoords.Count().Should().Be(6);

            //ringCoords.Should().BeEquivalentTo(coord.GetNeighbors());

            //ringCoords = coord.GetRing(2);
            //ringCoords.Count().Should().Be(12);

            //ringCoords.Should().BeEquivalentTo(new AxialCoord[] { new AxialCoord(2, 0),
            //                                                      new AxialCoord(2, -2),
            //                                                      new AxialCoord(2, -1),
            //                                                      new AxialCoord(-2, 0),
            //                                                      new AxialCoord(-2, 1),
            //                                                      new AxialCoord(-2, 2),
            //                                                      new AxialCoord(-1, 2),
            //                                                      new AxialCoord(-1, -1),
            //                                                      new AxialCoord(1, -2),
            //                                                      new AxialCoord(1, 1),
            //                                                      new AxialCoord(0, 2),
            //                                                      new AxialCoord(0, -2),
            //                                                      });
        }
コード例 #14
0
ファイル: AI.cs プロジェクト: kr2068858/AbaloneUnity
 private bool CanChoose(int[,] data, AxialCoord start, CubeCoord chooseCoord, int howManyIsChosen, int index)
 {
     if (howManyIsChosen >= 2)
     {
         if (!IsInArea((start + (AxialCoord)chooseCoord).x, (start + (AxialCoord)chooseCoord).z))
         {
             return(false);
         }
         if (data[(start + (AxialCoord)chooseCoord).x, (start + (AxialCoord)chooseCoord).z] != index)
         {
             return(false);
         }
     }
     if (howManyIsChosen == 3)
     {
         if (!IsInArea((start + (AxialCoord)chooseCoord * 2).x, (start + (AxialCoord)chooseCoord * 2).z))
         {
             return(false);
         }
         if (data[(start + (AxialCoord)chooseCoord * 2).x, (start + (AxialCoord)chooseCoord * 2).z] != index)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #15
0
        public static GameEntity CreateBoardBubble(AxialCoord coord, int bubbleNumber)
        {
            var bubble = CreateBubble();

            bubble.AddAxialCoord(coord);
            bubble.AddBubbleNumber(bubbleNumber);
            return(bubble);
        }
コード例 #16
0
    public static void SetCell(this TileMap self, AxialCoord coord, string key)
    {
        var id = self.TileSet.FindTileByName(key);

        var offsetCoord = coord.ToOffsetCoord();

        self.SetCell(offsetCoord.col, offsetCoord.row, id);
    }
コード例 #17
0
        public void AxialToOffset(int q, int r, int expectedX, int expectedY)
        {
            var axial  = new AxialCoord(q, r);
            var offset = axial.ToOffset();

            Assert.AreEqual(expectedX, offset.X);
            Assert.AreEqual(expectedY, offset.Y);
        }
コード例 #18
0
 private UctAction(UctActionType type, int abilityId, int mobId, int targetId, AxialCoord coord)
 {
     Type      = type;
     AbilityId = abilityId;
     MobId     = mobId;
     TargetId  = targetId;
     Coord     = coord;
 }
コード例 #19
0
ファイル: MobInfo.cs プロジェクト: darthdeus/HexMage.NET
 public MobInfo(TeamColor team, int maxHp, int maxAp, int iniciative, IEnumerable <int> abilities)
 {
     Team       = team;
     MaxHp      = maxHp;
     MaxAp      = maxAp;
     Iniciative = iniciative;
     Abilities  = abilities.ToList();
     OrigCoord  = AxialCoord.Zero;
 }
コード例 #20
0
        public void AxialToCubeTest(int q, int r, int expectedX, int expectedY, int expectedZ)
        {
            var axial = new AxialCoord(q, r);
            var cube  = axial.ToCube();

            Assert.AreEqual(expectedX, cube.X);
            Assert.AreEqual(expectedY, cube.Y);
            Assert.AreEqual(expectedZ, cube.Z);
        }
コード例 #21
0
ファイル: BubbleView.cs プロジェクト: ahmetayrnc/BubblePopsC
        public void OnAxialCoord(GameEntity entity, AxialCoord hex)
        {
            transform.position = HexHelperService.HexToPoint(hex);

            if (entity.isGhost)
            {
                GhostBubbleAppear();
            }
        }
コード例 #22
0
        public static GameEntity CreateGhostBubble(AxialCoord coord)
        {
            var bubble = CreateBubble();

            bubble.isGhost = true;
            bubble.AddAxialCoord(coord);

            return(bubble);
        }
コード例 #23
0
        private static void FastMove(GameInstance game, int mobId, AxialCoord coord)
        {
            var mobInstance = game.State.MobInstances[mobId];

            int distance = game.Pathfinder.Distance(mobInstance.Coord, coord);

            game.State.ChangeMobAp(mobId, -distance);
            game.State.SetMobPosition(mobId, coord);
        }
コード例 #24
0
        /// <summary>
        /// Checks if a given coord is valid on the map.
        /// </summary>
        public bool IsValidCoord(AxialCoord c)
        {
            int a        = (c.X + c.Y);
            int distance = ((c.X < 0 ? -c.X : c.X)
                            + (a < 0 ? -a : a)
                            + (c.Y < 0 ? -c.Y : c.Y)) / 2;

            return(distance <= Game.Size);
        }
コード例 #25
0
        // TODO : handle invalid string
        public static GameData Parse(string boardString)
        {
            var gameData = new GameData();

            var lines     = boardString.Split('\n');
            var arraySize = 0;

            foreach (var line in lines)
            {
                if (line.Contains("="))
                {
                    // metadata
                    var splitted = line.Split('=');
                    var left     = splitted[0].Trim().ToLower();
                    var right    = splitted[1].Trim();

                    switch (left)
                    {
                    case "name":
                        gameData.name = right;
                        break;

                    case "size":
                        var side = int.Parse(right);
                        arraySize          = side * 2 - 1;
                        gameData.boardSide = side;
                        gameData.placement = new int[arraySize, arraySize];
                        break;

                    case "players":
                        gameData.players = right.Split(',');
                        break;
                    }
                }
                else
                {
                    // marble placement
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    var splitted = line.Split(' ');
                    foreach (var marble in splitted)
                    {
                        var trimmed  = marble.Trim();
                        var match    = playerMarbleNotation.Match(trimmed);
                        var player   = int.Parse(match.Groups[1].Value);
                        var position = AxialCoord.FromNotation(match.Groups[2].Value, arraySize);
                        Debug.Log(position);
                        gameData.SetAt(position, player);
                    }
                }
            }

            return(gameData);
        }
コード例 #26
0
ファイル: MapEditor.cs プロジェクト: darthdeus/HexMage.NET
 /// <summary>
 /// Changes the order of starting points such that the starting
 /// point under mouse cursor is moved to a given index.
 /// </summary>
 private void ReorderStartingPoint(Keys key, int index, AxialCoord mouseHex, List <AxialCoord> hoverList)
 {
     if (InputManager.Instance.IsKeyJustPressed(key))
     {
         var tmp = hoverList[index];
         var i   = hoverList.IndexOf(mouseHex);
         hoverList[index] = hoverList[i];
         hoverList[i]     = tmp;
     }
 }
コード例 #27
0
ファイル: Camera2D.cs プロジェクト: darthdeus/HexMage.NET
        public Vector2 HexToPixel(AxialCoord coord, float scale)
        {
            int row = coord.Y;
            int col = coord.X;

            var x = (int)(GuiConfig.GridSize * scale * (col + row / 2.0));
            var y = (int)(row * GuiConfig.HeightOffset * scale);

            return(new Vector2(x, y));
        }
コード例 #28
0
ファイル: EqualsTest.cs プロジェクト: daihaminkey/HexCoords
        public void DifferentTypeDifferentValueNotEqualTest(int cubeX, int cubeY, int cubeZ, int axialQ, int axialR, int offsetX, int offsetY)
        {
            var cube   = new CubeCoord(cubeX, cubeY, cubeZ);
            var axial  = new AxialCoord(axialQ, axialR);
            var offset = new OffsetCoord(offsetX, offsetY);

            Assert.AreNotEqual(cube, axial);
            Assert.AreNotEqual(cube, offset);
            Assert.AreNotEqual(axial, offset);
        }
コード例 #29
0
ファイル: AI.cs プロジェクト: kr2068858/AbaloneUnity
 public TheCase(AxialCoord target, int chooseDirection, int moveDirection, int howManyIsChosen, int howManyWillPush, Priority priority, bool opponentPush, bool pushOut)
 {
     this.target          = target;
     this.chooseDirection = chooseDirection;
     this.moveDirection   = moveDirection;
     this.howManyIsChosen = howManyIsChosen;
     this.howManyWillPush = howManyWillPush;
     this.priority        = priority;
     this.opponentPush    = opponentPush;
     this.pushOut         = pushOut;
 }
コード例 #30
0
ファイル: Cell.cs プロジェクト: sericaer/Fengj_godot
        public Cell(AxialCoord axialCoord, ITerrainDef def)
        {
            this.axialCoord = axialCoord;

            this.terrainType = def.type;
            this.terrainCode = def.code;
            this.detectType  = DetectType.UN_VISIBLE;

            this._components = new List <IComponent>();
            Intergrate();
        }
コード例 #31
0
ファイル: HexCoord.cs プロジェクト: rameshvarun/TheSixthSun
 public HexCoord(int q, int r)
 {
     coordinate = new AxialCoord(q,r);
 }
コード例 #32
0
ファイル: TerrainManager.cs プロジェクト: marshl/Scorch
    private void BuildNeighbourConnections()
    {
        HexTile.TILE_DIRECTION[] directions = (HexTile.TILE_DIRECTION[])Enum.GetValues( typeof( HexTile.TILE_DIRECTION ) );

        foreach ( HexTile tile in this.availableTiles )
        {
            foreach ( HexTile.TILE_DIRECTION dir in directions )
            {
                AxialCoord coord = new AxialCoord( tile.x, tile.y );
                coord = coord.AddDirection( dir );
                if ( this.IsValidDisplayableTile( coord.q, coord.r ) )
                {
                    tile.neighbourMap.Add( dir, this.GetTileAxial( coord ) );
                }
            }
        }
    }
コード例 #33
0
ファイル: TerrainManager.cs プロジェクト: marshl/Scorch
 public HexTile GetTileAxial( AxialCoord _c )
 {
     return this.GetDisplayableTile( _c.q, _c.r );
 }
コード例 #34
0
ファイル: HexCoord.cs プロジェクト: rameshvarun/TheSixthSun
 /// <summary>Construct a HexCoord object from Cube coordinates.</summary>
 public HexCoord(int x, int y, int z)
 {
     coordinate = new CubeCoord(x, y, z).toAxialCoord();
 }