public void HandleInput() { if (Input.GetMouseButtonDown(0)) { Place(BoardUtils.ScreenToBoardPosition(Input.mousePosition), GameData.CurrentBattle.CurrentPlayer.AvailableActors[addWarriors_index] as BattleActor); } }
private IEnumerator ClearAndCollapseRoutine(IEnumerable <GemBehaviour> matches) { var complete = false; while (!complete) { GridManager.ClearGems(matches); yield return(new WaitForSeconds(0.25f)); var movedGems = GridManager.CollapseColumns(matches); while (!BoardUtils.IsFallComplete(movedGems)) { yield return(null); } yield return(new WaitForSeconds(SequenceParameters.RefreshMatchCheckDelay)); matches = GridManager.FindMatchesAt(movedGems); if (!matches.Any()) { complete = true; } else { yield return(StartCoroutine(ClearAndCollapseRoutine(matches))); } } }
private void SetDirection(Direction direction) { currentDirection = direction; // Clear area foreach (Tile oldTile in area.AllTiles()) { oldTile.ResetDisplay(); } area.Clear(); // Set area if (direction == Direction.NONE) { return; } (int x, int y) = wide ? launcher.on.GetNeighborCoords(direction.Opposite()) : (launcher.on.x, launcher.on.y); foreach (Tile newTile in BoardUtils.AllTiles(t => { if (BoardUtils.DirectionTo(x, y, t) != direction) { return(false); } float distance = BoardUtils.DistanceBetween(launcher.on, constraint, t); return(minRange <= distance && distance <= maxRange); })) { var flow = new TileFlow(newTile, direction); area.Add(flow); flow.UpdateDisplay(2, Tile.TileColor.VALID); } }
private void AddSegmentSpaceRecursively(BeamSegment _segment, int exitSide) { // Do we have too many segments? Okay, stop; we're probably caught in an infinite-Beam Portal mirroring situation. if (NumSegments > 10) { return; } // Are we not allowed to EXIT this space? Then stop here. if (!BoardUtils.CanBeamExitSpace(GetSpace(_segment.LastColRow), exitSide)) { return; } // What space will we add it to? TranslationInfo ti = BoardUtils.GetTranslationInfo(mySource.BoardRef, _segment.LastColRow, exitSide); BoardSpace spaceToAddBeam = BoardUtils.GetSpace(BoardRef, ti.to); // If we can't ENTER the next space, then stop. :) int nextSideIn = MathUtils.GetSide(ti.dirIn); if (!BoardUtils.CanBeamEnterSpace(spaceToAddBeam, nextSideIn)) { return; } // Otherwise, add this space to the segment! _segment.AddSpace(spaceToAddBeam); // How is the beam exiting?? int endSideExiting = spaceToAddBeam.GetSideBeamExits(nextSideIn); // keep updaing endSideExiting (until we hit the end). // Otherwise, keep going! Add again! AddSegmentSpaceRecursively(_segment, endSideExiting); }
private void Update() { if (piece != null) { if (piece.Line != null) { isRoof = piece.Line.IsRoof; } if (piece.HoldConnections != null) { hold = piece.HoldConnections.Count; } if (piece.Connections != null) { normal = piece.Connections.Count; } } if (!IsMoving || !isUsing) { return; } transform.localPosition += mMovingDirection * SPEED; if (piece != null) { var lp = BoardUtils.GetLineAndPosition(transform.localPosition, mBoardView.board); mBoardView.gameView.gameEngine.UpdatePiecePosition(piece, lp.y, lp.x); } Predict(); }
private int calculateQuiescenceDepth(Board board, int depth) { if (depth == 1 && this.quiescenceCount < MAX_QUIESCENCE) { int activityMeasure = 0; if (board.getCurrentPlayer().isCheck()) { activityMeasure += 1; } foreach (Move move in BoardUtils.lastNMoves(board, 2)) { if (move.isAttack()) { activityMeasure += 1; } } if (activityMeasure >= 2) { this.quiescenceCount++; return(1); } } return(depth - 1); }
private void SmoothThePath(ref BoardCellDynamicArray rawTurns, ref BoardCellDynamicArray pathCells, ref BoardCellDynamicArray turns, List <int> turnDistances) { if (rawTurns.Length == 0) { Service.Logger.Error("SmoothThePath: Not expecting empty path!"); return; } pathCells.Add(rawTurns.Array[0]); turns.Add(rawTurns.Array[0]); turnDistances.Add(0); if (rawTurns.Length == 1) { return; } if (rawTurns.Length == 2) { this.AddTurn(rawTurns.Array[0], rawTurns.Array[1], ref pathCells, ref turns, turnDistances); return; } BoardCell boardCell = rawTurns.Array[0]; BoardCell boardCell2 = rawTurns.Array[1]; for (int i = 2; i < rawTurns.Length; i++) { BoardCell boardCell3 = rawTurns.Array[i]; if (!BoardUtils.HasLineOfClearance(this.board, boardCell.X, boardCell.Z, boardCell3.X, boardCell3.Z, this.TroopWidth)) { this.AddTurn(boardCell, boardCell2, ref pathCells, ref turns, turnDistances); boardCell = boardCell2; } boardCell2 = boardCell3; } this.AddTurn(boardCell, boardCell2, ref pathCells, ref turns, turnDistances); }
private void SmoothThePath(List <BoardCell <Entity> > rawTurns, List <BoardCell <Entity> > pathCells, List <BoardCell <Entity> > turns, List <int> turnDistances) { if (rawTurns.Count == 0) { Service.Get <StaRTSLogger>().Error("SmoothThePath: Not expecting empty path!"); return; } pathCells.Add(rawTurns[0]); turns.Add(rawTurns[0]); turnDistances.Add(0); if (rawTurns.Count == 1) { return; } if (rawTurns.Count == 2) { this.AddTurn(rawTurns[0], rawTurns[1], pathCells, turns, turnDistances); return; } BoardCell <Entity> boardCell = rawTurns[0]; BoardCell <Entity> boardCell2 = rawTurns[1]; for (int i = 2; i < rawTurns.Count; i++) { BoardCell <Entity> boardCell3 = rawTurns[i]; if (!BoardUtils.HasLineOfClearance(this.board, boardCell.X, boardCell.Z, boardCell3.X, boardCell3.Z, this.TroopWidth)) { this.AddTurn(boardCell, boardCell2, pathCells, turns, turnDistances); boardCell = boardCell2; } boardCell2 = boardCell3; } this.AddTurn(boardCell, boardCell2, pathCells, turns, turnDistances); }
private void OnlyGoLeft(Point localPosition) { if (localPosition.Y == 0) { return; } for (var y = (byte)(localPosition.Y - 1); y >= 0; y--) { var color = _board.GetColor(localPosition.X, y); if (BoardUtils.IsEmptyTile(localPosition.X, y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(localPosition.X, y)) { break; } localPosition.AdditionalScores++; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
private void OnlyGoDown(Point localPosition) { if (localPosition.X == _board.GetRows - 1) { return; } for (var x = (byte)(localPosition.X + 1); x < _board.GetRows; x++) { if (BoardUtils.IsEmptyTile(x, localPosition.Y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(x, localPosition.Y)) { break; } localPosition.AdditionalScores++; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
private void OnlyGoUp(Point localPosition) { if (localPosition.X == 0) { return; } for (var x = (byte)(localPosition.X - 1); x >= 0; x--) { if (BoardUtils.IsEmptyTile(x, localPosition.Y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(x, localPosition.Y)) { break; } localPosition.AdditionalScores++; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
private void OnlyGoDownAndRight(Point localPosition) { if (localPosition.Y == _board.GetColumns - 1 || localPosition.X == _board.GetRows - 1) { return; } byte y = (byte)(localPosition.Y + 1); byte x = (byte)(localPosition.X + 1); while (y < _board.GetColumns && x < _board.GetRows) { if (BoardUtils.IsEmptyTile(x, y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(x, y)) { break; } localPosition.AdditionalScores++; x++; y++; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
private void OnlyGoUpAndLeft(Point localPosition) { if (localPosition.Y == 0 || localPosition.X == 0) { return; } byte y = (byte)(localPosition.Y - 1); byte x = (byte)(localPosition.X - 1); while (y >= 0 && x >= 0) { if (BoardUtils.IsEmptyTile(x, y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(x, y)) { break; } localPosition.AdditionalScores++; x--; y--; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
private void OnlyGoRight(Point localPosition) { if (localPosition.Y == _board.GetColumns - 1) { return; } for (var y = (byte)(localPosition.Y + 1); y < _board.GetColumns; y++) { if (BoardUtils.IsEmptyTile(localPosition.X, y)) { localPosition.AdditionalScores = 0; return; } if (BoardUtils.IsMyColor(localPosition.X, y)) { break; } localPosition.AdditionalScores++; } localPosition.Scores += localPosition.AdditionalScores; localPosition.AdditionalScores = 0; }
/// <summary> /// Caclulate the king's legal moves /// </summary> /// <param name="board"></param> /// <returns></returns> public override ICollection <Move> calculateLegalMoves(Board board) { IList <Move> legalMoves = new List <Move>(); foreach (int currentCandidateOffset in CANDIDATE_MOVE_COORDINATES) { //Check for first column exclusion for the king if (isFirstColumnExclusion(this.piecePosition, currentCandidateOffset) || isEighthColumnExclusion(this.piecePosition, currentCandidateOffset)) { continue; } int candidateDestinationCoordinate = this.piecePosition + currentCandidateOffset; if (BoardUtils.IsValidTileCoordinate(candidateDestinationCoordinate)) { Tile candidateDestinationTile = board.getTile(candidateDestinationCoordinate); //If the destination tile is not occupied if (!candidateDestinationTile.isTileOccupied()) { legalMoves.Add(new MajorMove(board, this, candidateDestinationCoordinate)); } //If the destination tile is occupied else { Piece pieceAtDestination = candidateDestinationTile.getPiece(); Alliance pieceAlliance = pieceAtDestination.getPieceAlliance(); if (this.pieceAlliance != pieceAlliance) { legalMoves.Add(new MajorAttackMove(board, this, candidateDestinationCoordinate, pieceAtDestination)); } } } } return(legalMoves.ToList()); }
public void TestTransposition() { var input = "...b."; var tr = BoardUtils.Transpose(input); var output = ".,.,.,b,."; Assert.AreEqual(tr, output); }
public void TestTransposition2() { var input = "...b.,aa.de"; var tr = BoardUtils.Transpose(input); var output = ".a,.a,..,bd,.e"; Assert.AreEqual(tr, output); }
public void SetPosition(Vector2 position) { GameData.CurrentBattle.Board.SetObjectAt(null, Position); Position = position; GameObject.transform.position = BoardUtils.BoardToWorldPosition(position); GameData.CurrentBattle.Board.SetObjectAt(this, Position); }
// ---------------------------------------------------------------- // Makin' Moves // ---------------------------------------------------------------- private bool MayExecuteMove(Vector2Int dir) { if (IsEveryPlayerDead()) { return(false); } //if (AreGoalsSatisfied) { return false; } // We can't execute after we've won. return(BoardUtils.MayMovePlayers(this, players, dir)); // Ok, now just check if it's legal! }
public override void _Draw() { if (_board == null) { return; } BoardUtils.DrawTetrisGrid(this, _board, _cellWidth); }
public static Mesh GetPatternMesh(WarriorPattern pattern, PatternFlags flags, Vector2 position, bool inverted = false) { List <Vector2> locations = pattern.GetLocationsForFlags(flags, inverted); int sizeX = GameData.CurrentBattle.Board.Width; Vector3[] vertices = new Vector3[locations.Count * 4]; int[] triangles = new int[locations.Count * 6]; Vector2[] uv = new Vector2[vertices.Length]; position = BoardUtils.BoardToWorldPosition(position); int count = 0; foreach (Vector2 location in locations) { int x = ((int)position.x + (int)location.x); //TODO int y = ((int)position.y - (int)location.y); //TODO if (!BoardUtils.IsInsideBoard(new Vector2(x, y))) { continue; } int vX = count * 4; vertices[vX] = new Vector3(x, y); vertices[vX + 1] = new Vector3(x + 1, y); vertices[vX + 2] = new Vector3(x + 1, y + 1); vertices[vX + 3] = new Vector3(x, y + 1); int tX = count * 6; triangles[tX] = vX; triangles[tX + 1] = vX + 1; triangles[tX + 2] = vX + 2; triangles[tX + 3] = vX; triangles[tX + 4] = vX + 2; triangles[tX + 5] = vX + 3; //TODO varies depending on the X float xOffset = (flags & PatternFlags.Attack) == PatternFlags.Attack ? 0.5f : 0.75f; uv[vX] = new Vector2(xOffset, 0); uv[vX + 1] = new Vector2(xOffset + 0.25f, 0); uv[vX + 2] = new Vector2(xOffset + 0.25f, 1); uv[vX + 3] = new Vector2(xOffset, 1); count++; } Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.uv = uv; mesh.RecalculateNormals(); return(mesh); }
public override void _Draw() { if (_tetromino == null) { return; } var cellWidth = RectSize.x / _tetromino.Width; BoardUtils.DrawTetrisGrid(this, _tetromino, cellWidth); }
private bool InRangeOfTarget(BoardCell curCell) { if (curCell == this.destCell && this.minShooterRange == 0u) { return(true); } int x; int z; if (this.melee && this.destCell != null) { x = this.destCell.X; z = this.destCell.Z; } else { if (this.targetCell == null) { return(false); } x = this.targetCell.X; z = this.targetCell.Z; } int halfWidthForOffset = BoardUtils.GetHalfWidthForOffset(this.TroopWidth); int num = curCell.X + halfWidthForOffset; int num2 = curCell.Z + halfWidthForOffset; int num3 = num - x; int num4 = num3 + ((num3 <= 0) ? -1 : 1); int num5 = num2 - z; int num6 = num5 + ((num5 <= 0) ? -1 : 1); int num7 = num4 * num4 + num6 * num6; num7 = num7; int num8 = num3 * num3 + num5 * num5; num8 = num8; uint num9 = this.maxShooterRange * this.maxShooterRange; uint num10 = this.minShooterRange * this.minShooterRange; if (this.isHealer) { num7 += (int)(num9 / 2u); } else if (this.targetInRangeModifier > 0u) { num9 /= this.targetInRangeModifier; } if ((long)num7 < (long)((ulong)num9) && (long)num8 >= (long)((ulong)num10)) { BoardCell boardCell = BoardUtils.WhereDoesLineCrossFlag(Service.BoardController.Board, num, num2, x, z, 64u); return(boardCell == null); } return(false); }
public void TestBallRemovalFromArrayBySection6() { var arr = new List <int> { -4, 0, 1, 2, 2 }; BoardUtils.RemoveZeroAtSectionFromList(arr, 1); S(arr, new List <int> { -5, 1, 2, 2 }); }
public SkillArea SkillAreaIfTarget(Tile tile) { if (CanSelect(tile)) { return(new SkillArea(BoardUtils.AreaOf(tile, areaRange, areaConstraint).Select(t => new TileFlow(t)))); } else { return(null); } }
public void TestBallRemovalFromArrayBySection1() { var arr = new List <int> { 0, -1, 2, 2 }; BoardUtils.RemoveZeroAtSectionFromList(arr, 0); S(arr, new List <int> { -2, 2, 2 }); }
public void TestPushAdder4() { var arr = new List <int> { -5 }; BoardUtils.AddPushToListAt(arr, 2, 1); S(arr, new List <int> { -2, 1, -2 }); }
public void TestPushAdder5() { var arr = new List <int> { 2, -5 }; BoardUtils.AddPushToListAt(arr, 2, 2); S(arr, new List <int> { 2, -1, 2, -3 }); }
public void TestPushAdder8() { var arr = new List <int> { 2, -5 }; BoardUtils.AddPushToListAt(arr, 5, 2); S(arr, new List <int> { 2, -4, 2 }); }
public void TestPushAdder6() { var arr = new List <int> { 2, -5 }; BoardUtils.AddPushToListAt(arr, 0, 2); S(arr, new List <int> { 4, -5 }); }