public void OnMouseDown() { if (Game.Controller.die.rolling || Game.Controller.GetCurrentPlayer() != Owner || Game.Controller.GetCurrentPlayer().IsAI) { return; } // allow for a king to delegate one piece to a bishop each turn if (GetDivision() == "M" && !GetCommander().Moved&& type != "king") { Owner.Selected = this; Owner.SelectedDivision = GetDivision(); Game.Controller.commandDelegation.gameObject.SetActive(true); } else { Game.Controller.commandDelegation.gameObject.SetActive(false); } SpriteRenderer.sortingOrder = 1; dragging = true; Game.Controller.uiManager.DisableAttack(); if (Game.Controller.GetCurrentPlayer() == Owner) { MovementUtil.DestroyMovePlates(); InitiateMovePlates(); } }
/// <summary> /// For step or outline movement /// </summary> /// <returns></returns> private List <LineSegment> GetEmptySegments() { var items = base.GetDataCollection(); double accelebration = GlobalModel.Params.LayerConfig.ProcessAcceleratedSpeed; return(MovementUtil.GetLineSegments(items, this.layerPara.CutSpeed, accelebration)); }
//Swaps the current turn of the game public void IncrementTurnCounter() { movingPiece = false; ModifyEvalBar(); // player reaches move limit if (turnCounter >= _currentPlayer.RemainingMoves) { // change for current player before switching MovementUtil.DestroyMovePlates(); _currentPlayer.Disable(); AIMoves = null; _currentPlayer = _currentPlayer == Player1 ? Player2 : Player1; turnCounter = 0; totalTurns++; uiManager.InsertMoveRecord(totalTurns + ". " + (_currentPlayer.Name == "player1" ? "Player 1" : "Player 2"), true, Color.white); Text moveText = _currentPlayer == Player1 ? uiManager.whiteMoves : uiManager.blackMoves; moveText.text = "1/" + (_currentPlayer.RemainingMoves + 1); //reset all bools used to keep track of squadron selection _currentPlayer.Reset(); commandDelegation.Reset(); commandDelegation.gameObject.SetActive(false); } // increment turn counter and set ui else { turnCounter++; Text moveText = _currentPlayer == Player1 ? uiManager.whiteMoves : uiManager.blackMoves; moveText.text = (turnCounter + 1) + "/" + (_currentPlayer.RemainingMoves + 1); } RequestAI(); }
// Create moveplates for possible moves private void InitiateMovePlates() { List <Square> moves = MovementUtil.GetPossibleMoves(ChessGrid.Pieces, this); foreach (Square m in moves) { MovePlate.Spawn(Position, m, m.AttackOnly, Game.Controller); } }
public void MoveTo(PointF point, double speed, double acceleration, CancellationToken token, Action <MotorInfoMap <double>, MotorInfoMap <double> > infoHandler) { var posInfo = this.Motor.CurrentPosInfo; var p1 = new PointF((float)posInfo[AxisTypes.AxisX], (float)posInfo[AxisTypes.AxisY]); var p2 = point; var lines = MovementUtil.GetLineSegments(p1, p2, speed, acceleration); this.Motor.MoveAsync(lines, token, infoHandler).Wait(); }
public override void Intialize(out List <LineSegment> segments, double speed, CancellationToken token) { var items = base.GetDataCollection(); double accelebration = GlobalModel.Params.LayerConfig.EmptyMoveAcceleratedSpeed; if (double.IsNaN(speed)) { speed = GlobalModel.Params.LayerConfig.EmptyMoveSpeed; } segments = MovementUtil.GetLineSegments(items, speed, accelebration); }
protected override void OnUpdate() { float dt = Time.deltaTime; foreach (var e in GetEntities <Ship>()) { var movement = e.movement; var transform = e.transform; transform.position = MovementUtil.Move(transform.position, transform.forward, movement.speed, Time.deltaTime, movement.bottomBound, movement.topBound); } }
public static List <Square> GetPossibleMoves(Dictionary <Square, AiChessPiece> board, AiChessPiece piece, bool updateStrength, float[,] strength) { string owner = piece.Owner.Name; int direction = owner == "player1" ? 1 : -1; List <Square> possibleMoves = null; switch (piece.Type) { case "pawn": case "bishop": { possibleMoves = InfantryMoves(piece.Position, direction, updateStrength, strength); break; } case "king": case "queen": { possibleMoves = RoyaltyMoves(board, piece.Position, 3, owner, updateStrength, strength); break; } case "knight": { possibleMoves = RoyaltyMoves(board, piece.Position, 4, owner, updateStrength, strength); break; } case "rook": { possibleMoves = ArcherMoves(board, piece.Position, owner, updateStrength, strength); break; } } List <Square> cleaned = new List <Square>(); List <Square> surrounding = MovementUtil.SurroundingSquares(piece.Position); foreach (Square s in possibleMoves.Where(s => ChessGrid.ValidPosition(s))) { if (board.ContainsKey(s)) { if (piece.Type != "knight" && !s.AttackOnly && !surrounding.Contains(s)) { // remove this if statement if we want pieces to be able to attack any squares they can reach continue; } AiChessPiece target = board[s]; if (target.Owner == piece.Owner) { continue; } } cleaned.Add(s); } return(cleaned); }
public override void Intialize(out List <LineSegment> segments, double speed, CancellationToken token) { var items = base.GetDataCollection(); double accelebration = GlobalModel.Params.LayerConfig.ProcessAcceleratedSpeed; if (double.IsNaN(speed)) { speed = this.layerPara.CoolingSpeed; } segments = MovementUtil.GetLineSegments(items, speed, accelebration); //Fllow logic, case: EmptyMove }
protected override void OnUpdate() { for (int i = 0; i < enemies.Length; i++) { Position position = enemies.positions[i]; Rotation rotation = enemies.rotations[i]; MoveSpeed speed = enemies.moveSpeeds[i]; ShipData shipData = enemies.shipData[i]; position.Value = MovementUtil.Move(position.Value, math.forward(rotation.Value), speed.speed, Time.deltaTime, shipData.bottomBound, shipData.topBound); enemies.positions[i] = position; } }
// Movement for the Rook and its Attack range private static List <Square> ArcherMoves(Dictionary <Square, AiChessPiece> board, Square start, string owner, bool updateStrength, float[,] strength) { int direction = owner == "player1" ? 1 : -1; List <Square> moves = MovementUtil.SurroundingSquares(start); foreach (Square s in moves) { if (!board.ContainsKey(s)) { continue; } AiChessPiece target = board[s]; if (target.Owner.Name != owner) { s.AttackOnly = true; } } for (int i = -3; i <= 3; i++) { for (int j = -3; j <= 3; j++) { if (i == 0 && j == 0) { continue; } Square s = new Square(start.X + i, start.Y + j); if (updateStrength && ChessGrid.ValidPosition(s)) { strength[s.X, s.Y] += direction * EvaluationValues.PieceStrength["rook"]; } if (!board.ContainsKey(s)) { continue; } AiChessPiece target = board[s]; if (target.Owner.Name != owner) { moves.Add(new Square(s.X, s.Y, true)); } } } return(moves); }
public override void Intialize(out List <LineSegment> segments, double speed, CancellationToken token) { var items = base.GetDataCollection(); double accelebration = GlobalModel.Params.LayerConfig.ProcessAcceleratedSpeed; if (double.IsNaN(speed)) { speed = this.layerPara.CutSpeed; } segments = MovementUtil.GetLineSegments(items, speed, accelebration); if (SystemContext.Hardware?.IsLaserOn == true) { int delay = (int)this.layerPara.LaserOpenDelay; token.WaitHandle.WaitOne(delay); } //Fllow logic, case: EmptyMove }
private static bool ValidatePath(Dictionary <Square, AiChessPiece> board, HashSet <Square> validMoves, Square current, Square final, int index, int depth, bool updateStrength, float[,] strength) { // NOTE: putting a debug statement in here will lag it a lot and crash unity, especially for knight movement if (Equals(current, final)) { return(true); } // if not the last, but we run into a piece on the way if (index >= depth || (index > 0 && board.ContainsKey(current))) { return(false); } if (index > 0 && !validMoves.Contains(current)) { return(false); } // get all surrounding squares List <Square> surroundings = MovementUtil.SurroundingSquares(current); int start = surroundings.IndexOf(new Square(current.X + Math.Sign(final.X - current.X), current.Y + Math.Sign(final.Y - current.Y))); // iterate over all of the surrounding squares. if one of them succeeds, the path is valid for (int i = 0; i < 5; i++) { if (i < 4) { if (ValidatePath(board, validMoves, surroundings[MovementUtil.WrapAround(start - i, surroundings.Count)], final, index + 1, depth, updateStrength, strength)) { return(true); } } if (ValidatePath(board, validMoves, surroundings[MovementUtil.WrapAround(start + i, surroundings.Count)], final, index + 1, depth, updateStrength, strength)) { return(true); } } // if every path failed, target is unreachable return(false); }
// Use this for initialization void Start() { stateMachine = new StateMachine(this.gameObject); //Find the patrol state from our component list and set it. var patrol = GetComponent<PatrolState>(); patrol.Target = Target; patrol.WayPoints = WayPoints; patrol.StateGameObject = this.gameObject; patrol.Start(); stateMachine.SetState( patrol ); //Just makes moving around easier: movement = new MovementUtil(); movement.ControlObject = this.gameObject; movement.MaxSpeed = 10.0f; patrol.movement = movement; }
void FixedUpdate() { Device = SteamVR_Controller.Input((int)TrackedOBJ.index); if (MovementMethod.BeginMovement(Device)) { Vector3 position = MovementMethod.RunMovement(PlayerHead, Hand, Player, Device); if (MovementUtil.IsValidMove(PlayerHead.transform.position, position)) { Player.transform.Translate(position); } } else { Vector3 position; if (MovementMethod.IdleMovement(Device, out position)) { if (MovementUtil.IsValidMove(PlayerHead.transform.position, position)) { Player.transform.Translate(position); } } } }
private List <LineSegment> GetCuttingSegments() { double startLen = 0; double startSpeed = 0; double stopLen = 0; double stopSpeed = 0; double normalSpeed = this.layerPara.CutSpeed; if (this.layerPara.IsSlowStart) { startSpeed = this.layerPara.SlowStartSpeed; if (startSpeed > 0) { startLen = this.layerPara.SlowStartDistance; } } if (this.layerPara.IsSlowStop) { stopSpeed = this.layerPara.SlowStopSpeed; if (stopSpeed > 0) { stopLen = this.layerPara.SlowStopDistance; } } var items = base.GetDataCollection(); var segments = new List <LineSegment>(); var spiltter = new DataSplitter(items, startLen, stopLen); double accelebration = GlobalModel.Params.LayerConfig.ProcessAcceleratedSpeed; if (spiltter.IsValid) { var part1 = spiltter.GetStartData(); if (part1.Any()) { var tmp = MovementUtil.GetLineSegments(part1, startSpeed, accelebration); if (tmp.Any()) { segments.AddRange(tmp); } } var part2 = spiltter.GetMiddleData(); if (part2.Any()) { segments.AddRange(MovementUtil.GetLineSegments(part2, normalSpeed, accelebration)); } var part3 = spiltter.GetEndData(); if (part3.Any()) { var tmp = MovementUtil.GetLineSegments(part3, stopSpeed, accelebration); if (tmp.Any()) { segments.AddRange(tmp); } } } else { segments.AddRange(MovementUtil.GetLineSegments(items, normalSpeed, accelebration)); } return(segments); }
public void Execute(ref Position position, [ReadOnly] ref Rotation rotation, [ReadOnly] ref MoveSpeed speed) { position.Value = MovementUtil.Move(position.Value, math.forward(rotation.Value), speed.speed, deltaTime, bottomBound, topBound); }
void Update() { transform.position = MovementUtil.Move(transform.position, transform.forward, speed, Time.deltaTime, bottomBound, topBound); }
public void Execute(int index, TransformAccess transform) { transform.position = MovementUtil.Move(transform.position, Vector3.forward, speed, deltaTime, bottomBound, topBound); }