I've only glanced down your code and am not familiar with your previous efforts. Combine insulting and stirred-up to one class. "CharacterTraits" or so. This then makes it easier to add more traits like happiness, warmongering, intelligence, luck etc.
Python
Welcome to the Python community on the programming.dev Lemmy instance!
๐ Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django ๐ฌ)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
๐ Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
๐ Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
โจ Python Ecosystem:
๐ Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythรถrhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API
Feeds
They currently have the parent class "Action" for their common attributes and methods. Does that cover what you are suggesting?
They currently have the parent class โActionโ for their common attributes and methods. Does that cover what you are suggesting?
I didn't see, but if they want a trait that has a completely set of different methods? I'm not a big fan of interface-esque classes unless the API is absolutely solid. In this case it would not be.
A set of different methods would warrant assignment to a different class. So far no character traits warrant that. What is the alternative to interface-esque classes? If you could provide a dummy code example that would be great. What would make the API solid? Thank you for all the suggestions.
Why not have one class that has a level for each trait, which are scored 0-100, 0-10 etc. so... self.luck = 7.3
self.anger = 4.0
and so on. And then there's one method that determines the action. That's going to be so much easier to maintain, extend, and work with.
class CharacterTraits:
def __init__(self, luck, anger, magic, ...):
self.luck = luck
self.anger = anger
# and so on
# maybe keep a list of previous actions which could inform the next action state
self.history = []
def get_action(self):
# do whatever to decide action
action = ...
# then add it to history
self.history.append(action)
return action
and then the calling code determines what's output to the screen. So, internally, the class is just responsible for one thing - hte business logic. Maybe another class Game
could be responsible for outputting the strings, taking user input etc. If the UI were to change at a later date, the CharacterTraits
class stays the same, but only the Game
class would need to be modified. Instead of - as I understand it - all the classes currently would have to be updated (a maintenance nightmare!)
I only had a really quick look down the code so I may be missing the point entirely, but that's the direction I would go down.
EDIT: the get_action
method could take in some args, like opponent_traits
or some kind of situation, maybe even add additional methods like is_lucky
to return a bool as to whether a situation that requires luck has been successful or not. Another method could be has_won_fight(opponent_traits)
and the method compares strength, luck, magic whatever, to the opponent to decide whether the character has won. And so on. By keeping it simple like this, it's a lot easier to work with!
Thank you for all the suggestions. I will take them into deep consideration.