I do have a problem with my connect four code ; it doesn't check whether there is a winner even though the function its okay :-/
Can anyone help me to solve my problem ???
import random
board = dict()
rows,columns = 4,4
def game():
choose_player()
#MAKE BOARD FUNCTION
def make_board():
global rows,columns
global board
rows = input("Give number of rows [more than 4]: ")
print " ----- ---------- ------ ------ ----- ----- "
columns = input("Give number of columns [more than 4]: ")
board = dict()
min = 4
if rows<min:
make_board()
elif columns<min:
make_board()
for x in range(rows):
for y in range(columns):
#board = (x+1,y+1)
board[(x,y)] = "EmptyCells"
return board
#CHOOSE PLAYER FUNCTION
def choose_player():
choose = input("Player 1 vs. Computer [type 1] or Player 1 vs. Player 2 [type 2] : ")
if choose == 1:
#p1 vs. computer
choose_1()
elif choose == 2:
choose_2()
else:
choose_player()
#BLANKS EXIST
def blanks_exist():
for x in range(rows):
for y in range(columns):
if board[(x,y)] == "EmptyCells":
return True
return False
def print_board():
for x in range(rows):
print "|",
for y in range(columns):
if board[(x,y)] == "EmptyCells": print " |",
print board[(x,y)], "|"
print ""
#CHOOSE 1
def choose_1():
board = make_board()
i = 0
while blanks_exist():
#for i in range(rows*columns):
#if i%2 <> 0:
player1 = "RED PLAYER"
print "RED PLAYER"
y = input("Please choose column: 1 to column choice number: ")
if y >=columns:
y = input()
else:
x = (rows-1)
while x>=1:
if board[(x,y)] == "EmptyCells":
board[(x,y)] == "R"
winCheck(board)
x = 0
else:
x = x - 1
#i = i + 1
print_board()
#else:
player2 = "BLACK PLAYER"
print "BLACK PLAYER"
#def p_c(rows,columns):
x = (rows-1)
y = random.choice(range(columns))
while x>=1:
if board[(x,y)] == "EmptyCells":
board[(x,y)] == "B"
print board[(x,y)] == "B"
winCheck(board)
x = 0
else:
x = x - 1
i = i + 1
print_board()
def choose_2():
board = make_board()
while blanks_exist():
#for i in range(rows*columns):
#if i%2 <> 0:
player1 = "RED PLAYER"
print "RED PLAYER"
y = input("Please choose column: 1 to column choice number: ")
if y>= columns:
y = input()
else:
x = (rows-1)
while x>=1:
if board[(x,y)] == "EmptyCells":
board[(x,y)] == "R"
winCheck(board)
x = 0
else:
x = x-1
#i = i + 1
print board()
#else:
player2 = "BLACK PLAYER"
print "BLACK PLAYER"
y = input("Please choose column: 1 to column choice number: ")
if y>= columns:
y = input()
else:
x = (rows-1)
while x>=1:
if board[(x,y)] == "EmptyCells":
board[(x,y)] == "B"
winCheck(board)
x = 0
else:
x = x - 1
i = i + 1
print board()
def winCheck(board):
print "check win"
winVertical(board)
winHorizontal(board)
winDiagonal(board)
def winVertical(board):
for x in range(rows):
for y in range(columns):
if (board[(x,y)] == "R" and board[(x+1,y)] == "R" and board[(x+2,y)] == "R" and board[(x+3,y)] == "R"):
print "Winner == Red player"
break
elif (board[(x,y)] == "B" and board[(x+1,y)] == "B" and board[(x+2,y)] == "B" and board[(x+3,y)] == "B"):
print "Winner == Black player"
break
def winHorizontal(board):
for x in range(rows):
for y in range(columns):
if (board[(x,y)] == "R" and board[(x,y+1)] == "R" and board[(x,y+2)] == "R" and board[(x,y+3)] == "R"):
print "Winner == Red player"
break
elif (board[(x,y)] == "B" and board[(x,y+1)] == "B" and board[(x,y+2)] == "B" and board[(x,y+3)] == "B"):
print "Winner == Black player"
break
def winDiagonal(board):
for x in range(rows):
for y in range(columns):
if (board[x,y] == "R" and board[(x+1,y+1)] == "R" and board[(x+2,y+2)] == "R" and board[(x+3,y+3)] =="R"):
print "Winner == Red player"
elif (board[x,y] == "B" and board[(x+1,y+1)] == "B" and board[(x+2,y+2)] == "B" and board[(x+3,y+3)] =="B"):
print "Winner == Black player"
elif (board[x,y] == "R" and board[(x-1,y-1)] == "R" and board[(x-2,y+2)] == "R" and board[(x-3,y+3)] =="R"):
print "Winner == Red player"
elif (board[x,y] == "B" and board[(x-1,y-1)] == "B" and board[(x-2,y+2)] == "B" and board[(x-3,y+3)] =="B"):
print "Winner == Black player"
game()