From d10601b55444680bf15a098fcdac16307e0b8604 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 9 Dec 2017 21:21:24 -0800 Subject: [PATCH] TicTacToe: Refactor new-game handling into existing section. Also extend storage-update section; all related storage.put calls are now together. --- zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py index 68a31f4..5460fcf 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py @@ -283,14 +283,15 @@ class ticTacToeHandler(object): if not storage.contains(original_sender): storage.put(original_sender, None) user_board = storage.get(original_sender) - if (not user_board) and command == "new": - user_board = copy.deepcopy(initial_board) - storage.put(original_sender, user_board) user_game = TicTacToeGame(user_board) if user_board else None move = None if command == 'new': - if user_game and not first_time(user_game.board): + if not user_board: + user_board = copy.deepcopy(initial_board) + user_game = TicTacToeGame(user_board) + move = "new" + if not first_time(user_game.board): return_content = "You're already playing a game! Type **@tictactoe help** or **@ttt help** to see valid inputs." else: return_content = "Welcome to tic-tac-toe! You'll be x's and I'll be o's. Your move first!\n" @@ -308,7 +309,7 @@ class ticTacToeHandler(object): if move is not None: if any(reset_text in move for reset_text in ("win", "draw", "quit")): storage.put(original_sender, None) - elif move is "next_turn": + elif any(keep_text == move for keep_text in ("new", "next_turn")): storage.put(original_sender, user_board) else: # "filled" => no change, user_board remains the same pass