From d7939d35df539c7c1bb73db56edc0c4b44bd24b6 Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Thu, 26 May 2022 10:11:54 +0800 Subject: [PATCH] update --- README.md | 4 ++-- config.py | 5 +++-- src/game.py | 30 ++++++++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index faeb4f8..d353ab9 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # **Easy Game** [comment]: <> (![python](https://img.shields.io/pypi/pyversions/pygame)) -![pygame](https://img.shields.io/badge/release-2.0.0beta-red.svg) +![pygame](https://img.shields.io/badge/release-1.2.1-red.svg) [![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/) -[![MLGame](https://img.shields.io/badge/MLGame-9.5.1-.svg)](https://github.com/PAIA-Playful-AI-Arena/MLGame) +[![MLGame](https://img.shields.io/badge/MLGame-9.4.0-.svg)](https://github.com/PAIA-Playful-AI-Arena/MLGame) [![pygame](https://img.shields.io/badge/pygame-2.0.1-.svg)](https://github.com/pygame/pygame/releases/tag/2.0.1) diff --git a/config.py b/config.py index d9f3e6c..3cad48b 100644 --- a/config.py +++ b/config.py @@ -2,8 +2,8 @@ import sys from os import path sys.path.append(path.dirname(__file__)) -from mlgame.argument.tool import read_json_file, parse_config -from src.game import EasyGame +from mlgame.utils.parse_config import read_json_file, parse_config +from .src.game import EasyGame config_file = path.join(path.dirname(__file__), "game_config.json") @@ -16,5 +16,6 @@ GAME_PARAMS = parse_config(config_data) GAME_SETUP = { "game": EasyGame, + "ml_clients": EasyGame.ai_clients(), # "dynamic_ml_clients":True } diff --git a/src/game.py b/src/game.py index dbd59d8..85f4f90 100644 --- a/src/game.py +++ b/src/game.py @@ -3,9 +3,8 @@ from os import path import pygame -from mlgame.argument.model import AI_NAMES -from mlgame.gamedev.paia_game import PaiaGame, GameResultState, GameStatus -from mlgame.tests.test_decorator import check_game_progress, check_game_result +from mlgame.gamedev.game_interface import PaiaGame, GameResultState, GameStatus +from mlgame.view.test_decorator import check_game_progress, check_game_result from mlgame.view.view_model import create_text_view_data, create_asset_init_data, create_image_view_data, Scene, \ create_scene_progress_data from .game_object import Ball, Food @@ -35,13 +34,9 @@ class EasyGame(PaiaGame): def update(self, commands): # handle command - ai_1p_cmd = commands[AI_NAMES[0]] - if ai_1p_cmd is not None: - action = ai_1p_cmd[0] - else: - action = "NONE" + ai_1p_cmd = commands[self.ai_clients()[0]["name"]][0] # print(ai_1p_cmd) - self.ball.update(action) + self.ball.update(ai_1p_cmd) # update sprite self.foods.update() @@ -77,7 +72,8 @@ class EasyGame(PaiaGame): "status": self.get_game_status() } - to_players_data[AI_NAMES[0]] = data_to_1p + for ai_client in self.ai_clients(): + to_players_data[ai_client['name']] = data_to_1p # should be equal to config. GAME_SETUP["ml_clients"][0]["name"] return to_players_data @@ -143,7 +139,7 @@ class EasyGame(PaiaGame): "state": self.game_result_state, "attachment": [ { - "player": AI_NAMES[0], + "player": self.ai_clients()[0]["name"], "rank": 1, "score": self.score } @@ -167,7 +163,8 @@ class EasyGame(PaiaGame): cmd_1p.append("RIGHT") else: cmd_1p.append("NONE") - return {AI_NAMES[0]: cmd_1p} + ai_1p = self.ai_clients()[0]["name"] + return {ai_1p: cmd_1p} def _create_foods(self, count: int = 5): for i in range(count): @@ -175,3 +172,12 @@ class EasyGame(PaiaGame): food = Food(self.foods) pass + @staticmethod + def ai_clients(): + """ + let MLGame know how to parse your ai, + you can also use this names to get different cmd and send different data to each ai client + """ + return [ + {"name": "1P"} + ]