def evaluate( game, player): if(game._statskey_forced): start = dt.datetime.now() result_row = 0 for r in game.ROWS: r = max_continuous( [game.board[r,c] for c in game.COLS], player ) result_row = max( result_row, r ) # print result_row result_col = 0 for c in game.COLS: r = max_continuous( [game.board[r,c] for r in game.ROWS], player ) result_col = max( result_col, r ) # print result_col result_d1 = 0 for d1 in game.DIAG: r = max_continuous( [game.board[m.row,m.col] for m in game.DIAG1(d1)], player ) result_d1 = max( result_d1, r ) # print result_d1 result_d2 = 0 for d2 in game.DIAG: r = max_continuous( [game.board[m.row,m.col] for m in game.DIAG2(d2)], player ) result_d2 = max( result_d2, r ) # print result_d2 if(game._statskey_forced): end = dt.datetime.now() stats.collect(game._statskey_forced, (end-start).total_seconds()) return max( result_row, result_col, result_d1, result_d2 )
def evaluate_cached(game, player): if (game._statskey_cached): start = dt.datetime.now() k = (game.board.hash << 2) + (player % 4) if (not game._cache.has_key(k)): v = game.evaluate(player) game._cache[k] = v if (game._statskey_cached): end = dt.datetime.now() stats.collect(game._statskey_cached, (end - start).total_seconds()) return game._cache[k]
def evaluate_cached(game, player): if(game._statskey_cached): start = dt.datetime.now() k = (game.board.hash << 2)+(player%4) if( not game._cache.has_key( k ) ): v = game.evaluate(player) game._cache[k] = v if(game._statskey_cached): end = dt.datetime.now() stats.collect(game._statskey_cached, (end-start).total_seconds()) return game._cache[k]
def evaluate(game, player): if (game._statskey_forced): start = dt.datetime.now() result_row = 0 for r in game.ROWS: r = max_continuous([game.board[r, c] for c in game.COLS], player) result_row = max(result_row, r) # print result_row result_col = 0 for c in game.COLS: r = max_continuous([game.board[r, c] for r in game.ROWS], player) result_col = max(result_col, r) # print result_col result_d1 = 0 for d1 in game.DIAG: r = max_continuous( [game.board[m.row, m.col] for m in game.DIAG1(d1)], player) result_d1 = max(result_d1, r) # print result_d1 result_d2 = 0 for d2 in game.DIAG: r = max_continuous( [game.board[m.row, m.col] for m in game.DIAG2(d2)], player) result_d2 = max(result_d2, r) # print result_d2 if (game._statskey_forced): end = dt.datetime.now() stats.collect(game._statskey_forced, (end - start).total_seconds()) return max(result_row, result_col, result_d1, result_d2)
from datetime import datetime import requests import stats if __name__=="__main__": print "Starting to collect stats..." while True: t = localtime() time = ":".join([str(t) for t in [t.tm_hour,t.tm_min,t.tm_sec]]) print "Collecting stats at "+time now = str(datetime.utcnow()) date = now[:11] time = "-".join(now[-15:-7].split(":")) filename = "stats/records/"+date+"/"+time+".json" dirname = os.path.dirname(filename) if not os.path.exists(dirname): os.makedirs(dirname) # collect and record stats, silently failing if we don't have an internet connection try: stats.record(*stats.collect(), filename=filename) except requests.exceptions.ConnectionError: pass # sleep for 30 mins sleep(1800)