Skip to content

[#62] [WIP] En Passant Logic For Pawn#48

Open
Se7enB2st wants to merge 40 commits into
masterfrom
En_Passant
Open

[#62] [WIP] En Passant Logic For Pawn#48
Se7enB2st wants to merge 40 commits into
masterfrom
En_Passant

Conversation

@Se7enB2st

@Se7enB2st Se7enB2st commented Jul 31, 2016

Copy link
Copy Markdown
Contributor

-Dependent on Turn Base Logic PR

This is building off Chad's obstruction PR.

Add:

  • first_turn! to game model
  • end_turn! to game model
  • En Passant logics to pawn model
  • move_number to game database table
  • en_passant to game database table
  • last_moved_piece to piece database table

Not including:

  • Pawn Capture Logic
  • En Passant Capture Logic (Dependent on Pawn Capture Logic)

En Passant Logic:

  1. Target pawn just moved 2 space forward
  2. Target pawn only capturable within the next turn
  3. Target pawn can only be captured by pawn of opposite color
  4. Opposite Pawn must be adjacent to the Target pawn ( x+1 or x-1)

There is probably some refactoring can be done, feel free to leave feedbacks.

@lasley

lasley commented Aug 1, 2016

Copy link
Copy Markdown
Contributor

Rebased onto master for branch isolation

@chadbaum

chadbaum commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

I suggest we merge pawn capture logic first so Ethan can then complete en passant logic as noted in desc.

@chadbaum chadbaum changed the title En Passant Logic For Pawn [#49] En Passant Logic For Pawn Aug 6, 2016
@chadbaum

chadbaum commented Aug 6, 2016

Copy link
Copy Markdown
Contributor

Now that pawn capture is in, pls confirm work is done and PR is ready for review by removing WIP tag and commenting.

@Se7enB2st

Copy link
Copy Markdown
Contributor Author

Integrated En Passant Logic into Pawn's valid_move? logic. En Passant Logic now works with piece move! logic.

@Se7enB2st Se7enB2st changed the title [WIP] En Passant Logic For Pawn En Passant Logic For Pawn Aug 7, 2016
@lasley

lasley commented Aug 8, 2016

Copy link
Copy Markdown
Contributor

Looks like we have conflicts

@Se7enB2st

Copy link
Copy Markdown
Contributor Author

Fixed Merge Conflicts, also add a test to make sure En Passant Logic only works on enemy pawn.

@chadbaum

chadbaum commented Aug 9, 2016

Copy link
Copy Markdown
Contributor

Can you explain your schema decisions? Scanning your code, you have added:

Piece: last_moved_piece
Game: en_passant, move_number, turn,

As far as I can tell:

  • En_passant is not used for anything in your code, please delete or explain.
  • As discussed at last 2 meetings, move_number and turn are both redundant, you only need one. An odd turn means it is white player's turn, an even turn means it is black player's turn. There is no need for another column here. I would delete move_number and just make turn an incrementing integer.
  • I would rename last_moved_piece as it is both redundant (don't need to say piece when talking about piece model) but also vague...I think what you meant is something like turn_last_moved.

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.

@Se7enB2st

Copy link
Copy Markdown
Contributor Author

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.

@chadbaum

chadbaum commented Aug 9, 2016

Copy link
Copy Markdown
Contributor

@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.

Comment thread app/models/pawn.rb Outdated
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

@aleksgorbenko aleksgorbenko Aug 9, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think for readability it should be:

return true if adjacent_piece.type == 'Pawn' &&
               adjacent_piece.color != color

@Se7enB2st Se7enB2st Aug 9, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop approve

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Aleks, this should be refactored as he suggested for best formatting. But it is minor.

@aleksgorbenko

Copy link
Copy Markdown
Contributor

@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.

Comment thread app/models/pawn.rb
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aleksgorbenko

Copy link
Copy Markdown
Contributor

I can't say I understand the methods entirely - it would be best to discuss on a call.

Comment thread app/models/pawn.rb
# 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this guard clause.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to remove this line, but it causes the method to return Nil class error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Se7enB2st Se7enB2st Aug 9, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lasley

lasley commented Aug 12, 2016

Copy link
Copy Markdown
Contributor

This is good to review right, or are you guys still wokring on it?

@Se7enB2st

Copy link
Copy Markdown
Contributor Author

Yes, I will refactor more once turn base logic is merged.

@chadbaum

Copy link
Copy Markdown
Contributor

This still does not seem ready to merge as there are many pending questions, so we will fix this for the next version release.

@chadbaum chadbaum changed the title En Passant Logic For Pawn [WIP] En Passant Logic For Pawn Aug 16, 2016
@chadbaum chadbaum changed the title [WIP] En Passant Logic For Pawn [#62] [WIP] En Passant Logic For Pawn Aug 17, 2016
@Se7enB2st Se7enB2st closed this Nov 18, 2016
@Se7enB2st Se7enB2st reopened this Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants