예제 #1
0
파일: BlackBishop.cs 프로젝트: vgichar/shah
 /// <summary>
 /// Checks if the piece might move on this "board", 
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         base.MightMove(board, from, to) &&
         Math.Abs(Board.File(from) - Board.File(to)) == Math.Abs(Board.Rank(from) - Board.Rank(to)) &&// it's a diagonal move
         board.IsPathClear(from, to);// the path is clear
 }
예제 #2
0
 /// <summary>
 /// Checks if the piece might move on this "board",
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         (base.MightMove(board, from, to) &&
          Math.Abs(Board.File(from) - Board.File(to)) == Math.Abs(Board.Rank(from) - Board.Rank(to)) && // it's a diagonal move
          board.IsPathClear(from, to));                                                                 // the path is clear
 }
예제 #3
0
파일: WhiteKing.cs 프로젝트: vgichar/shah
 /// <summary>
 /// Verifies if the king can castle short.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public bool CanCastleShort(Board board, int from, int to)
 {
     return (
         from == Board.E1 && to == Board.G1 &&
         board.Status.WhiteCouldCastleShort &&//check if the king or the rook didn't already move 
         board.IsPathClear(Board.E1, Board.H1) &&// check if the path is clear 
         !board.IsAttackedByBlack(Board.E1) && !board.IsAttackedByBlack(Board.F1) && !board.IsAttackedByBlack(Board.G1)// check if the squares traversed by king are not attacked
         );
 }
예제 #4
0
 /// <summary>
 /// Verifies if the king can castle short.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public bool CanCastleShort(Board board, int from, int to)
 {
     return(
         from == Board.E8 && to == Board.G8 &&
         board.Status.BlackCouldCastleShort &&                                                                          //check if the king or the rook didn't already move
         board.IsPathClear(Board.E8, Board.H8) &&                                                                       // check if the path is clear
         !board.IsAttackedByWhite(Board.E8) && !board.IsAttackedByWhite(Board.F8) && !board.IsAttackedByWhite(Board.G8) // check if the squares traversed by king are not attacked
         );
 }
예제 #5
0
파일: BlackKing.cs 프로젝트: vgichar/shah
 /// <summary>
 /// Verifies if the king can castle long.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public bool CanCastleLong(Board board, int from, int to)
 {
     return (
         from == Board.E8 && to == Board.C8 &&
         board.Status.BlackCouldCastleLong &&//check if the king or the rook didn't already move
         board.IsPathClear(Board.A8, Board.E8) &&// check if the path is clear 
         !board.IsAttackedByWhite(Board.E8) && !board.IsAttackedByWhite(Board.D8) && !board.IsAttackedByWhite(Board.C8)// check if the squares traversed by king are not attacked
         );
 }
예제 #6
0
 /// <summary>
 /// Verifies if the king can castle long.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public bool CanCastleLong(Board board, int from, int to)
 {
     return(
         from == Board.E1 && to == Board.C1 &&
         board.Status.WhiteCouldCastleLong &&                                                                           //check if the king or the rook didn't already move
         board.IsPathClear(Board.A1, Board.E1) &&                                                                       // check if the path is clear
         !board.IsAttackedByBlack(Board.E1) && !board.IsAttackedByBlack(Board.D1) && !board.IsAttackedByBlack(Board.C1) // check if the squares traversed by king are not attacked
         );
 }
예제 #7
0
 /// <summary>
 /// Checks if the piece might move on this "board",
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         (base.MightMove(board, from, to) &&
          (
              Board.File(from) == Board.File(to) || // the same file
              Board.Rank(from) == Board.Rank(to)    // the same rank
          ) &&
          board.IsPathClear(from, to));             // the path is clear
 }
예제 #8
0
파일: WhiteRook.cs 프로젝트: vgichar/shah
 /// <summary>
 /// Checks if the piece might move on this "board", 
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         base.MightMove(board, from, to) &&
         (
         Board.File(from) == Board.File(to) ||// the same file
         Board.Rank(from) == Board.Rank(to)// the same rank
         ) &&
         board.IsPathClear(from, to);// the path is clear
 }
예제 #9
0
파일: BlackQueen.cs 프로젝트: vgichar/shah
 /// <summary>
 /// Checks if the piece might move on this "board", 
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         base.MightMove(board, from, to) &&
         (
         Board.File(from) == Board.File(to) ||// the same file
         Board.Rank(from) == Board.Rank(to) ||// the same rank
         Math.Abs(Board.File(from) - Board.File(to)) == Math.Abs(Board.Rank(from) - Board.Rank(to))// it's a diagonal move
         ) &&
         board.IsPathClear(from, to);
 }
예제 #10
0
 /// <summary>
 /// Checks if the piece might move on this "board",
 /// from the "from" square to the "to" square according to the chess rules.
 /// It doesn't verify if its own king is in check after the move.
 /// </summary>
 /// <param name="board">The board</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <returns></returns>
 public override bool MightMove(Board board, int from, int to)
 {
     return
         (base.MightMove(board, from, to) &&
          (
              Board.File(from) == Board.File(to) ||                                                      // the same file
              Board.Rank(from) == Board.Rank(to) ||                                                      // the same rank
              Math.Abs(Board.File(from) - Board.File(to)) == Math.Abs(Board.Rank(from) - Board.Rank(to)) // it's a diagonal move
          ) &&
          board.IsPathClear(from, to));
 }