Skip to content

Solution#667

Open
Polikovs wants to merge 4 commits intomate-academy:masterfrom
Polikovs:develop
Open

Solution#667
Polikovs wants to merge 4 commits intomate-academy:masterfrom
Polikovs:develop

Conversation

@Polikovs
Copy link

@Polikovs Polikovs commented Mar 8, 2026

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

Good job on the overall structure with the Deck, Ship, and Battleship classes! However, this requires changes because there are a few critical issues with the game logic that need to be addressed.

Here are the main points to fix:

  1. Incorrect Ship Creation: The current logic can create rectangular ships (e.g., from (0,0) to (1,1)). Ships must be a straight line, either horizontally or vertically. Please adjust your logic to create decks only along a single row or column.
  2. Handling Repeated Shots: The fire method returns None for a shot on an already-hit cell ('*' or 'X'). The method must always return one of the required strings ("Miss!", "Hit!", or "Sunk!"). A repeated shot should probably be considered a "Miss!".
  3. Incomplete Board Update: When a ship is sunk, all of its decks must be updated to 'X' on the game field. Currently, only the last-hit deck is updated, while the others remain as '*'.
  4. Redundant else: The else statement in your fire method is redundant because the preceding if block has a return. This violates a checklist item [CHECKLIST ITEM #3].

Please fix these issues to ensure the game functions correctly according to the requirements.


✨ 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 +19 to +21
for row in range(row_start, row_end + 1):
for column in range(column_start, column_end + 1):
self.decks.append(Deck(row, column))

Choose a reason for hiding this comment

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

The current logic for creating ship decks can result in rectangular ships (e.g., for start=(0,0) and end=(1,1)), which is not standard for Battleship. Ships should always be straight lines, either horizontal or vertical. You should adjust this logic to create decks only along a single row or a single column.

app/main.py Outdated
Comment on lines +56 to +58
if ship.is_drowned:
self.field[row][column] = "X"
return "Sunk!"

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 should update all its decks on the game field to reflect this status (e.g., to 'X'). Currently, only the deck that was last hit is being updated, leaving other parts of the sunk ship marked as just 'hit' ('*').

app/main.py Outdated
Comment on lines +59 to +61
else:
self.field[row][column] = "*"
return "Hit!"

Choose a reason for hiding this comment

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

This else statement is redundant. The if block above it contains a return, so the code inside this else will only execute if the if condition is false anyway. You can remove the else and unindent its content. This violates checklist item #3: 'Don't use redundant else if a non-empty return is used'.

app/main.py Outdated
else:
self.field[row][column] = "*"
return "Hit!"
return None

Choose a reason for hiding this comment

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

The method returns None if a shot is fired at a cell that has already been hit (marked with '*' or 'X'). The task description requires the method to return one of the specified strings ("Miss!", "Hit!", or "Sunk!"). Firing at an already-hit cell should probably be considered a "Miss!".

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

Great job fixing the critical issues from the last review! The core logic for handling ships and shots is working perfectly now. However, this submission requires changes because the two extra methods from the task description, print_field and _validate_field, have not been implemented yet. While they were marked as optional, they are part of the overall requirements for completing this task. Please add these methods. Also, consider updating the fire method's return type hint from str | None to str for better accuracy, as it never returns None. You're very close to finishing this!


✨ 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

self.is_drowned = all(not d.is_alive for d in self.decks)


class Battleship:

Choose a reason for hiding this comment

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

The two extra tasks from the description, print_field and _validate_field, have not been implemented. While they are optional for the core functionality, they are part of the overall task requirements.

app/main.py Outdated
for deck in new_ship.decks:
self.field[deck.row][deck.column] = "□"

def fire(self, location: tuple) -> str | None:

Choose a reason for hiding this comment

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

The return type hint str | None is not entirely accurate. This method always returns a string ("Miss!", "Hit!", or "Sunk!"), so it never returns None. The type hint should be simplified to -> str.


if ship.is_drowned:
for deck in ship.decks:
self.field[deck.row][deck.column] = "X"

Choose a reason for hiding this comment

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

The task description for the print_field method specifies using a lowercase 'x' for the decks of a sunk ship. Using 'X' here is inconsistent with that requirement. This also affects the check on line 50.

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

Great job implementing the print_field and _validate_field methods! The logic you've written is solid and you're very close to a perfect solution.

I am approving this submission as an educational override to help you move forward, but there is one crucial detail to address. While you've correctly implemented the _validate_field method, it is never actually called. To ensure the initial ship placement is always validated when a Battleship object is created, you need to call this method from within your __init__ constructor.

Simply add self._validate_field() at the end of the __init__ method. Keep up the excellent work!


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

Footnotes

  1. Rate AI review example

Comment on lines +36 to +45
def __init__(self, ships: list) -> None:
self.field = [["~" for _ in range(10)] for _ in range(10)]
self.ships_objects = []

for start, end in ships:
new_ship = Ship(start, end)
self.ships_objects.append(new_ship)

for deck in new_ship.decks:
self.field[deck.row][deck.column] = "□"

Choose a reason for hiding this comment

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

The task requires _validate_field to be called from the __init__ method. You've correctly implemented the validation logic, but it needs to be invoked here after all ships have been processed to ensure the initial field is valid.

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