#๐Ÿ”’ hog

114 messages ยท Page 1 of 1 (latest)

south shellBOT
#

@lethal cradle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

lethal cradle
#

im not sure why its doing the wrong result

#

for test 4

shy gate
# lethal cradle im not sure why its doing the wrong result

I don't understand it either without context but if you break it down into small pieces, that would be a good starting point.

Scores after swap - Player 0: 1, Player 1: 106
Wrong result from play: input (<function always_roll.<locals>.strategy at 0x1035c8ae0>, <function always_roll.<locals>.strategy at 0x1035c91c0>)
   returned (1, 106) not (92, 106)
lethal cradle
#

i check my play function

#

but it seems to be right

shy gate
#

I still have no clue. Why would it return 92,106?

lethal cradle
#

maybe im missing something

shy gate
#

Can you explain how all of this works? It might help

lethal cradle
#

its a hog project (game)

and im supposed to work on hog.py which u can see in the pastebin link i sent. and im running python3 hog_grader.py in terminal. That's the file my professor made, which im not supposed to touch. I did all the functions correct im just not sure why test 4 is failing

shy gate
#

OK I understood the hog_grader.py

#

Can you explain how to run hog.py?

#

And as it runs, can you explain what its doing and returning what out of each function?

#

Idk if you're also tasked to write documentation out of your code, but if you have one, share that and I'll probably just read that instead

lethal cradle
shy gate
#

I read the rules and already hating the game lol

#

its chaotic

#

But I get it

lethal cradle
#

RIGHT

#

maybe i should just take the L

shy gate
#

no not really

lethal cradle
#

ive been sturggling on it for 3 hour

shy gate
#

strategy0?

lethal cradle
#

yes i believe it is the take turn function

#

they either call roll dice or free bacon

shy gate
#

I'm looking at how this test plays out

Scores - Player 0: 1, Player 1: 91
Scores after swap - Player 0: 91, Player 1: 1
Scores - Player 0: 106, Player 1: 1
Scores after swap - Player 0: 1, Player 1: 106
Wrong result from play: input (<function always_roll.<locals>.strategy at 0x1035c8ae0>, <function always_roll.<locals>.strategy at 0x1035c91c0>)
   returned (1, 106) not (92, 106)
#

In this, it shows Player 0 and Player 1 being 1,91 first and then swapped

#

After the swap its 91,1

#

Then Player 0 plays its grew to 106, but Player 1 doesn't get to play?

#

oh wait I see it

lethal cradle
#

yes it swap

shy gate
#

Player 1 did play

#

it seems like the problem play tests fails if either score is > 100

lethal cradle
#

so it suggest both players should have 100?

#

100 <

shy gate
#

Where does is_swap function get used?

#

nvm I see it

#

The swap doesn't make sense

#

its like, it will always swap because 1 is always there

lethal cradle
#

is my swap function wrong?

shy gate
#

return (score0 < score1 and score1 % score0 == 0) or (score1 < score0 and score0 % score1 == 0)

#

Why do you have to check if either score is higher or lower than the other?

#

We just need to know if one score is a multiple over the other

lethal cradle
#
Example 1: Player 0 has 20 points and Player 1 has 5; it is Player 1's turn. She scores 5 more, bringing her total to 10. The players swap scores: Player 0 now has 10 points and Player 1 has 20. It is now Player 0's turn. Example 2: Player 0 has 90 points and Player 1 has 50; it is Player 0's turn. She scores 10 more, bringing her total to 100. The players swap scores, and Player 1 wins the game 100 to 50. ```
#

because double mean thet swap

shy gate
#

The one on Github is any positive multiple factor over the other

#

Not an exact double

#

Which one do you follow?

lethal cradle
#

oh sorry ``` Introduction
In this project, you will develop a simulator and multiple strategies for the dice game Hog. You will need to use control and higher-order functions together, from Sections 1.1 through 1.6 of the Composing Programs online text.

In Hog, two players alternate turns trying to reach 100 points first. On each turn, the current player chooses some number of dice to roll, up to 10. His/her turn score is the sum of the dice outcomes, unless any of the dice come up a 1, in which case the score for his/her turn is only 1 point (the Pig out rule).

To spice up the game, we will play with some special rules:

Free bacon: If a player chooses to roll zero dice, he/she scores one more than the largest digit in her opponent's score.
For example, if Player 1 has 42 points, Player 0 gains 1 + max(4, 2) = 5 points by rolling zero dice. If Player 1 has 48 points, Player 0 gains 1 + max(4, 8) = 9 points.
Hog wild: If the sum of both players' total scores is a multiple of seven (e.g., 14, 21, 35), then the current player rolls four-sided dice instead of the usual six-sided dice.
Swine swap: If at the end of a turn one of the player's total score is exactly double the other's, then the players swap total scores.
Example 1: Player 0 has 20 points and Player 1 has 5; it is Player 1's turn. She scores 5 more, bringing her total to 10. The players swap scores: Player 0 now has 10 points and Player 1 has 20. It is now Player 0's turn. Example 2: Player 0 has 90 points and Player 1 has 50; it is Player 0's turn. She scores 10 more, bringing her total to 100. The players swap scores, and Player 1 wins the game 100 to 50.
This project includes six files, but all of your changes will be made to the first one (hog.py), and it is the only one you should need to read and understand.

To get started, download all of the project code as a zip archive: Download the project file```

#

do u want the link to the project file?

shy gate
#

This is not in the one in Github:

Hog wild: If the sum of both players' total scores is a multiple of seven (e.g., 14, 21, 35), then the current player rolls four-sided dice instead of the usual six-sided dice.

#

