Open Brimbin opened 3 years ago
board = []
for i in range(6): board.append(["0"]*7)
m = 7 print(" "3 + (" "3).join(["{}".format(i) for i in range(0,m)])) for j,bb in enumerate(board): print("{}: ".format(j) + " | ".join(bb))
Gewinner = False Rz = 0 i = 5 x = 6 a = 6 col = 0 while(Gewinner==False): if Rz % 2 == 0: col = int(input("Spieler 1 gib eine Zahl(0-6) für die spalte(0-6) ein:" )) if board[i][col] == "0": board[i][col] = "R" x = 5 else: if board[i-1][col]== "0": board[i-1][col]= "R" x = 4 else: if board[i - 2][col] == "0": board[i - 2][col] = "R" x = 3 else: if board[i - 3][col] == "0": board[i - 3][col] = "R" x = 2 else: if board[i - 4][col] == "0": board[i - 4][col] = "R" x = 1 else: board[i - 5][col] = "R" x = 0
Rz += 1 print(" " * 3 + (" " * 3).join(["{}".format(i) for i in range(0, m)])) for j, bb in enumerate(board): print("{}: ".format(j) + " | ".join(bb)) while (x <= 2): if board[x][col] == "R" and board[x + 1][col] == "R" and board[x + 2][col] == "R" and board[x + 3][col] == "R": print("Spieler 1 hat gewonnen") Gewinner = True break else: break while (col >= 3): if board[x][col] == "R" and board[x][col - 1] == "R" and board[x][col - 2] == "R" and board[x][col - 3] == "R": print("Spieler 1 hat gewonnen") Gewinner = True break else: break print(x) if board[x][col] == "R" and board[x][col + 1] == "R" and board[x][col + 2] == "R" and board[x][col + 3] == "R": print("Spieler 1 hat gewonnen") Gewinner = True else: col = int(input("Spieler 2 gib eine Zahl(0-6) für die spalte(0-6) ein:" )) if board[i][col] == "0": board[i][col] = "G" a = 5 else: if board[i - 1][col] == "0": board[i - 1][col] = "G" a = 4 else: if board[i - 2][col] == "0": board[i - 2][col] = "G" a = 3 else: if board[i - 3][col] == "0": board[i - 3][col] = "G" a = 2 else: if board[i - 4][col] == "0": board[i - 4][col] = "G" a = 1 else: board[i - 5][col] = "G" a = 0 Rz += 1 print(" " * 3 + (" " * 3).join(["{}".format(i) for i in range(0, m)])) for j, bb in enumerate(board): print("{}: ".format(j) + " | ".join(bb)) while (a <= 2): if board[a][col] == "G" and board[a + 1][col] == "G" and board[a + 2][col] == "G" and board[a + 3][col] == "G": print("Spieler 2 hat gewonnen") Gewinner = True break else: break while (col >= 3): if board[a][col] == "G" and board[a][col - 1] == "G" and board[a][col - 2] == "G" and board[a][col - 3] == "G": print("Spieler 2 hat gewonnen") Gewinner = True break else: break if board[a][col] == "G" and board[a][col + 1] == "G" and board[a][col + 2] == "G" and board[a][col + 3] == "G": print("Spieler 2 hat gewonnen") Gewinner = True
Connect 4 grid
board = []
for i in range(6): board.append(["0"]*7)
m = 7 print(" "3 + (" "3).join(["{}".format(i) for i in range(0,m)])) for j,bb in enumerate(board): print("{}: ".format(j) + " | ".join(bb))
Gewinner = False Rz = 0 i = 5 x = 6 a = 6 col = 0 while(Gewinner==False): if Rz % 2 == 0: col = int(input("Spieler 1 gib eine Zahl(0-6) für die spalte(0-6) ein:" )) if board[i][col] == "0": board[i][col] = "R" x = 5 else: if board[i-1][col]== "0": board[i-1][col]= "R" x = 4 else: if board[i - 2][col] == "0": board[i - 2][col] = "R" x = 3 else: if board[i - 3][col] == "0": board[i - 3][col] = "R" x = 2 else: if board[i - 4][col] == "0": board[i - 4][col] = "R" x = 1 else: board[i - 5][col] = "R" x = 0