mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 17:17:59 -08:00
Added is_game_finished
I have absolutely no idea if it works..
This commit is contained in:
@@ -57,5 +57,17 @@ def main():
|
|||||||
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