0

I've recently been trying to code a program which plays domino with two players and with input, but apparently my syntax is flawed at the line where I define a function. I think it might be because of my near-zero experience with coding , but after I've searched on the internet, I haven't found any solution. Here's the code :

def comptage():
    occurences_of_numbers=[]
    for i in range(7):
        a=0
        for k in range(7):
            if i in list(hand[k]):
                a=a+1
        occurences_of_numbers.append(a)
    return(occurences_of_numbers)


File "<string>", line 36
    def comptage():
    ^
SyntaxError: invalid syntax

This function counts the numbers of occurrences of the numbers (0,1,2,3,4,5,6) in the tuples representing the dominos in the list named hand. I then use the function for other functions.

available_draws=14
opponent_hand=7
while comptage()[list(board[0])[0]]==0 and comptage()[list(board[len(board)-1])[1]]==0:
    inpt_list=list(map(int,input('   Quel domino pioché ?')))
    M.append((inpt_list[0],inpt_list[1]))
    available_draws=available_draws-1


#board is a tuple list representing the board


def riposte():
    probability=[]
    for i in range(7):
        b=0
        for k in range(len(board)):
            if i in list(board[k]):
                b=b+1
        probability.append((7-comptage()[i]-b)/(28-len(hand)-len(board))*(opponent_hand/(opponent_hand+available_draws)))
    return(probability)

This error popped up after I changed something in the riposte() function (I added the b characteristic). But it shows the mistake for the comptage() function. I don't know why it showed that. I've tried changing the code a bit, rewriting it, and using other variants, but the error message stands still.

The rest of the code is : (some unfinished stuff)

zero=[]
one=[]
two=[]
three=[]
four=[]
five=[]
six=[]
all_the_dominos=[zero,one,two,three,four,five,six]
for i in range(7):
    for k in range(7):
        all_the_dominos[i].append((i,k))

hand=[]
for i in range(1,8):
    input_list=list(map(int,input('   Domino '+str(i)+' ?')))
    hand.append((input_list[0],input_list[1]))
print(hand)

for i in range(7):
    for k in range(7):
                if hand[i] in all_the_dominos[k]:
                    del all_the_dominos[k][all_the_dominos[k].index(hand[i])]
                elif tuple(reversed(list(hand[i]))) in all_the_dominos[k]:
                    del all_the_dominos[k][all_the_dominos[k].index(tuple(reversed(list(hand[i]))))

board=[(6,1),(1,2),(2,6),(6,6)]

#example of a board 

available_draws=14
opponent_hand=7
while input('   Pioche adverse ?')=='oui':
    opponent_hand=opponent_hand+1
    available_draws=available_draws-1

The only thing that comes after what is problematic is the last bit.

Help would be greatly appreciated.

!! UPDATE !!

I've trisd another version of the compatge function, but it still shows the same error :

def comptage():
    F=[0,0,0,0,0,0,0]
    for i in range(7):
        for k in range(len(M)):
            if i in list(M[k]):
                F[i]=F[i]+1
    return(F)

But something's strange : i can't even define a variable !

a=0

File "<string>", line 34
    a=0
    ^
SyntaxError: invalid syntax

I definitely think there is a problem with my phone because i've downloaded several other coding programs and always got the same error. It's strange because it was working fine and all of a sudden, it doesn't allow me to do anything.

Well maybe there's just a problem with the code but i really don't think so.

  • 1
    Can you share the full code? I believe there is an error above with mismatched paranthesis – Aditya Jul 04 '22 at 21:19
  • 1
    For easiness to read and debug your code it's better to write self explanatory names for variables, like `board` instead of `J`. Also, it's a convention to use Capital letter at the beginning for classes. For variables it's better `board`, `domino_board` or `dominoBoard`. Trust me, they seem unnecessary longer, but yourself-in-three-months is going to be thankful with yourself-now. – Ignatius Reilly Jul 04 '22 at 21:26
  • 2
    Check the line before the one where you're getting an error and make sure all the parentheses and other brackets are properly closed. – kindall Jul 07 '22 at 00:08

2 Answers2

0

It looks like you have 1 more closing parenthesis ()) than opening parenthesis (() on this line: P.append((7-comptage()[i]-b)/(28-len(M)-len(J))*(aM/(aM+p)))

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
0

Actually, I've found the problem : there was just a missing bracket . I'm new to Python so I didn't pay enough attention even though I thought I did.

  • Could you detail the mistake you made and post the working code? A comment that it works should be reserved for the comments section, and not be added as an 'answer'. – Steinn Hauser Magnússon Jul 08 '22 at 14:19
  • 1
    Ok noted ! The mistake I made was that I forgot a closing bracket on the following line : ```del all_the_dominos[k][all_the_dominos[k].index(tuple(reversed(list(hand[i]))))``` But still, it was strange that the error message showed the lines after the mistake as the real mistakes. – Alexandre Palamodov Jul 08 '22 at 22:50