mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Added is_game_finished
I have absolutely no idea if it works..
This commit is contained in:
@@ -56,6 +56,18 @@ def main():
|
|||||||
print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
||||||
print_instructions()
|
print_instructions()
|
||||||
play_game()
|
play_game()
|
||||||
|
|
||||||
|
def is_game_finished(board):
|
||||||
|
for pos in board.keys():
|
||||||
|
if board[pos] == "X":
|
||||||
|
for space in [1,9]:
|
||||||
|
nextToPeg = ((pos + space) in board) and board[pos + space]
|
||||||
|
hasMovableSpace = (not ((pos - space) in board and board[pos - space])) or (not ((pos + space * 2) in board and board[pos + space * 2]))
|
||||||
|
if nextToPeg and hasMovableSpace:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user