daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Moves {
  2.  
  3.     private final Board B;
  4.     private boolean regular;
  5.     public Moves(final Board b) { B = b; regular = regular_position(); }
  6.  
  7.     public boolean get_regular_position() { return regular; }
  8.     public void set_regular_position(final boolean new_reg) {
  9.       regular = new_reg;
  10.     }
  11.  
  12.     // checking whether B represents a "normal" position or not;
  13.     // if not, then only simple checks regarding move-correctness should
  14.     // be performed, only checking the direct characteristics of the figure
  15.     // moved;
  16.     // checks whether there is exactly one king of each colour, there are
  17.     // no more figures than promotions allow, and there are no pawns on the
  18.     // first or last rank;
  19.     public boolean regular_position() {
  20.       int[] counts = new int[256];
  21.       for (char file = 'a'; file <= 'h'; ++file)
  22.         for (char rank = '1'; rank <= '8'; ++rank)
  23.           ++counts[(int) B.get(file,rank)];
  24.       if (counts[Board.white_king] != 1 || counts[Board.black_king] != 1)
  25.         return false;
  26.       if (counts[Board.white_pawn] > 8 || counts[Board.black_pawn] > 8)
  27.         return false;
  28.       int count_w_promotions = 0;
  29.       count_w_promotions += Math.max(counts[Board.white_queen]-1,0);
  30.       count_w_promotions += Math.max(counts[Board.white_rook]-2,0);
  31.       count_w_promotions += Math.max(counts[Board.white_bishop]-2,0);
  32.       count_w_promotions += Math.max(counts[Board.white_knight]-2,0);
  33.       if (count_w_promotions > 8 - counts[Board.white_pawn]) return false;
  34.       int count_b_promotions = 0;
  35.       count_b_promotions += Math.max(counts[Board.black_queen]-1,0);
  36.       count_b_promotions += Math.max(counts[Board.black_rook]-2,0);
  37.       count_b_promotions += Math.max(counts[Board.black_bishop]-2,0);
  38.       count_b_promotions += Math.max(counts[Board.black_knight]-2,0);
  39.       if (count_b_promotions > 8 - counts[Board.black_pawn]) return false;
  40.       for (char file = 'a'; file <= 'h'; ++file) {
  41.         final char fig1 = B.get(file,'1');
  42.         if (fig1 == Board.white_pawn || fig1 == Board.black_pawn) return false;
  43.         final char fig8 = B.get(file,'8');
  44.         if (fig8 == Board.white_pawn || fig8 == Board.black_pawn) return false;
  45.       }
  46.       return true;
  47.     }
  48.  
  49.     public boolean check_normal_white_move(final char file0, final char rank0,
  50.                                            final char file1, final char rank1) {
  51.         if (! Board.is_valid_white_figure(B.get(file0,rank0))) return false;
  52.         if (! B.is_empty(file1,rank1) && ! Board.is_valid_black_figure(B.get(file1,rank1)))
  53.           return false;
  54.         if (B.get_active_colour() != 'w') return false;
  55.         if (! check_move_simple(file0,rank0,file1,rank1)) return false;
  56.         if (! regular) return true;
  57.         final Board test_board = new Board(B);
  58.         test_board.normal_white_move_0(file0,rank0,file1,rank1);
  59.         final Moves test_move = new Moves(test_board);
  60.         final char[] king_pos = test_move.white_king_position();
  61.         assert(king_pos.length == 2);
  62.         return test_move.black_not_attacking(king_pos[0],king_pos[1]);
  63.     }
  64.     public boolean check_normal_black_move(final char file0, final char rank0,
  65.                                            final char file1, final char rank1) {
  66.       // ADDED THE CHECK NORMAL BLACK MOVE BASED ON THE CHECK NORMAL WHITE MOVE
  67.  
  68.       if (! Board.is_valid_black_figure(B.get(file0,rank0))) return false;
  69.       if (! B.is_empty(file1,rank1) && ! Board.is_valid_white_figure(B.get(file1,rank1)))
  70.         return false;
  71.       if (B.get_active_colour() != 'b') return false;
  72.       if (! check_move_simple(file0,rank0,file1,rank1)) return false;
  73.       if (! regular) return true;
  74.       final Board test_board = new Board(B);
  75.       test_board.normal_black_move_0(file0,rank0,file1,rank1);
  76.       final Moves test_move = new Moves(test_board);
  77.       final char[] king_pos = test_move.black_king_position();
  78.       assert(king_pos.length == 2);
  79.       return test_move.white_not_attacking(king_pos[0],king_pos[1]);
  80.  
  81.     }
  82.  
  83.     // for checking a normal move by just applying the move-rules
  84.     private boolean check_move_simple(final char file0, final char rank0,
  85.                                       final char file1, final char rank1) {
  86.         final char fig = B.get(file0,rank0);
  87.         if (fig == Board.white_king || fig == Board.black_king)
  88.           return check_king_move(file0,rank0,file1,rank1);
  89.         if (fig == Board.white_queen || fig == Board.black_queen)
  90.           return check_queen_move(file0,rank0,file1,rank1);
  91.         if (fig == Board.white_rook || fig == Board.black_rook)
  92.           return check_rook_move(file0,rank0,file1,rank1);
  93.         if (fig == Board.white_bishop || fig == Board.black_bishop)
  94.           return check_bishop_move(file0,rank0,file1,rank1);
  95.         if (fig == Board.white_knight || fig == Board.black_knight)
  96.           return check_knight_move(file0,rank0,file1,rank1);
  97.         if (fig == Board.white_pawn)
  98.           return check_white_pawn_move(file0,rank0,file1,rank1);
  99.         else
  100.           return check_black_pawn_move(file0,rank0,file1,rank1);
  101.     }
  102.     private boolean check_king_move(final char file0, final char rank0,
  103.                                     final char file1, final char rank1) {
  104.       // ADDED KING MOVE
  105.       int fileChange = file0 - file1;
  106.       int rankChange = rank0 - rank1;
  107.  
  108.       return fileChange <= 1 && fileChange >= -1
  109.       && rankChange <= 1 && rankChange >= -1;
  110.     }
  111.     private boolean check_queen_move(final char file0, final char rank0,
  112.                                     final char file1, final char rank1) {
  113.       // ADDED QUEEN MOVE
  114.       int fileChange = file0 - file1;
  115.       int rankChange = rank0 - rank1;
  116.  
  117.       return fileChange <=8 && fileChange >= -8
  118.       && rankChange <= 8 && rankChange >= -8;
  119.     }
  120.     private boolean check_rook_move(final char file0, final char rank0,
  121.                                     final char file1, final char rank1) {
  122.       // ADDED ROOK MOVE
  123.       int fileChange = file0 - file1;
  124.       int rankChange = rank0 - rank1;
  125.  
  126.       return fileChange <=8 || fileChange >= -8
  127.       || rankChange <= 8 || rankChange >= -8;
  128.     }
  129.     private boolean check_bishop_move(final char file0, final char rank0,
  130.                                     final char file1, final char rank1) {
  131.       // ADDED BISHOP MOVE
  132.       int fileChange = file0 - file1;
  133.       int rankChange = rank0 - rank1;
  134.  
  135.       return fileChange <= 8 && rankChange <= 8
  136.         || fileChange <= 8 && rankChange >= -8
  137.         || fileChange >= -8 && rankChange >= -8
  138.         || fileChange >= -8 && rankChange <= 8;
  139.     }
  140.     private boolean check_knight_move(final char file0, final char rank0,
  141.                                     final char file1, final char rank1) {
  142.       // ADDED KNIGHT MOVE
  143.       int fileChange = file0 - file1;
  144.       int rankChange = rank0 - rank1;
  145.  
  146.       /* IS THIS THE CORRECT WAY?
  147.        * return fileChange <= 1 && rankChange <= 2
  148.         || fileChange <= 1 && rankChange >= -2
  149.         || fileChange <= 2 && rankChange <= 1
  150.         || fileChange <= 2 && rankChange >= -1
  151.         || fileChange >= -1 && rankChange <= 2
  152.         || fileChange >= -1 && rankChange >= -2
  153.         || fileChange >= -2 && rankChange <= 1
  154.         || fileChange >= -2 && rankChange >= -1;*/
  155.  
  156.       // OR IS THIS?
  157.       return fileChange <= 1 || fileChange >= -1 || fileChange <= 2 || fileChange >= -2
  158.         && rankChange <= 1 || rankChange >= - 1 || rankChange <= 2 || rankChange >= -2;
  159.     }
  160.     private boolean check_white_pawn_move(final char file0, final char rank0,
  161.                                           final char file1, final char rank1) {
  162.       // ADDED PAWN MOVE
  163.       int fileChange = file0 - file1;
  164.       int rankChange = rank0 - rank1;
  165.  
  166.       return fileChange == 0
  167.       && rankChange <= 1;
  168.     }
  169.     private boolean check_black_pawn_move(final char file0, final char rank0,
  170.                                           final char file1, final char rank1) {
  171.       // ADDED PAWN MOVE
  172.       int fileChange = file0 - file1;
  173.       int rankChange = rank0 - rank1;
  174.  
  175.       return fileChange == 0
  176.       && rankChange >= -1;
  177.     }
  178.  
  179.     public boolean check_white_kingside_castling() {
  180.         // only demonstration code:
  181.         final char c = B.get_white_castling();
  182.         if (c == '-' || c == 'q') return false;
  183.         if (B.get_active_colour() == 'b') return false;
  184.         if (B.get('e','1') != 'K') return false;
  185.         if (! black_not_attacking('e','1')) return false;
  186.         if (! free_white('f','1')) return false;
  187.         // XXX
  188.         return true;
  189.     }
  190.     public boolean check_white_queenside_castling() {
  191.         // only demonstration code:
  192.         final char c = B.get_white_castling();
  193.         if (c == '-' || c == 'k') return false;
  194.         if (B.get_active_colour() == 'b') return false;
  195.         // ADDED BASED ON KINGSIDE CASTLING
  196.         if (B.get('e','1') != 'Q') return false;
  197.         if (! black_not_attacking('e','1')) return false;
  198.         if (! free_white('f','1')) return false;
  199.         // XXX
  200.         return true;
  201.     }
  202.     public boolean check_black_kingside_castling() {
  203.         // only demonstration code:
  204.         final char c = B.get_black_castling();
  205.         if (c == '-' || c == 'q') return false;
  206.         if (B.get_active_colour() == 'w') return false;
  207.  
  208.         // ADDED BASED ON CHECK WHITE
  209.         if (B.get('e','8') != 'K') return false;
  210.         if (! black_not_attacking('e','8')) return false;
  211.         if (! free_white('f','8')) return false;
  212.         // XXX
  213.         return true;
  214.     }
  215.     public boolean check_black_queenside_castling() {
  216.         // only demonstration code:
  217.         final char c = B.get_black_castling();
  218.         if (c == '-' || c == 'k') return false;
  219.         if (B.get_active_colour() == 'w') return false;
  220.         // ADDED BASED ON KINGSIDE CASTLING
  221.         if (B.get('e','8') != 'Q') return false;
  222.         if (! black_not_attacking('e','8')) return false;
  223.         if (! free_white('f','8')) return false;
  224.         // XXX
  225.         return true;
  226.     }
  227.  
  228.     public boolean check_white_promotion(final char pawn_file, final char figure) {
  229.         // XXX
  230.       // ADDED CHECKING FOR CORRECT FIGURE AND POSITION - ALTHOUGH IT SEEMS AS THOUGH
  231.       // PAWN_FILE SHOULD BE PAWN_RANK, AS IT IS THE REACHING OF THE END RANK THAT
  232.       // CAUSES PROMOTION OF A PAWN, NOT FILE
  233.       if (figure == P && pawn_file == 8) {
  234.         return true;
  235.       }
  236.       else return false;        
  237.  
  238.     }
  239.     public boolean check_black_promotion(final char pawn_file, final char figure) {
  240.         // XXX
  241.       // ADDED CHECKING FOR CORRECT FIGURE AND POSITION
  242.       if (figure == p && pawn_file == 1) {
  243.         return true;
  244.       }
  245.       else return false;
  246.     }
  247.  
  248.     // checks whether black doesn't attack the field:
  249.     public boolean black_not_attacking(final char file, final char rank) {
  250.         // XXX
  251.         return true;
  252.     }
  253.     public boolean free_white(final char file, final char rank) {
  254.         // XXX
  255.         return black_not_attacking(file,rank) && B.is_empty(file,rank);
  256.     }
  257.     // checks whether white doesn't attack the field:
  258.     public boolean white_not_attacking(final char file, final char rank) {
  259.         // XXX
  260.         return true;
  261.     }
  262.     public boolean free_black(final char file, final char rank) {
  263.         // XXX
  264.         return white_not_attacking(file,rank) && B.is_empty(file,rank);
  265.     }
  266.  
  267.     public char[] white_king_position() {
  268.       for (char file = 'a'; file <= 'h'; ++file)
  269.         for (char rank = '1'; rank <= '8'; ++rank)
  270.           if (B.get(file,rank) == Board.white_king) {
  271.             char[] result = new char[2];
  272.             result[0] = file; result[1] = rank;
  273.             return result;
  274.           }
  275.       return new char[0];
  276.     }
  277.     public char[] black_king_position() {
  278.       for (char file = 'a'; file <= 'h'; ++file)
  279.         for (char rank = '1'; rank <= '8'; ++rank)
  280.           if (B.get(file,rank) == Board.black_king) {
  281.             char[] result = new char[2];
  282.             result[0] = file; result[1] = rank;
  283.             return result;
  284.           }
  285.       return new char[0];
  286.     }
  287.  
  288.  
  289.     public static void main(final String[] args) {
  290.       // checking regular_position
  291.       {
  292.         Moves m = new Moves(new Board());
  293.         assert(m.regular_position());
  294.         m = new Moves(new Board("8/8/8/8/8/8/8/8 w - - 0 1"));
  295.         assert(!m.regular_position());
  296.         m = new Moves(new Board("KK6/8/8/8/8/8/8/8 w - - 0 1"));
  297.         assert(!m.regular_position());
  298.         m = new Moves(new Board("kk6/8/8/8/8/8/8/8 w - - 0 1"));
  299.         assert(!m.regular_position());
  300.         m = new Moves(new Board("Kk6/8/8/8/8/8/8/8 w - - 0 1"));
  301.         assert(m.regular_position());
  302.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/8 w - - 0 1"));
  303.         assert(m.regular_position());
  304.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/n7 w - - 0 1"));
  305.         assert(!m.regular_position());
  306.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/N7 w - - 0 1"));
  307.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/b7 w - - 0 1"));
  308.         assert(!m.regular_position());
  309.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/B7 w - - 0 1"));
  310.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/r7 w - - 0 1"));
  311.         assert(!m.regular_position());
  312.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/R7 w - - 0 1"));
  313.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/q7 w - - 0 1"));
  314.         assert(!m.regular_position());
  315.         m = new Moves(new Board("Kk6/qqqqqqqq/QQQQQQQQ/Q7/q7/rrbbnn2/RRBBNN2/Q7 w - - 0 1"));
  316.         assert(!m.regular_position());
  317.         m = new Moves(new Board("Kkp5/8/8/8/8/8/8/8 w - - 0 1"));
  318.         assert(!m.regular_position());
  319.         m = new Moves(new Board("KkP5/8/8/8/8/8/8/8 w - - 0 1"));
  320.         assert(!m.regular_position());
  321.         m = new Moves(new Board("Kk6/8/8/8/8/8/8/7p w - - 0 1"));
  322.         assert(!m.regular_position());
  323.         m = new Moves(new Board("Kk6/8/8/8/8/8/8/7P w - - 0 1"));
  324.         assert(!m.regular_position());
  325.       }
  326.       // checking check_white/black_king/queenside_castling
  327.       {
  328.         Moves m = new Moves(new Board("4k2r/8/8/8/8/8/8/4K2R w Kk - 0 1"));
  329.         assert(!m.check_white_kingside_castling());
  330.         assert(!m.check_black_kingside_castling());
  331.         assert(!m.check_white_queenside_castling());
  332.         assert(!m.check_black_queenside_castling());
  333.         m = new Moves(new Board("4k2r/8/8/8/8/8/8/4K2R b Kk - 0 1"));
  334.         assert(!m.check_white_kingside_castling());
  335.         assert(!m.check_black_kingside_castling());
  336.         assert(!m.check_white_queenside_castling());
  337.         assert(!m.check_black_queenside_castling());
  338.         m = new Moves(new Board("4k2r/4pppp/8/8/8/8/4PPPP/4K2R w KQkq - 0 1"));
  339.         assert(m.check_white_kingside_castling());
  340.         assert(!m.check_black_kingside_castling());
  341.         assert(!m.check_white_queenside_castling());
  342.         assert(!m.check_black_queenside_castling());
  343.         m = new Moves(new Board("4k2r/4pppp/8/8/8/8/4PPPP/4K2R b KQkq - 0 1"));
  344.         assert(!m.check_white_kingside_castling());
  345.         assert(m.check_black_kingside_castling());
  346.         assert(!m.check_white_queenside_castling());
  347.         assert(!m.check_black_queenside_castling());
  348.         m = new Moves(new Board("r3k3/8/8/8/8/8/8/R3K3 w Qq - 0 1"));
  349.         assert(!m.check_white_kingside_castling());
  350.         assert(!m.check_black_kingside_castling());
  351.         assert(!m.check_white_queenside_castling());
  352.         assert(!m.check_black_queenside_castling());
  353.         m = new Moves(new Board("r3k3/8/8/8/8/8/8/R3K3 b Qq - 0 1"));
  354.         assert(!m.check_white_kingside_castling());
  355.         assert(!m.check_black_kingside_castling());
  356.         assert(!m.check_white_queenside_castling());
  357.         assert(!m.check_black_queenside_castling());
  358.         m = new Moves(new Board("r3k3/p7/8/8/8/8/8/R3K3 w Qq - 0 1"));
  359.         assert(!m.check_white_kingside_castling());
  360.         assert(!m.check_black_kingside_castling());
  361.         assert(m.check_white_queenside_castling());
  362.         assert(!m.check_black_queenside_castling());
  363.         m = new Moves(new Board("r3k3/p7/8/8/8/8/8/R3K3 b Qq - 0 1"));
  364.         assert(!m.check_white_kingside_castling());
  365.         assert(!m.check_black_kingside_castling());
  366.         assert(!m.check_white_queenside_castling());
  367.         assert(m.check_black_queenside_castling());
  368.         m = new Moves(new Board("r3k3/p7/8/8/8/n7/8/R3K3 w Qq - 0 1"));
  369.         assert(!m.check_white_kingside_castling());
  370.         assert(!m.check_black_kingside_castling());
  371.         assert(!m.check_white_queenside_castling());
  372.         assert(!m.check_black_queenside_castling());
  373.         m = new Moves(new Board("r3k3/p7/B7/8/8/8/8/R3K3 b Qq - 0 1"));
  374.         assert(!m.check_white_kingside_castling());
  375.         assert(!m.check_black_kingside_castling());
  376.         assert(!m.check_white_queenside_castling());
  377.         assert(!m.check_black_queenside_castling());
  378.         // XXX
  379.       }
  380.     }
  381.  
  382. }
  383.    
  384. private boolean check_king_move(final char file0, final char rank0,
  385.                                     final char file1, final char rank1) {
  386.       // ADDED KING MOVE
  387.       int fileChange = file0 - file1;
  388.       int rankChange = rank0 - rank1;
  389.  
  390.       return fileChange <= 1 && fileChange >= -1
  391.       && rankChange <= 1 && rankChange >= -1;
  392.     }
  393.     private boolean check_queen_move(final char file0, final char rank0,
  394.                                     final char file1, final char rank1) {
  395.       // ADDED QUEEN MOVE
  396.       int fileChange = file0 - file1;
  397.       int rankChange = rank0 - rank1;
  398.  
  399.       return fileChange <=8 && fileChange >= -8
  400.       && rankChange <= 8 && rankChange >= -8;
  401.     }
  402.     private boolean check_rook_move(final char file0, final char rank0,
  403.                                     final char file1, final char rank1) {
  404.       // ADDED ROOK MOVE
  405.       int fileChange = file0 - file1;
  406.       int rankChange = rank0 - rank1;
  407.  
  408.       return fileChange <=8 || fileChange >= -8
  409.       || rankChange <= 8 || rankChange >= -8;
  410.     }
  411.     private boolean check_bishop_move(final char file0, final char rank0,
  412.                                     final char file1, final char rank1) {
  413.       // ADDED BISHOP MOVE
  414.       int fileChange = file0 - file1;
  415.       int rankChange = rank0 - rank1;
  416.  
  417.       return fileChange <= 8 && rankChange <= 8
  418.         || fileChange <= 8 && rankChange >= -8
  419.         || fileChange >= -8 && rankChange >= -8
  420.         || fileChange >= -8 && rankChange <= 8;
  421.     }
  422.     private boolean check_knight_move(final char file0, final char rank0,
  423.                                     final char file1, final char rank1) {
  424.       // ADDED KNIGHT MOVE
  425.       int fileChange = file0 - file1;
  426.       int rankChange = rank0 - rank1;
  427.  
  428.       /* IS THIS THE CORRECT WAY?
  429.        * return fileChange <= 1 && rankChange <= 2
  430.         || fileChange <= 1 && rankChange >= -2
  431.         || fileChange <= 2 && rankChange <= 1
  432.         || fileChange <= 2 && rankChange >= -1
  433.         || fileChange >= -1 && rankChange <= 2
  434.         || fileChange >= -1 && rankChange >= -2
  435.         || fileChange >= -2 && rankChange <= 1
  436.         || fileChange >= -2 && rankChange >= -1;*/
  437.  
  438.       // OR IS THIS?
  439.       return fileChange <= 1 || fileChange >= -1 || fileChange <= 2 || fileChange >= -2
  440.         && rankChange <= 1 || rankChange >= - 1 || rankChange <= 2 || rankChange >= -2;
  441.     }
  442.     private boolean check_white_pawn_move(final char file0, final char rank0,
  443.                                           final char file1, final char rank1) {
  444.       // ADDED PAWN MOVE
  445.       int fileChange = file0 - file1;
  446.       int rankChange = rank0 - rank1;
  447.  
  448.       return fileChange == 0
  449.       && rankChange <= 1;
  450.     }
  451.     private boolean check_black_pawn_move(final char file0, final char rank0,
  452.                                           final char file1, final char rank1) {
  453.       // ADDED PAWN MOVE
  454.       int fileChange = file0 - file1;
  455.       int rankChange = rank0 - rank1;
  456.  
  457.       return fileChange == 0
  458.       && rankChange >= -1;
  459.     }
  460.    
  461. if (fileChange <= 8 || fileChange >= -8 && rankChange == 0)
  462.   return true;
  463. else if (fileChange == 0 && rankChange <= 8 || rankChange >= -8)
  464.   return true;
  465. else if (fileChange <= 8 && rankChange <= 8 && fileChange == rankChange)
  466.   return true;
  467. else if (fileChange >= -8 && rankChange >= -8 && fileChange == rankChange)
  468.   return true;
  469. else if (fileChange <= 8 && rankChange >= -8 && fileChange == -(rankChange))
  470.   return true;
  471. else if (fileChange >= -8 && rankChange <= 8 && -(fileChange) == rankChange)
  472.   return true;
  473. else
  474.   return false;
  475.    
  476. private boolean check_king_move(final char file0, final char rank0,
  477.                                     final char file1, final char rank1) {
  478.       // ADDED KING MOVE
  479.       int fileChange = file0 - file1;
  480.       int rankChange = rank0 - rank1;
  481.  
  482.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  483.         return fileChange <= 1 && fileChange >= -1
  484.         && rankChange <= 1 && rankChange >= -1;
  485.       }
  486.       else return false;
  487.     }
  488.     private boolean check_queen_move(final char file0, final char rank0,
  489.                                     final char file1, final char rank1) {
  490.       // ADDED QUEEN MOVE
  491.       int fileChange = file0 - file1;
  492.       int rankChange = rank0 - rank1;
  493.  
  494.       /*return fileChange <=8 || fileChange >= -8
  495.       && rankChange <= 8 || rankChange >= -8;*/
  496.  
  497.       // NEW QUEEN MOVES
  498.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  499.         if (fileChange <= 8 || fileChange >= -8 && rankChange == 0)
  500.           return true;
  501.         else if (fileChange == 0 && rankChange <= 8 || rankChange >= -8)
  502.           return true;
  503.         else if (fileChange <= 8 && rankChange <= 8 && fileChange == rankChange)
  504.           return true;
  505.         else if (fileChange >= -8 && rankChange >= -8 && fileChange == rankChange)
  506.           return true;
  507.         else if (fileChange <= 8 && rankChange >= -8 && fileChange == -(rankChange))
  508.           return true;
  509.         else if (fileChange >= -8 && rankChange <= 8 && -(fileChange) == rankChange)
  510.           return true;
  511.         else
  512.           return false;
  513.       }
  514.       else return false;
  515.     }
  516.     private boolean check_rook_move(final char file0, final char rank0,
  517.                                     final char file1, final char rank1) {
  518.       // ADDED ROOK MOVE
  519.       int fileChange = file0 - file1;
  520.       int rankChange = rank0 - rank1;
  521.  
  522.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  523.         return fileChange <=8 || fileChange >= -8
  524.         || rankChange <= 8 || rankChange >= -8;
  525.       }
  526.       else return false;
  527.     }
  528.     private boolean check_bishop_move(final char file0, final char rank0,
  529.                                     final char file1, final char rank1) {
  530.       // ADDED BISHOP MOVE
  531.       int fileChange = file0 - file1;
  532.       int rankChange = rank0 - rank1;
  533.  
  534.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  535.         return fileChange <= 8 && rankChange <= 8
  536.         || fileChange <= 8 && rankChange >= -8
  537.         || fileChange >= -8 && rankChange >= -8
  538.         || fileChange >= -8 && rankChange <= 8;
  539.       }
  540.       else return false;
  541.     }
  542.     private boolean check_knight_move(final char file0, final char rank0,
  543.                                     final char file1, final char rank1) {
  544.       // ADDED KNIGHT MOVE
  545.       int fileChange = file0 - file1;
  546.       int rankChange = rank0 - rank1;
  547.  
  548.       // IS THIS THE CORRECT WAY?
  549.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  550.         return fileChange == 1 && rankChange == 2
  551.         || fileChange == 1 && rankChange == -2
  552.         || fileChange == 2 && rankChange == 1
  553.         || fileChange == 2 && rankChange == -1
  554.         || fileChange == -1 && rankChange == 2
  555.         || fileChange == -1 && rankChange == -2
  556.         || fileChange == -2 && rankChange == 1
  557.         || fileChange == -2 && rankChange == -1;
  558.       }
  559.       else return false;
  560.  
  561.       /*// OR IS THIS?
  562.       return fileChange <= 1 || fileChange >= -1 || fileChange <= 2 || fileChange >= -2
  563.         && rankChange <= 1 || rankChange >= - 1 || rankChange <= 2 || rankChange >= -2;*/
  564.     }
  565.     private boolean check_white_pawn_move(final char file0, final char rank0,
  566.                                           final char file1, final char rank1) {
  567.       // ADDED PAWN MOVE
  568.       int fileChange = file0 - file1;
  569.       int rankChange = rank0 - rank1;
  570.  
  571.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  572.         return fileChange == 0 && rankChange == 1;
  573.       }
  574.       else return false;
  575.     }
  576.     private boolean check_black_pawn_move(final char file0, final char rank0,
  577.                                           final char file1, final char rank1) {
  578.       // ADDED PAWN MOVE
  579.       int fileChange = file0 - file1;
  580.       int rankChange = rank0 - rank1;
  581.  
  582.       if (file1 <= 8 && rank1 <= 8 && file1 >= 1 && rank1 >= 1 ) {
  583.         return fileChange == 0 && rankChange == -1;
  584.       }
  585.       else return false;
  586.     }
  587.    
  588. return fileChange <=8 && fileChange >= -8 && rankChange <= 8 && rankChange >= -8;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top