public static List <AxialCoord> GetNeighbours(AxialCoord hex) { return(AxialDirections.Select(axialDirection => new AxialCoord { Q = axialDirection.Q + hex.Q, R = axialDirection.R + hex.R }).ToList()); }
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); }
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); }
/// <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); }
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); }
public static CellInfo CreateCellInfo(AxialCoord coord) { var info = ScriptableObject.CreateInstance <CellInfo>(); info.Coord = coord; return(info); }
public HexGridCell(AxialCoord axialCoord, TCellValue value) { AxialCoord = axialCoord; CubeCoord = HexCoord.AxialToCube(axialCoord); Value = value; CacheNeighbourCoords(); }
public BoardSettings(int side) { this.side = side; arraySize = side * 2 - 1; cutThreshold = side - 1; placementOffset = new AxialCoord(-cutThreshold, -cutThreshold); }
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); }
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); }
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); }
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); }
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), // }); }
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); }
public static GameEntity CreateBoardBubble(AxialCoord coord, int bubbleNumber) { var bubble = CreateBubble(); bubble.AddAxialCoord(coord); bubble.AddBubbleNumber(bubbleNumber); return(bubble); }
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); }
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); }
private UctAction(UctActionType type, int abilityId, int mobId, int targetId, AxialCoord coord) { Type = type; AbilityId = abilityId; MobId = mobId; TargetId = targetId; Coord = coord; }
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; }
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); }
public void OnAxialCoord(GameEntity entity, AxialCoord hex) { transform.position = HexHelperService.HexToPoint(hex); if (entity.isGhost) { GhostBubbleAppear(); } }
public static GameEntity CreateGhostBubble(AxialCoord coord) { var bubble = CreateBubble(); bubble.isGhost = true; bubble.AddAxialCoord(coord); return(bubble); }
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); }
/// <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); }
// 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); }
/// <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; } }
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)); }
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); }
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; }
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(); }
public HexCoord(int q, int r) { coordinate = new AxialCoord(q,r); }
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 ) ); } } } }
public HexTile GetTileAxial( AxialCoord _c ) { return this.GetDisplayableTile( _c.q, _c.r ); }
/// <summary>Construct a HexCoord object from Cube coordinates.</summary> public HexCoord(int x, int y, int z) { coordinate = new CubeCoord(x, y, z).toAxialCoord(); }