Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Created August 29, 2023 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masouduut94/f576396f3b0aefceb9673ae5124cedbc to your computer and use it in GitHub Desktop.
Save masouduut94/f576396f3b0aefceb9673ae5124cedbc to your computer and use it in GitHub Desktop.
def would_lose(self, cell: tuple, color: int) -> bool:
"""
Return True is the move indicated by cell and color would lose the game,
False otherwise.
"""
connect1 = False
connect2 = False
if color == GameMeta.PLAYERS['black']:
if cell[1] == 0:
connect1 = True
elif cell[1] == self.size - 1:
connect2 = True
for n in self.neighbors(cell):
if self.black_groups.connected(GameMeta.EDGE1, n):
connect1 = True
elif self.black_groups.connected(GameMeta.EDGE2, n):
connect2 = True
elif color == GameMeta.PLAYERS['white']:
if cell[0] == 0:
connect1 = True
elif cell[0] == self.size - 1:
connect2 = True
for n in self.neighbors(cell):
if self.white_groups.connected(GameMeta.EDGE1, n):
connect1 = True
elif self.white_groups.connected(GameMeta.EDGE2, n):
connect2 = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment