Skip to content

solution py battleship#652

Open
SerhiiChumak wants to merge 5 commits intomate-academy:masterfrom
SerhiiChumak:develop
Open

solution py battleship#652
SerhiiChumak wants to merge 5 commits intomate-academy:masterfrom
SerhiiChumak:develop

Conversation

@SerhiiChumak
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Your Battleship implementation is well-structured and handles most game mechanics effectively, demonstrating a solid understanding of the requirements. However, changes are needed to address a critical inconsistency in symbol usage and some code redundancy. Specifically, the fire method in app/main.py uses 'o' for missed shots, which deviates from the requirement that print_field must use '~' for empty cells, and 'o' is not a defined symbol in the task description. Please ensure that a missed shot on an empty cell leaves the '~' symbol unchanged. Additionally, the Ship.get_deck method in app/main.py is defined but never used, violating the principle that one function should have one purpose [CHECKLIST ITEM #1] and contributing to redundant statements. Finally, consider correcting the type hint for the ships parameter in Battleship.__init__ to reflect that it expects a list of coordinate tuples, not list[Ship]. Once these adjustments are made, your solution will be even stronger.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

app/main.py Outdated
Comment on lines +38 to +40
@staticmethod
def get_deck(row: int, column: int) -> Deck:
return Deck(row, column)

Choose a reason for hiding this comment

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

The get_deck method in the Ship class is defined but never used. This violates checklist item #1: 'Functions must adhere to the principle that one function has one purpose.' as it's a redundant method, and it also violates 'Do not use redundant statements.'

app/main.py Outdated
if result != "Miss!":
self.field[row][col] = "*" if result == "Hit!" else "x"
return result
self.field[row][col] = "o"

Choose a reason for hiding this comment

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

When a shot misses, the field cell self.field[row][col] is set to "o". The task description specifies "~" for empty cells and does not define "o" for missed shots. A missed shot on an empty cell should ideally leave the "~" symbol unchanged to reflect that it's still an empty cell as per the requirements.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because one core functional requirement is not yet met, which affects the correctness of the game state. At the moment, when a ship is sunk, only the last fired cell is updated to 'x', while the other decks of that same ship stay as '□'; the specification explicitly requires that all decks of a drowned ship be marked with 'x', so your Battleship.fire logic needs to iterate over ship.decks and set self.field[d.row][d.column] = 'x' for each of them when result == "Sunk!". This is a behavioral mismatch that would cause tests or visual checks of the field state to fail and therefore counts as a critical blocker.

The rest of the core functionality is well done: 10x10 field, ship placement from end coordinates, fire returning "Miss!"/"Hit!"/"Sunk!", and validation of ship counts and neighbor rules all look solid. As a non-blocking improvement, consider fixing the Battleship.__init__ type hint so it reflects the actual input type (a list of coordinate tuples rather than list[Ship]), which will make the API clearer and avoid confusion for readers or type-checking tools. Once you adjust the sunk-ship marking so that every deck is turned into 'x', your solution should fully satisfy the specification. Keep up the good work—you're very close; this is mainly a small but important correctness detail to fix.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

app/main.py Outdated
Comment on lines +69 to +76
def fire(self, location: tuple) -> str:
row, col = location
for ship in self.ships:
result = ship.fire(*location)
if result != "Miss!":
self.field[row][col] = "*" if result == "Hit!" else "x"
return result
# self.field[row][col] = "o"

Choose a reason for hiding this comment

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

When a ship is sunk you only set the fired cell in the field to 'x'. The extra-task/specification requires using x for decks of the drowned ship (all decks). Update the logic so that when result == "Sunk!" you iterate over ship.decks and set every corresponding self.field[d.row][d.column] = 'x' (replace any prior '*' or '□' for that ship).

app/main.py Outdated
# If it is, then it should check if this cell is the last alive
# in the ship or not.
pass
def __init__(self, ships: list[Ship]) -> None:

Choose a reason for hiding this comment

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

Type hint mismatch: __init__ is annotated ships: list[Ship] but the constructor actually expects a list of coordinate tuples like ((0,0),(0,3)). Consider changing the annotation to reflect that (for example ships: list[tuple[tuple[int, int], tuple[int, int]]] or a simpler list[tuple]) to avoid confusion.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this iteration! You've successfully addressed the critical issue from the previous review, and the logic for marking sunk ships is now correct. I am approving your solution as an educational override so you can continue to the next stage.

There is one minor point for improvement: the self.is_drowned attribute in the Ship class (app/main.py) is assigned but never used. Since the "sunk" status is determined dynamically, this attribute is redundant and can be removed to make the code cleaner. [CHECKLIST ITEM #4]

Great job getting the functionality right. Keep up the fantastic work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

end: tuple,
is_drowned: bool = False
) -> None:
self.is_drowned = is_drowned

Choose a reason for hiding this comment

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

This attribute self.is_drowned is assigned a value here and on line 45, but it's never read or used anywhere else in the program. This violates checklist item #4: 'Remove unused attributes.' The state of the ship (whether it's sunk or not) is determined on-the-fly by checking its decks, so this attribute is redundant. Consider removing it, along with the is_drowned parameter from the __init__ method.

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.

2 participants