public override List <AvailableMove> GetValidMoves() { List <AvailableMove> moveable = new List <AvailableMove>(); List <AvailableMove> moves = new List <AvailableMove>(); GetPawnAttack(moveable); if (!Board.instance.selectedPiece.wasMoved) { UntilBlockedPath(moves, direction, false, 2); if (moves.Count == 2) { moves[1] = new AvailableMove(moves[1].pos, MoveType.PawnDoubleMove); } } else { UntilBlockedPath(moves, direction, false, 1); if (moves.Count > 0) { moves[0] = CheckPromotion(moves[0]); } } moveable.AddRange(moves); return(moveable); }
public static void MovePiece(TaskCompletionSource <bool> tcs, bool skipMovement, MoveType moveType) { changes = new List <AffectedPiece>(); enPassantFlag = new AvailableMove(); switch (moveType) { case MoveType.Normal: NormalMove(tcs, skipMovement); break; case MoveType.Casting: Castling(tcs, skipMovement); break; case MoveType.PawnDoubleMove: PawnDoubleMove(tcs, skipMovement); break; case MoveType.EnPassant: EnPassant(tcs, skipMovement); break; case MoveType.Promotion: Promotion(tcs, skipMovement); break; } }
AvailableMove CheckPromotion(AvailableMove availableMove) { if (availableMove.pos.y != promotionHeight) { return(availableMove); } return(new AvailableMove(availableMove.pos, MoveType.Promotion)); }
static void PawnDoubleMove(TaskCompletionSource <bool> tcs, bool skipMovement) { Piece pawn = Board.instance.selectedPiece; Vector2Int direction = pawn.maxTeam ? new Vector2Int(0, 1) : new Vector2Int(0, -1); enPassantFlag = new AvailableMove(pawn.tile.pos + direction, MoveType.EnPassant); NormalMove(tcs, skipMovement); }
public async Task <Ply> CalculatePlays() { lastInterval = Time.realtimeSinceStartup; int minimaxDirection; if (StateMachineController.instance.currentlyPlaying == StateMachineController.instance.player1) { minimaxDirection = 1; } else { minimaxDirection = -1; } enPassantSaved = PieceMovementState.enPassantFlag; Ply currentPly = new Ply(); calculationCount = 0; currentPly.originPly = null; int currentPlyDepth = 0; currentPly.changes = new List <AffectedPiece>(); Debug.Log("Começo"); Task <Ply> calculation = CalculatePly(currentPly, -1000000, 1000000, currentPlyDepth, minimaxDirection); await calculation; currentPly.bestFuture = calculation.Result; Debug.Log("Calculations: " + calculationCount); Debug.Log("Time: " + (Time.realtimeSinceStartup - lastInterval)); PrintBestPly(currentPly.bestFuture); PieceMovementState.enPassantFlag = enPassantSaved; return(currentPly.bestFuture); }