[#62] [WIP] En Passant Logic For Pawn#48
Conversation
|
Rebased onto master for branch isolation |
|
I suggest we merge pawn capture logic first so Ethan can then complete en passant logic as noted in desc. |
|
Now that pawn capture is in, pls confirm work is done and PR is ready for review by removing WIP tag and commenting. |
|
Integrated En Passant Logic into Pawn's valid_move? logic. En Passant Logic now works with piece move! logic. |
|
Looks like we have conflicts |
|
Fixed Merge Conflicts, also add a test to make sure En Passant Logic only works on enemy pawn. |
|
Can you explain your schema decisions? Scanning your code, you have added: Piece: last_moved_piece As far as I can tell:
This also takes care of the turn logic in the next ticket so I'm not sure there is any work to be done there. When this is done we can surface what turn it is in the games#show view with a simple `<%= game.turn %>'. Also, I noticed a bunch of surface-level changes to files unrelated to en passant, do you know what caused them and if we should be reviewing any of it? If you look at your files changed, you have many initializers, application.rb, and environment files included. Want to make sure you're not wasting your time Rubocopping any of these files -- they should have already been blacklisted. |
|
En Passant is not needed at this point(It was necessary when I first attempt at En Passant Logic), I will clean up the database to remove/change any redundant columns. The surface-level changes were due to Rubocop errors. It kept asking me to add top-level comments at those files(Not sure why it was doing this if it was blacklisted). But there is no other change made to those files beside the top comments. |
|
@aleksgorbenko Do you know why Ethan running Rubocop would have caused violations for these files when it doesn't for the rest of us? @Se7enB2st I wouldn't waste your time Rubocopping Rails files. I've not had any problems with the whitelist/blacklist since Aleks implemented it so maybe he can investigate. |
| adjacent_piece = occupant_piece(x + (adjacent ? 1 : -1), y) | ||
| return false if adjacent_piece.nil? | ||
| return true if adjacent_piece.type == | ||
| 'Pawn' && adjacent_piece.color != color |
There was a problem hiding this comment.
i think for readability it should be:
return true if adjacent_piece.type == 'Pawn' &&
adjacent_piece.color != colorThere was a problem hiding this comment.
I agree with Aleks, this should be refactored as he suggested for best formatting. But it is minor.
|
@chadbaum re: Rubocop - no idea really. I just checked the rubocop.yml file and it is in place in this branch. Not sure what could have caused that. |
| # En Passant Logic: | ||
| # 1)target pawn just moved 2 space forward | ||
| # 2)only capture within the next turn | ||
| # 3)can only capture by opponent's pawn |
There was a problem hiding this comment.
I'm not sure what step 3 means. En Passant does not require that the ONLY piece available to capture the victim be the pawn, only that the pawn COULD have captured it in the first space on the previous turn.
|
I can't say I understand the methods entirely - it would be best to discuss on a call. |
| # Return true if opponent's pawn is found | ||
| def valid_en_passant_pawn?(x, y, adjacent) | ||
| adjacent_piece = occupant_piece(x + (adjacent ? 1 : -1), y) | ||
| return false if adjacent_piece.nil? |
There was a problem hiding this comment.
Don't need this guard clause.
There was a problem hiding this comment.
Tried to remove this line, but it causes the method to return Nil class error.
There was a problem hiding this comment.
Can you explain what the adjacent parameter is doing? I see you passing true and false between these 2 methods but they are not commented.
There was a problem hiding this comment.
Just because a pawn is adjacent to another pawn does not make it a valid en passant victim so I think the name and return of this method are misleading. What makes it valid is this PLUS the victim having moved 2 spaces forward last turn.
There was a problem hiding this comment.
This method checks if there is any valid pawn adjacent to the victim pawn(include? true or false). If any of adjacent side have a valid pawn, it will return true. A separate method check if the pawn moved 2 space forward in the last turn.
This was the rafactored version of following methods:
def valid_en_passant_pawn?(x, y)
return false unless valid_passant_pawn_left?(x, y)
return false unless valid_passant_pawn_right?(x. y)
false
end
def valid_passant_pawn_left?(x, y)
left_piece = find_piece(x - 1, y)
return false if left_piece.nil?
return true if left_piece.type == 'Pawn' && side_piece.color != color
false
end
def valid_passant_pawn_right?(x, y)
right_piece = find_piece(x + 1, y)
return false if right_piece.nil?
return true if right_piece.type == 'Pawn' && side_piece.color != color
false
endThere was a problem hiding this comment.
I don't see the other method you are referring to that checks the 2 spaces forward. IMO this logic should all be one method, it is really hard to follow otherwise.
|
This is good to review right, or are you guys still wokring on it? |
|
Yes, I will refactor more once turn base logic is merged. |
|
This still does not seem ready to merge as there are many pending questions, so we will fix this for the next version release. |
-Dependent on Turn Base Logic PR
This is building off Chad's obstruction PR.
Add:
first_turn!to game modelend_turn!to game modelEn Passant logicsto pawn modelmove_numberto game database tableen_passantto game database tablelast_moved_pieceto piece database tableNot including:
En Passant Logic:
x+1orx-1)There is probably some refactoring can be done, feel free to leave feedbacks.