From a29e9bd8cf2dd021c4bfb66f7b35078938eeb70b Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 30 Sep 2017 13:55:08 -0700 Subject: [PATCH] Set TTT_DEBUG to 1 Print some extra stuff when TTT_DEBUG is 1 --- .env | 1 + tictactoe.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 344dc13..1fdf296 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ FLASK_APP=tictactoe.py +TTT_DEBUG=1 diff --git a/tictactoe.py b/tictactoe.py index 8f9a170..0b5b4b7 100644 --- a/tictactoe.py +++ b/tictactoe.py @@ -1,3 +1,4 @@ +import os from flask import Flask, abort, request BOARD_SIZE = 9 @@ -171,10 +172,11 @@ def hello(): return ("It isn't O's turn.\n\n{}".format(board), 400, {'Content-type': 'text/plain'}) next_board = board.move() - out = '''{} - -Score: {} - -Next: -{}'''.format(board, board.evaluate(), next_board) + out = str(next_board) + if bool(os.environ.get('TTT_DEBUG', False)): + import pprint + out += '\n\n---------- DEBUG ----------' + out += '\n\nInput:\n{}'.format(board) + out += '\n\nScore: {}'.format(board.score) + out += '\n\nChildren:\n{}'.format(pprint.pformat(board.children)) return (out, 200, {'Content-type': 'text/plain'})