//Checks whichs directions the current piece can move in. private void CheckAllDirections(List <IChessPiece> MyList, List <IChessPiece> EnemyList, IChessPiece Piece, List <MovementOptions> AllLegalMovesForThisPiece) { for (int direction = 0; direction < Piece.AllMoveOptionsForThisPiece.Count; direction++) { Piece.ClearMovementoptions(); Piece.MoveOption(Piece.teamDirection); CheckLengthInDirection(MyList, EnemyList, Piece, AllLegalMovesForThisPiece, direction); } }
//Chechs how far the current piece is allowed to move in the allowed directions. private void CheckLengthInDirection(List <IChessPiece> MyList, List <IChessPiece> EnemyList, IChessPiece Piece, List <MovementOptions> AllLegalMovesForThisPiece, int direction) { for (int walkingLength = 1; walkingLength <= Piece.AllMoveOptionsForThisPiece[direction].WalkingLength; walkingLength++) { var outOfBounds = false; var friendlyAhead = false; var enemyAhead = false; Piece.ClearMovementoptions(); Piece.MoveOption(Piece.teamDirection); int MovingPositionX = Piece.AllMoveOptionsForThisPiece[direction].PositionX * walkingLength; int MovingPositionY = Piece.AllMoveOptionsForThisPiece[direction].PositionY * walkingLength; int FuturePositionX = Piece.PositionX + MovingPositionX; int FuturePositionY = Piece.PositionY + MovingPositionY; outOfBounds = CheckIfOutOfBounds(FuturePositionX, FuturePositionY); friendlyAhead = CheckIfFriendlyAhead(FuturePositionX, FuturePositionY, MyList); enemyAhead = CheckIfEnemyAhead(FuturePositionX, FuturePositionY, EnemyList); walkingLength = GameRules.CheckIfLegalMove(Piece, AllLegalMovesForThisPiece, direction, walkingLength, outOfBounds, friendlyAhead, enemyAhead, FuturePositionX, FuturePositionY); } }