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.