@@ -21,43 +21,43 @@ function __construct(String $color, int $x, int $y)
2121 }
2222
2323
24- function check_move_legal (mixed $ chessboard , int $ current_x , int $ current_y , int $ move_to_x , int $ move_to_y ): bool
24+ function check_move_legal (mixed $ chessboard , Move $ move ): bool
2525 {
2626
27- return ($ this ->check_moving_onesquare_forwards ($ chessboard , $ current_x , $ current_y , $ move_to_x , $ move_to_y ) or
28- $ this ->check_moving_twosquares_forwards ($ chessboard , $ current_x , $ current_y , $ move_to_x , $ move_to_y ) or
29- $ this ->check_diagonal_move ($ chessboard , $ current_x , $ current_y , $ move_to_x , $ move_to_y ) or
30- $ this ->check_enpassant ($ move_to_x , $ move_to_y )) and
31- $ this ->check_target_square ($ chessboard , $ current_x , $ current_y , $ move_to_x , $ move_to_y );
27+ return ($ this ->check_moving_onesquare_forwards ($ chessboard , $ move ) or
28+ $ this ->check_moving_twosquares_forwards ($ chessboard , $ move ) or
29+ $ this ->check_diagonal_move ($ chessboard , $ move ) or
30+ $ this ->check_enpassant ($ move )) and
31+ $ this ->check_target_square ($ chessboard , $ move );
3232 }
3333
3434
35- function check_moving_onesquare_forwards (mixed $ chessboard , int $ current_x , int $ current_y , int $ move_to_x , int $ move_to_y ):bool
35+ function check_moving_onesquare_forwards (mixed $ chessboard , Move $ move ):bool
3636 {
37- $ is_white_move = $ this ->color == "white " && $ current_y + 1 == $ move_to_y ;
38- $ is_black_move = $ this ->color == "black " && $ current_y - 1 == $ move_to_y ;
39- $ same_file = $ current_x == $ move_to_x ;
40- $ target_square_empty = $ this ->target_square_empty ($ chessboard , $ move_to_x , $ move_to_y );
37+ $ is_white_move = $ this ->color == "white " && $ move -> from_y + 1 == $ move -> to_y ;
38+ $ is_black_move = $ this ->color == "black " && $ move -> from_y - 1 == $ move -> to_y ;
39+ $ same_file = $ move -> from_x == $ move -> to_x ;
40+ $ target_square_empty = $ this ->target_square_empty ($ chessboard , $ move );
4141 return ($ is_white_move || $ is_black_move ) && $ same_file && $ target_square_empty ;
4242 }
4343
4444
45- function check_moving_twosquares_forwards (mixed $ chessboard , int $ current_x , int $ current_y , int $ move_to_x , int $ move_to_y ):bool
45+ function check_moving_twosquares_forwards (mixed $ chessboard , Move $ move ):bool
4646 {
47- $ is_white_move = $ this ->color == "white " && $ current_y == 2 && $ move_to_y == 4 && $ chessboard [$ current_x ][$ current_y + 1 ] == "" ;
48- $ is_black_move = $ this ->color == "black " && $ current_y == 7 && $ move_to_y == 5 && $ chessboard [$ current_x ][$ current_y - 1 ] == "" ;
49- $ same_file = $ current_x == $ move_to_x ;
50- $ target_square_empty = $ this ->target_square_empty ($ chessboard , $ move_to_x , $ move_to_y );
47+ $ is_white_move = $ this ->color == "white " && $ move -> from_y == 2 && $ move -> to_y == 4 && $ chessboard [$ move -> from_x ][$ move -> from_y + 1 ] == "" ;
48+ $ is_black_move = $ this ->color == "black " && $ move -> from_y == 7 && $ move -> to_y == 5 && $ chessboard [$ move -> from_x ][$ move -> from_y - 1 ] == "" ;
49+ $ same_file = $ move -> from_x == $ move -> to_x ;
50+ $ target_square_empty = $ this ->target_square_empty ($ chessboard , $ move );
5151 return ($ is_white_move || $ is_black_move ) && $ same_file && $ target_square_empty ;
5252 }
5353
5454
55- function check_diagonal_move (mixed $ chessboard , int $ current_x , int $ current_y , int $ move_to_x , int $ move_to_y ):bool
55+ function check_diagonal_move (mixed $ chessboard , Move $ move ):bool
5656 {
57- $ is_takes_move = $ chessboard [$ move_to_x ][$ move_to_y ] instanceof ChessPiece;
58- $ is_black_move = $ this ->color == "black " && $ current_y - 1 == $ move_to_y ;
59- $ is_white_move = $ this ->color == "white " && $ current_y + 1 == $ move_to_y ;
60- $ is_diagonal_move = abs ($ current_x - $ move_to_x ) == 1 ;
57+ $ is_takes_move = $ chessboard [$ move -> to_x ][$ move -> to_y ] instanceof ChessPiece;
58+ $ is_black_move = $ this ->color == "black " && $ move -> from_y - 1 == $ move -> to_y ;
59+ $ is_white_move = $ this ->color == "white " && $ move -> from_y + 1 == $ move -> to_y ;
60+ $ is_diagonal_move = abs ($ move -> from_x - $ move -> to_x ) == 1 ;
6161 return $ is_takes_move && $ is_diagonal_move && ($ is_black_move || $ is_white_move );
6262 }
6363
@@ -89,27 +89,27 @@ function get_enpassant_right_possible():bool
8989 return $ this ->enpassant_right_possible ;
9090 }
9191
92- function check_enpassant (int $ move_to_x , int $ move_to_y ):bool
92+ function check_enpassant (Move $ move ):bool
9393 {
9494 if ($ this ->color == "white " ){
9595 if ($ this ->enpassant_left_possible ){
96- if ($ move_to_x == $ this ->x -1 && $ move_to_y == $ this ->y +1 ){
96+ if ($ move -> to_x == $ this ->x -1 && $ move -> to_y == $ this ->y +1 ){
9797 return true ;
9898 }
9999 }
100100 if ($ this ->enpassant_right_possible ){
101- if ($ move_to_x == $ this ->x +1 && $ move_to_y == $ this ->y +1 ){
101+ if ($ move -> to_x == $ this ->x +1 && $ move -> to_y == $ this ->y +1 ){
102102 return true ;
103103 }
104104 }
105105 }else {
106106 if ($ this ->enpassant_left_possible ){
107- if ($ move_to_x == $ this ->x -1 && $ move_to_y == $ this ->y -1 ){
107+ if ($ move -> to_x == $ this ->x -1 && $ move -> to_y == $ this ->y -1 ){
108108 return true ;
109109 }
110110 }
111111 if ($ this ->enpassant_right_possible ){
112- if ($ move_to_x == $ this ->x +1 && $ move_to_y == $ this ->y -1 ){
112+ if ($ move -> to_x == $ this ->x +1 && $ move -> to_y == $ this ->y -1 ){
113113 return true ;
114114 }
115115 }
@@ -118,9 +118,9 @@ function check_enpassant(int $move_to_x, int $move_to_y):bool
118118 }
119119
120120
121- function target_square_empty (mixed $ chessboard , int $ move_to_x , int $ move_to_y ): bool
121+ function target_square_empty (mixed $ chessboard , Move $ move ): bool
122122 {
123- if ($ chessboard [$ move_to_x ][$ move_to_y ] == "" ) {
123+ if ($ chessboard [$ move -> to_x ][$ move -> to_y ] == "" ) {
124124 return true ;
125125 }else {
126126 return false ;
0 commit comments