Skip to content

Commit d7b56bc

Browse files
authored
added case in which the game is draw
# line 132-135 def end_game_draw(self): if 0 not in self.field[0]: return True return False # line 182-192 draw = game.end_game_draw() if draw: print("The game is draw!") restart = input("type \"r\" to restart the game: ").lower() if restart == "r": start_game() else: break
1 parent 4763eb7 commit d7b56bc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Advanced/6.Workshop/Workshop - Lab/connect4.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def append_to_column(self):
129129
self.players.append(player)
130130
return [self.check_win(player), player]
131131

132+
def end_game_draw(self):
133+
if 0 not in self.field[0]:
134+
return True
135+
return False
136+
132137

133138
def start_game():
134139
matrix = [[0] * 7 for _ in range(6)]
@@ -174,5 +179,17 @@ def play(matrix, players):
174179
else:
175180
break
176181

182+
draw = game.end_game_draw()
183+
184+
if draw:
185+
print("The game is draw!")
186+
187+
restart = input("type \"r\" to restart the game: ").lower()
188+
if restart == "r":
189+
start_game()
190+
191+
else:
192+
break
193+
177194

178-
start_game()
195+
start_game()

0 commit comments

Comments
 (0)