I don't see any of your function changing the dice to four-sided

#

oh, its there

#

Man, my eyes today

#

Yeah the Swine Swap rule makes a huge difference

#
>>> score1 = 100
>>> score0 = 50
>>> score1 % score0
0
>>> score1 = 90
>>> score1 % score0
40
>>> score0 % score1
50
>>> score1 = 150
>>> score1 % score0
0
#

That last one, 150 % 50 gets you 0. Because 150 is a factor of 50. So the logic is incorrect.

#

you should use floor division of either side and check

#

then swap if they are the same

#

Does that make sense @lethal cradle ?

lethal cradle
#

return (score0 < score1 and score1 // score0 == score1 / score0) or (score1 < score0 and score0 // score1 == score0 / score1)

to check ?

shy gate
#

not quite

lethal cradle
#

i dont get wym

shy gate
#

So you don't check which score is higher than the other

#

You just check if one score's floor divided by 2 is equal to the other score

#

or even just divided by 2 is fine

#

Because that's the rule. Check if the score is exactly double of the other

lethal cradle
#

ah return (score0 // 2 == score1) or (score1 // 2 == score0) ??

shy gate
#

yes!

lethal cradle
#

ok i changed my is_swap function to

        return False
    return (score0 // 2 == score1) or (score1 // 2 == score0)```
#

is this correct?

shy gate
lethal cradle
#

oki

shy gate
#

awesome

shy gate
#
def swap_strategy(score, opponent_score):
    """This strategy rolls 0 dice when it would result in a beneficial swap and
    rolls BASELINE_NUM_ROLLS if it would result in a harmful swap."""
    score_after_bacon = free_bacon(opponent_score) + score
    if score < opponent_score and is_swap(score_after_bacon, opponent_score):
        return 0  # Beneficial swap
    elif free_bacon(opponent_score) >= BACON_MARGIN:
        return 0  # Free Bacon is beneficial
    return BASELINE_NUM_ROLLS
lethal cradle
#

it decides how many dice to roll based on urs and ur opponent score to help u score more points and avoid losing points on a swap

shy gate
#

If the current player score is 8 and the opponent player score is 9, why not just roll 10 six-sided dice?

lethal cradle
#

u cant roll 10 because it against the rules

shy gate
#

Is there anything in the project instructions to help define this?

#

You can roll 10

#

up to 10

#

Still though, why 4?

#

Do you know?

lethal cradle
#

ok so free bacon helps u gain points based on the opponent score, so if ur opponent has 9 it gives u 10 because 9+1

if u roll 0 dice and do free bacon u can get more points instead of rolling like 1

if u roll 10 dice u have higher chance of rolling 1 which means 0 points but the risk of rolling 1 is higher so its a really big gamble

i think he said rolling 4 dice is better because its a balance between risk and gaining point instead of rolling max because the risk is really high

#

the swap strategy is for finding a balance i think

#

"""This strategy rolls 0 dice when it would result in a beneficial swap and
rolls BASELINE_NUM_ROLLS if it would result in a harmful swap."""

shy gate
#

right

#

The strategy part is calling a bunch of functions so thats difficult to follow. Think you can handle it or?

lethal cradle
#

i will try it

#
def swap_strategy(score, opponent_score):
    """This strategy rolls 0 dice when it would result in a beneficial swap and
    rolls BASELINE_NUM_ROLLS if it would result in a harmful swap. It also rolls
    0 dice if that gives at least BACON_MARGIN points and rolls
    BASELINE_NUM_ROLLS otherwise.
    
    >>> swap_strategy(23, 60) # 23 + (1 + max(6, 0)) = 30: Beneficial swap
    0
    >>> swap_strategy(27, 18) # 27 + (1 + max(1, 8)) = 36: Harmful swap
    5
    >>> swap_strategy(50, 80) # (1 + max(8, 0)) = 9: Lots of free bacon
    0
    >>> swap_strategy(12, 12) # Baseline
    5
    """
    # Calculate the score if rolling 0 dice (Free Bacon)
    free_bacon_score = free_bacon(opponent_score)
    potential_score = score + free_bacon_score

    if is_swap(potential_score, opponent_score):
        return 0  # Roll 0 dice for a beneficial swa
    
    if free_bacon_score >= BACON_MARGIN:
        return 0  # Roll 0 dice for free bacon

    baseline_roll_score = roll_dice(BASELINE_NUM_ROLLS, select_dice(score, opponent_score))
    new_score_if_baseline = score + baseline_roll_score
    
    # If rolling 0 dice is a harmful swap, roll the baseline number of dice
    if is_swap(potential_score, opponent_score):
        return BASELINE_NUM_ROLLS  # Harmful swap because rolling 0

    # If rolling the baseline is a harmful swap, roll more dice
    if is_swap(new_score_if_baseline, opponent_score):
        return BASELINE_NUM_ROLLS  # Avoid harmful swap by rolling the baseline

    # Set default to rolling the base number of dice
    return BASELINE_NUM_ROLLS
south shellBOT
#

Hey @lethal cradle!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
lethal cradle
#

oops

#

i will dp pastebin

#

i got all right except for


Failed example:
    swap_strategy(27, 18) # 27 + (1 + max(1, 8)) = 36: Harmful swap
Expected:
    5
Got:
    0
A doctest example failed for swap_strategy.

#

:(

shy gate
#

nice

#

I guess find out, why do 5 dice instead of 0 in that case scenario

lethal cradle
#

haha i tried to fix it and

now the other one broken

Wrong result from swap_strategy: input (12, 34)
   returned 4 not 0
#

im hysterical

lethal cradle
#

i did it!

#

thanks so much btw

south shellBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.