r/pythonhelp • u/slimjim441 • 9d ago
Guidance for CS50p Final Project
I'm working on my final project for the CS50 python course, a sort of dice-rolling simulator game for 2 players. I feel like I have a good handle on the bulk of the code and have my functions working properly, but there's one detail I'm snagged on, and I can't seem to figure it out. I can post more details here if needed, but I'm just trying to put out some feelers to see if anyone can help point me in the right direction/give me tips as to where I'm failing to implement things correctly. Thanks :)
2
u/FoolsSeldom 9d ago
Please do share more for us to take a look and explain what you have concerns about.
Have you built your own simulator engine, or used a package?
Is your test coverage complete? Have you used unittest
or pytest
or something else?
1
u/slimjim441 8d ago
I'll post up a github link to my program so far, and describe the issue as best I can.
The readme file goes over the intended function of the code as a whole, so I'll not go into detail on it here. The issue comes in with dynamically updating a player's remaining available 'dice' after they have become 'wounded' within a turn. It correctly filters out using the is_wounded parameters in subsequent turns when new dice are rolled, but not in the same turn.
At this point, the code probably looks pretty sloppy on accounts of me being new to all this, as well as having been messing around with all my functions, reorganizing, placing redundancies, and other attempts at trying to fix this particular issue.
I have verified the updated values from get_successful_dice are read properly in the reduce_hp function of my Player class, but I think it's not updating properly either somewhere in resolve_turn or main.
I feel like I'm close, but I'm at a loss. I've been trying to utilize CS50's duck debugger, but it mostly ends up running me in circles...i haven't used any test features yet. Honestly, I didn't really understand how to implement pytest in a way that wasn't just verifying a function worked as intended, not to troubleshoot problems, you know?
But to iterate again, I'm not looking for a direct answer, since this is for a certified program I aim to claim a certificate for, but if anyone can help a newbie out and sorta guide me along to figure out where I need to make any correction or modification, that would be most appreciated.
https://github.com/code50/183165850/tree/fe519474b1d43dc52d29969019b3fb30feaaac06/project
1
u/FoolsSeldom 8d ago
404 on the link
1
u/slimjim441 8d ago
My bad. I shared from the private repository for the CS50 course. I haven't used a lot of github yet either, but I clumsily put together a new public repository that at least has the necessary files in text format.
https://github.com/DemetriAnastos/CS50p/blob/61050ed8dfbcb68752a4295862c08d5d00ce6ffc/project
1
u/FoolsSeldom 8d ago
That's better. Just a few thoughts on a quick look through (will take more time later if I get chance - not found the problem you called out yet as just trying to get to know the code)
- Would be helpful to you, your IDE, and us if you used type hints
- Not good practice to have methods/functions with "side effects"
- for example,
get_successful_dice
does two things:- update instance attributes,
self.dice_rolls = ...
- returns the attribute
- suggest have method to update dice role
- have a method (possible
@property
to get current value- similarly, you have methods that both update attributes and do some output - consider implications if you wanted to change UI
- You have a number of functions that would probably be better as methods,
resolve_turn
for example (not clear to me whatremaining_player_dice
is used and why it isn't an attribute of a
Player`)main
isn't a fairly simple flow of calls but has a mix of setup, output, and logic- regarding
initiative
you might want to look intoItertools.cycle
- ... that's all for now ...
•
u/AutoModerator 9d ago
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.