Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed task #868

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

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

Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request:

  1. Potion Application: The apply_potion method is called without checking if the potion is None for both red_knight and mordred. This could lead to errors if the potion is not provided. Please add a check to ensure the potion exists before applying it.

  2. Weapon Parameter: The Knight class constructor expects a weapon dictionary, but currently, only the power value is being passed. Ensure that the entire weapon dictionary is passed to the constructor to prevent errors.

  3. Attribute Initialization: The apply_potion method assumes self.armour is already defined. Make sure self.armour is initialized in the __init__ method or elsewhere before calling this method to avoid attribute errors.

  4. Armour Application: The apply_armour method expects a list of dictionaries with a 'protection' key. Ensure the input matches this expectation to prevent runtime errors.

  5. Weapon Handling: In line 9, you are adding self.weapon directly to self.power, which will cause an error since a dictionary cannot be added to an integer. Extract the specific value, such as weapon['power'], to add to self.power.

Once these issues are resolved, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you need further assistance. 😊

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

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

class Knight:
def __init__(self, name: str, power: int,
hp: int,
weapon: dict) -> None:

Choose a reason for hiding this comment

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

The weapon parameter is expected to be a dictionary, but in line 9, you are directly adding self.weapon to self.power. This will raise an error since you cannot add a dictionary to an integer. You might want to extract a specific value from the weapon dictionary, such as weapon['power'], to add to self.power.

self.weapon = weapon
self.power += self.weapon

def apply_armour(self, protection: list[dict]) -> None:

Choose a reason for hiding this comment

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

The apply_armour method expects a list of dictionaries, each containing a 'protection' key. Ensure that the input to this method matches this expectation to avoid runtime errors.

elif key == "power":
self.power += value
elif key == "protection":
self.armour += value

Choose a reason for hiding this comment

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

The apply_potion method assumes that self.armour is already defined. Ensure that self.armour is initialized in the __init__ method or elsewhere before this method is called to avoid attribute errors.

red_knight["hp"] += red_knight["potion"]["effect"]["hp"]
lancelot_value = knights_config["lancelot"]
lancelot = Knight(lancelot_value["name"], lancelot_value["power"],
lancelot_value["hp"], lancelot_value["weapon"]["power"])

Choose a reason for hiding this comment

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

The Knight class constructor expects a weapon dictionary, but you are passing lancelot_value["weapon"]["power"], which is an integer. You should pass the entire weapon dictionary instead.


arthur_value = knights_config["arthur"]
arthur = Knight(arthur_value["name"], arthur_value["power"],
arthur_value["hp"], arthur_value["weapon"]["power"])

Choose a reason for hiding this comment

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

Similar to the previous comment, ensure you pass the entire weapon dictionary to the Knight constructor, not just the power value.


mordred_value = knights_config["mordred"]
mordred = Knight(mordred_value["name"], mordred_value["power"],
mordred_value["hp"], mordred_value["weapon"]["power"])

Choose a reason for hiding this comment

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

Ensure you pass the entire weapon dictionary to the Knight constructor, not just the power value.

red_knight_value = knights_config["red_knight"]
red_knight = Knight(red_knight_value["name"], red_knight_value["power"],
red_knight_value["hp"],
red_knight_value["weapon"]["power"])

Choose a reason for hiding this comment

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

Ensure you pass the entire weapon dictionary to the Knight constructor, not just the power value.

app/main.py Outdated
mordred = Knight(mordred_value["name"], mordred_value["power"],
mordred_value["hp"], mordred_value["weapon"]["power"])
mordred.apply_armour(mordred_value["armour"])
mordred.apply_potion(mordred_value["potion"]["effect"])

Choose a reason for hiding this comment

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

The apply_potion method is called without checking if mordred_value["potion"] is None. This could lead to an error if potion is not provided. Consider adding a check similar to the other knights.

app/main.py Outdated
red_knight_value["hp"],
red_knight_value["weapon"]["power"])
red_knight.apply_armour(red_knight_value["armour"])
red_knight.apply_potion(red_knight_value["potion"]["effect"])

Choose a reason for hiding this comment

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

The apply_potion method is called without checking if red_knight_value["potion"] is None. This could lead to an error if potion is not provided. Consider adding a check similar to the other knights.

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 on addressing the issues previously mentioned! Your code now meets the task requirements and constraints. Here are some key points and suggestions for further improvement:

  1. Armour Initialization: Ensure that fighter_1.armour and fighter_2.armour are initialized before use to avoid attribute errors. Consider initializing self.armour to 0 instead of None to prevent errors during arithmetic operations.

  2. Weapon Handling: The weapon parameter is currently handled as an integer, which aligns with your current implementation. However, ensure consistency across your codebase, especially if previous feedback suggested using a dictionary.

  3. Code Consistency: The apply_potion method and Knight class constructor are correctly implemented, ensuring that potions and weapons are applied as intended. This consistency is crucial for the functionality of your game mechanics.

  4. Final Conclusion: Your code is well-structured, organized into modules and packages, and passes flake8 and pytest. The changes made have improved the functionality and reliability of your code.

Keep up the good work! Remember to review the comments to further enhance your code and learn from any mistakes. Addressing critical issues in the future will help you avoid similar problems and improve your coding skills. 🚀

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

Comment on lines +5 to +6
fighter_1.hp -= (fighter_2.power - fighter_1.armour)
fighter_2.hp -= (fighter_1.power - fighter_2.armour)

Choose a reason for hiding this comment

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

Ensure that fighter_1.armour and fighter_2.armour are initialized before they are used in these calculations. This is crucial to avoid attribute errors if the armour is not set.

class Knight:
def __init__(self, name: str, power: int,
hp: int,
weapon: int) -> None:

Choose a reason for hiding this comment

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

The weapon parameter is currently an integer, but previous feedback suggested passing a dictionary. Ensure consistency in how weapons are handled across your codebase.

self.hp = hp
self.weapon = weapon
self.power += self.weapon
self.armour = None

Choose a reason for hiding this comment

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

Consider initializing self.armour to 0 instead of None to avoid errors when performing arithmetic operations.

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