Hey Guys,

Ive been having a bit of trouble with a program which rolls dice for the game risk. Ive been able to implement number of dice choice selection for both attacker and defender, and to get them to roll the results. The part I am trying to implement now is some form of variable which will take the attackers and defenders results compare them and decide the winning pairs of dice from each player.

I beleive that I need a variable but looking at my code i've come to the conclusion that I may have wrote myself into a corner and need to rewrite the existing code so that roll calculation doesnt take place in the function call but in a new variable??

Anyway my code is as follows;

import random

#Attacking dice roll functions
def Attacking_Dice_1_Roll(Dice_Roll_1):
    print "Attacker die roll was: %r" % (Dice_Roll_1)

def Attacking_Dice_2_Roll(Dice_Roll_1, Dice_Roll_2):
    print "Attacker die Roll 1: %r, Die Roll 2: %r" % (Dice_Roll_1, Dice_Roll_2)

def Attacking_Dice_3_Roll(Dice_Roll_1, Dice_Roll_2, Dice_Roll_3):
    print "Attacker die Roll 1: %r, Die Roll 2: %r, Die Roll 3: %r" % (Dice_Roll_1, Dice_Roll_2, Dice_Roll_3)

#Defender dice roll functions
def Defending_Dice_1_Roll(Dice_Roll_1):
    print "Defender die roll was: %r" % (Dice_Roll_1)

def Defending_Dice_2_Roll(Dice_Roll_1, Dice_Roll_2):
    print "Defender die Roll 1: %r, Die Roll 2: %r" % (Dice_Roll_1, Dice_Roll_2)

#Attacking dice selection
print "Attacker, do you want to roll with 1, 2 or 3 dice?" 
Attacking_Dice_Selection = int(raw_input())
print "You have selected:", Attacking_Dice_Selection, "Dice"

#Defender dice selection
print "Defender, Do you want to roll with 1 or 2 dice?"
Defending_Dice_Selection = int(raw_input())
print "You have selected:", Defending_Dice_Selection, "Dice"

#Attacking dice results
if Attacking_Dice_Selection == int(1):
    Attacking_Dice_1_Roll(random.randint(1, 6))

if Attacking_Dice_Selection == int(2):
    Attacking_Dice_2_Roll(random.randint(1, 6),random.randint(1, 6))    

if Attacking_Dice_Selection == int(3):
    Attacking_Dice_3_Roll(random.randint(1, 6),random.randint(1, 6),random.randint(1, 6))

#Defending dice results
if Defending_Dice_Selection == int(1):
    Defending_Dice_1_Roll(random.randint(1, 6))

if Defending_Dice_Selection == int(2):
    Defending_Dice_2_Roll(random.randint(1, 6),random.randint(1, 6))

Just after some general direction on where to take it not full fledged code to fix it any suggestions would be greatly appreciated.

Cheers

Aaron

You can use tuples of integers to store the dice results, for example

attacking_values = (random.randint(1,6), random.randint(1,6),)
This question has already been answered. Start a new discussion instead.