def get(self): board = utils.string_to_list(self.request.get('board')) next_move = -1 # check if they sent you a full board, this will happen if the player went first. if tictactoe.is_full_board(board): # if they did, just check the game state. game_state, message = tictactoe.get_game_state(board) else: try: next_move = tictactoe.get_move(board, config.COMPUTER) new_board = tictactoe.make_move(board, next_move, config.COMPUTER) game_state, message = tictactoe.get_game_state(new_board) except Exception as e: game_state, message = config.ERROR, e.message result = {'move': next_move, 'game_state': game_state, 'message': message} self.render_json(result)
def test_is_full(self): board = new_board() for i in range(9): self.assertFalse(tictactoe.is_full_board(board)) board[i] = 1 self.assertTrue(tictactoe.is_full_board(board))