Hi, I am trying to write a connect four program in python, which I am not very experienced at. This is what I have so far:
row7 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row6 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row5 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row4 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row3 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row2 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row1 = [' ', ' ', ' ', ' ', ' ', ' ', ' ']
row1 = list(row1)
row2 = list(row2)
row3 = list(row3)
row4 = list(row4)
row5 = list(row5)
row6 = list(row6)
def make_board():
print "6| %s | %s | %s | %s | %s | %s | %s |" % tuple((row6))
print "5| %s | %s | %s | %s | %s | %s | %s |" % tuple((row5))
print "4| %s | %s | %s | %s | %s | %s | %s |" % tuple((row4))
print "3| %s | %s | %s | %s | %s | %s | %s |" % tuple((row3))
print "2| %s | %s | %s | %s | %s | %s | %s |" % tuple((row2))
print "1| %s | %s | %s | %s | %s | %s | %s |" % tuple((row1))
print "-| a | b | c | d | e | f | g |"
make_board()
def p1move():
while True:
if p1move1=='a':
row1[0]='X'
make_board()
break
elif p1move1=='b':
row1[1]=='X'
make_board()
break
elif p1move1=='c':
row1[2]=='X'
make_board()
break
elif p1move1=='d':
row1[3]=='X'
make_board()
break
elif p1move1=='e':
row1[4]=='X'
make_board()
break
elif p1move1=='f':
row1[5]=='X'
make_board()
break
elif p1move1=='g':
row1[6]=='X'
make_board()
break
elif p1move1 != 'a' or 'b' or 'c' or 'd' or 'e' or 'f' or 'g':
print 'Please enter a letter a-g'
else:
print "Invalid input, try again."
p1move1=raw_input('Welcome to Connect Four, you are X, enter a lettered row to make a move!: ')
p1move()
def p2move():
while True:
if p2move1=='a'and p1move1=='a':
row2[0]='O'
elif p2move1=='a':
row1[0]='O'
make_board()
break
if p2move1=='b'and p1move1=='b':
row2[1]=='O'
elif p2move1=='b':
row1[1]='O'
make_board()
break
if p2move1=='c'and p1move1=='c':
row2[2]=='O'
elif p2move1=='c':
row1[2]='O'
make_board()
break
if p2move1=='d'and p1move1=='d':
row2[3]=='O'
elif p2move1=='d':
row1[3]='O'
make_board()
break
if p2move1=='e'and p1move1=='e':
row2[4]=='O'
elif p2move1=='e':
row1[4]='O'
make_board()
break
if p2move1=='f'and p1move1=='f':
row2[5]=='O'
elif p2move1=='f':
row1[5]='O'
make_board()
break
if p2move1=='g'and p1move1=='g':
row2[6]=='O'
elif p2move1=='g':
row1[6]='O'
make_board()
else:
print "Invalid input, try again."
p2move1=raw_input('Welcome to Connect Four, you are O, enter a lettered row to make a move!: ')
p2move()
make_board()
If I dont enter 'a' in the first input the variable 'X' is not assigned to the board (row1). The same problem exists with the player 2 move. Also do I have to keep repeating a function like p1move and p2move over and over? Is there an easier way to do this? Thanks and any help is appreciated.