diff --git a/douzero/server/battle.py b/douzero/server/battle.py index 70c720d..a8948bb 100644 --- a/douzero/server/battle.py +++ b/douzero/server/battle.py @@ -97,7 +97,7 @@ def battle_logic(baseline : Baseline, battle : Battle): def tick(): try: - battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(10) + battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.asc()).limit(1) for battle in battles: battle.status = -1 battle.save() diff --git a/evaluate_server.py b/evaluate_server.py index 68f3159..91f7bca 100644 --- a/evaluate_server.py +++ b/evaluate_server.py @@ -1,5 +1,7 @@ import itertools import os +import time +import threading from peewee import JOIN @@ -19,9 +21,6 @@ Model.create_table() Battle.create_table() Baseline.create_table() -threadpool = ThreadPoolExecutor(1) - - EnvCard2RealCard = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'T', 11: 'J', 12: 'Q', 13: 'K', 14: 'A', 17: '2', 20: 'X', 30: 'D'} @@ -49,9 +48,17 @@ def upload(): model_file.save(path) Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now()) Battle.create(challenger_path=path, challenger_position=position, status=0) - threadpool.submit(tick) return jsonify({'status': 0, 'message': 'success', 'result': ''}) +def start_runner(): + def start_loop(): + while True: + tick() + time.sleep(10) + + thread = threading.Thread(target=start_loop) + thread.start() + @app.route('/battle_tick', methods=['POST']) def battle_tick(): tick()