def main(): init_log() args = parse_args() count = 1000 server_list = ["127.0.0.1"] file_name = "default_policy_tree.csv" if args.file != None: file_name = args.file else: logging.info("Will use default file: " + file_name) if args.build == True: if args.flag != None: handle_flag = int(args.flag) else: print("Must set flag") return if args.count != None: count = int(args.count) if args.addr != None: server_list = str(args.addr).split(",") borad_size = 11 win_length = 5 db_type = "cassandra" game_history = CassandraGameHistory() game_history.set_board_size(borad_size) game_history.set_win_length(win_length) game_history.connect("games", server_list) tree_mgr = TreeMgr() build_policy_tree_from_history(game_history, tree_mgr, handle_flag, count) tree_mgr.dump_tree_nodes(file_name, 1) game_history.disconnect() if args.load == True: tree_mgr = TreeMgr() tree_mgr.load_tree_nodes(file_name) tree_mgr.stat_tree_nodes() if args.filter == True: new_file = file_name.replace(".csv", "_new.csv") if args.newfile != None: new_file = args.newfile tree_mgr = TreeMgr() tree_mgr.load_tree_nodes(file_name) tree_mgr.stat_tree_nodes() tree_mgr.dump_tree_nodes(new_file, 1)
logging.info("test_select_steps_from_history:") sqlite_file = "../sqlite_game_history.db" game_history = SqliteGameHistory() game_history.connect(sqlite_file) game_history.select_steps_from_history() game_history.disconnect() class TestFunction(unittest.TestCase): def test_convert_location_1(self): i, j = convert_location(55, 11) print("test_convert_location_1 i,j",i, j) self.assertEqual(i, 0) self.assertEqual(j, 5) i, j = convert_location(73, 11) print("test_convert_location_1 i,j",i, j) self.assertEqual(i, 7) self.assertEqual(j, 6) i, j = convert_location(46, 11) print("test_convert_location_1 i,j",i, j) self.assertEqual(i, 2) self.assertEqual(j, 4) if __name__ == '__main__': function.init_log() unittest.main()
move = int(request.json["move"]) if game_id in game_map: game_map[game_id].play(move) else: return "can't find game" + str(game_id), 404 return "play with move" + str(move), 200 #return "Play Game!" + str(count) @app.route("/nextstep", methods=['POST']) def next_step(): logging.debug("nextstep request: " + str(request.json)) game_id = request.json["game_id"] move = -1 if game_id in game_map: move, winner = game_map[game_id].try_to_get_next_step() return jsonify({ 'game_id': game_id, 'move': move, 'winner': winner }), 200 else: return "can't find game" + str(game_id), 404 #FLASK_APP=server.py flask run #FLASK_APP=server.py flask run --host=0.0.0.0 --port=8080 if __name__ == '__main__': init_log() logging.info("server starting...") app.run(debug=True)