#๐Ÿ”’ Calculation error? board game help

6 messages ยท Page 1 of 1 (latest)

fallen jasper
#

making a snakes and ladders game:
one of the simulations for my task at school is Player blue's position calculation. It says 91 !=98 Blue position calculation error, what is causing this?

from diceroll import roll_the_dice

p1_name = "Red"
p1_position = 0
p2_name = "Blue"


p2_position = 0


snake_heads = [25, 44, 65, 76, 99]

snake_tails = [6, 23, 34, 28, 56]


ladder_bases = [8, 26, 38, 47, 66]


ladder_tops = [43, 39, 55, 81, 92]



broken needleBOT
#

@fallen jasper

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.

fallen jasper
#

loop:

while True:
    if p2_position == 100 or p1_position ==100:
        break
    diceroll = roll_the_dice()
    p1_position = p1_position + diceroll
    if p1_position > 100:
        p1_position = p1_position - diceroll
        print(f"{p1_name} has rolled a {diceroll}, and hence, their dice roll is ignored. {p1_name} stays on {p1_position}.")
    else:
        print(f"{p1_name} has rolled a {diceroll}, their new position is now {p1_position}.")

    if p1_position == 100:
        winner = p1_name
        print(f"{winner} has reached 100 and has won the game!")
        break

    if p1_position in ladder_bases:
        p1_position = ladder_tops[ladder_bases.index(p1_position)]
        print(f"{p1_name} has landed on a ladder and climbed up! {p1_name}'s new position is now {p1_position}.")
    elif p1_position in snake_heads:
        p1_position = snake_tails[snake_heads.index(p1_position)]
        print(f"{p1_name} has landed on a snake head and slipped over! {p1_name}'s new position is now {p1_position}.")

#
    if p1_position == 100 or p2_position==100:
        break

    diceroll = roll_the_dice()
    p2_position = p2_position + diceroll


    if p2_position > 100:
        p2_position = p2_position - diceroll
        print(f"{p2_name} has rolled a {diceroll}, and hence, their dice roll is ignored. {p2_name} stays on {p2_position}.")
    else:
        print(f"{p2_name} has rolled a {diceroll}, their new position is now {p2_position}.")
    if p2_position == 100:
        winner = p2_name
        print(f"{winner} has reached 100 and won the game!")
        break
    if p2_position in ladder_bases:
        p2_position = ladder_tops[ladder_bases.index(p2_position)]
        print(f"{p2_name} has landed on a ladder and climbed up! {p2_name}'s new position is now {p2_position}.")
    elif p2_position in snake_heads:
        p2_position = snake_tails[snake_heads.index(p2_position)]
        print(f"{p2_name} has landed on a snake head and slipped over! {p2_name}'s new position is now {p2_position}.")
broken needleBOT
#

@fallen jasper

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.