diff --git a/douzero/server/battle.py b/douzero/server/battle.py index a8948bb..7b634b0 100644 --- a/douzero/server/battle.py +++ b/douzero/server/battle.py @@ -10,17 +10,20 @@ positions = ['landlord', 'landlord_up', 'landlord_front', 'landlord_down'] idx_position = {0: 'landlord', 1: 'landlord_down', 2: 'landlord_front', 3:'landlord_up'} position_idx = {'landlord': 0, 'landlord_down': 1, 'landlord_front': 2, 'landlord_up': 3} -baselines = Baseline.select().order_by(Baseline.rank.desc()).limit(1) baseline_players = [None, None, None, None] -if len(baselines) >= 1: - baseline = baselines[0] - try: - baseline_players[0] = DeepAgent('landlord', str(baseline.landlord_path), use_onnx=True) - baseline_players[1] = DeepAgent('landlord_down', str(baseline.landlord_down_path), use_onnx=True) - baseline_players[2] = DeepAgent('landlord_front', str(baseline.landlord_front_path), use_onnx=True) - baseline_players[3] = DeepAgent('landlord_up', str(baseline.landlord_up_path), use_onnx=True) - except: - pass + +def init_battlefield(flags): + global baseline_players + baselines = Baseline.select().order_by(Baseline.rank.desc()).limit(1) + if len(baselines) >= 1: + baseline = baselines[0] + try: + baseline_players[0] = DeepAgent('landlord', str(baseline.landlord_path), use_onnx=True) + baseline_players[1] = DeepAgent('landlord_down', str(baseline.landlord_down_path), use_onnx=True) + baseline_players[2] = DeepAgent('landlord_front', str(baseline.landlord_front_path), use_onnx=True) + baseline_players[3] = DeepAgent('landlord_up', str(baseline.landlord_up_path), use_onnx=True) + except: + pass def battle_logic(baseline : Baseline, battle : Battle): eval_data_first = 'eval_data_200.pkl' diff --git a/douzero/server/orm.py b/douzero/server/orm.py index 575fbf8..24a44a7 100644 --- a/douzero/server/orm.py +++ b/douzero/server/orm.py @@ -1,7 +1,14 @@ # -*- coding:utf8 -*- from peewee import * -db = MySQLDatabase('dou_model', host='192.168.1.88', user='douzero', passwd='VwjT6e0qf2t9iOH0') +db = MySQLDatabase(None) + +def init_db(flags): + db.init(flags.db_schema, host=flags.db_host, user=flags.db_user, passwd=flags.db_passwd) + Model.create_table() + Battle.create_table() + Baseline.create_table() + class BaseModel(Model): class Meta: diff --git a/evaluate_server.py b/evaluate_server.py index f86e3e3..ce4c7a6 100644 --- a/evaluate_server.py +++ b/evaluate_server.py @@ -5,8 +5,8 @@ import threading from peewee import JOIN -from douzero.server.orm import Model, Battle, Baseline -from douzero.server.battle import tick, baseline_players, positions, idx_position +from douzero.server.orm import init_db, Model, Battle, Baseline +from douzero.server.battle import init_battlefield, tick, baseline_players, positions, idx_position from flask import Flask, jsonify, request from flask_cors import CORS from datetime import datetime @@ -16,10 +16,6 @@ from douzero.env.game import get_legal_card_play_actions app = Flask(__name__) CORS(app) -Model.create_table() -Battle.create_table() -Baseline.create_table() - 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'} @@ -278,6 +274,14 @@ if __name__ == '__main__': import argparse parser = argparse.ArgumentParser(description='DouZero evaluation backend') parser.add_argument('--debug', action='store_true') + parser.add_argument('--enable_task', type=bool) + parser.add_argument('--db_host', type=str, default='127.0.0.1') + parser.add_argument('--db_schema', type=str, default='dou_model') + parser.add_argument('--db_user', type=str, default='douzero') + parser.add_argument('--db_passwd', type=str, default='VwjT6e0qf2t9iOH0') args = parser.parse_args() - start_runner() + init_db(args) + init_battlefield(args) + if args.enable_task: + start_runner() app.run(debug=args.debug, host="0.0.0.0") diff --git a/static/charts.html b/static/charts.html index 9943260..59f8577 100644 --- a/static/charts.html +++ b/static/charts.html @@ -2,6 +2,10 @@
+ + + +