From 4272ddc7d102ed3a11618f2bd46be5e60ab0b90a Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Fri, 6 May 2022 09:26:57 +0800 Subject: [PATCH] add description and logo on game_config.json --- README.md | 8 ++--- ai_clients/__init__.py | 0 ai_clients/client_template.py | 24 --------------- ai_clients/client_with_error_in_update.py | 26 ---------------- ai_clients/client_with_unvalid_import.py | 24 --------------- asset/logo.svg | 1 + config.py | 10 +++---- game_config.json | 9 ++++-- ai_clients/manual.py => ml/ml_play_manual.py | 10 ++++--- .../ml_play_template.py | 3 +- src/game.py | 30 +++++++++++-------- 11 files changed, 42 insertions(+), 103 deletions(-) delete mode 100644 ai_clients/__init__.py delete mode 100644 ai_clients/client_template.py delete mode 100644 ai_clients/client_with_error_in_update.py delete mode 100644 ai_clients/client_with_unvalid_import.py create mode 100644 asset/logo.svg rename ai_clients/manual.py => ml/ml_play_manual.py (78%) rename ai_clients/client_with_syntax_error.py => ml/ml_play_template.py (92%) diff --git a/README.md b/README.md index faeb4f8..e3cd5c9 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # **Easy Game** +logo [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.1.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) - - +--- 這是一個吃東西小遊戲,也是 PAIA 的遊戲教學範例 ![https://github.com/PAIA-Playful-AI-Arena/MLGame/raw/master/games/easy_game/asset/easy_game.gif](https://github.com/PAIA-Playful-AI-Arena/MLGame/raw/master/games/easy_game/asset/easy_game.gif) diff --git a/ai_clients/__init__.py b/ai_clients/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ai_clients/client_template.py b/ai_clients/client_template.py deleted file mode 100644 index 41fbe77..0000000 --- a/ai_clients/client_template.py +++ /dev/null @@ -1,24 +0,0 @@ -import random - - -class MLPlay: - def __init__(self, ai_name:str,*args, **kwargs): - print(f"Initial {__file__} script with ai_name:{ai_name}") - - - def update(self, scene_info: dict, *args, **kwargs): - """ - Generate the command according to the received scene information - """ - # print("AI received data from game :", json.dumps(scene_info)) - # print(scene_info) - actions = ["UP", "DOWN", "LEFT", "RIGHT"] - - return random.sample(actions, 1) - - def reset(self): - """ - Reset the status - """ - print("reset ml script") - pass diff --git a/ai_clients/client_with_error_in_update.py b/ai_clients/client_with_error_in_update.py deleted file mode 100644 index 5f9c4ce..0000000 --- a/ai_clients/client_with_error_in_update.py +++ /dev/null @@ -1,26 +0,0 @@ -import random - - -class MLPlay: - def __init__(self, *args, **kwargs): - print("Initial ml script") - self.count=0 - - def update(self, scene_info: dict, *args, **kwargs): - """ - Generate the command according to the received scene information - """ - # print("AI received data from game :", json.dumps(scene_info)) - # print(scene_info) - actions = ["UP", "DOWN", "LEFT", "RIGHT"] - self.count+=1 - if self.count >100: - a = actions[100] - return random.sample(actions, 1) - - def reset(self): - """ - Reset the status - """ - print("reset ml script") - pass diff --git a/ai_clients/client_with_unvalid_import.py b/ai_clients/client_with_unvalid_import.py deleted file mode 100644 index 4c16862..0000000 --- a/ai_clients/client_with_unvalid_import.py +++ /dev/null @@ -1,24 +0,0 @@ -import random -import aaa - - -class MLPlay: - def __init__(self, *args, **kwargs): - print("Initial ml script") - - def update(self, scene_info: dict, *args, **kwargs): - """ - Generate the command according to the received scene information - """ - # print("AI received data from game :", json.dumps(scene_info)) - # print(scene_info) - actions = ["UP", "DOWN", "LEFT", "RIGHT"] - - return random.sample(actions, 1) - - def reset(self): - """ - Reset the status - """ - print("reset ml script") - pass diff --git a/asset/logo.svg b/asset/logo.svg new file mode 100644 index 0000000..687a4ad --- /dev/null +++ b/asset/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/config.py b/config.py index d9f3e6c..afc979b 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,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 os import path + +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 +15,6 @@ GAME_PARAMS = parse_config(config_data) GAME_SETUP = { "game": EasyGame, + "ml_clients": EasyGame.ai_clients(), # "dynamic_ml_clients":True } diff --git a/game_config.json b/game_config.json index 90add02..67bd99d 100644 --- a/game_config.json +++ b/game_config.json @@ -1,7 +1,12 @@ { "game_name": "easy_game", - "version": "2.0.0-beta", - "url": "None", + "version": "1.1.1", + "url": "https://github.com/PAIA-Playful-AI-Arena/easy_game", + "description": "這是一個吃東西小遊戲,也是 PAIA 的遊戲教學範例", + "logo": [ + "./asset/logo.svg", + "https://raw.githubusercontent.com/PAIA-Playful-AI-Arena/Paia-Desktop/master/media/easygame.svg" + ], "game_params": [ { "name": "time_to_play", diff --git a/ai_clients/manual.py b/ml/ml_play_manual.py similarity index 78% rename from ai_clients/manual.py rename to ml/ml_play_manual.py index e85c808..5c612fe 100644 --- a/ai_clients/manual.py +++ b/ml/ml_play_manual.py @@ -1,12 +1,12 @@ +import random import pygame class MLPlay: - def __init__(self, ai_name: str, *args, **kwargs): - self.ai_name = ai_name - print(f"Initial {__file__} script with ai_name:{ai_name}") + def __init__(self): + print("Initial ml script") - def update(self, scene_info: dict, keyboard: list = [], *args, **kwargs): + def update(self, scene_info: dict, keyboard:list=[], *args, **kwargs): """ Generate the command according to the received scene information """ @@ -28,6 +28,8 @@ class MLPlay: return actions + + def reset(self): """ Reset the status diff --git a/ai_clients/client_with_syntax_error.py b/ml/ml_play_template.py similarity index 92% rename from ai_clients/client_with_syntax_error.py rename to ml/ml_play_template.py index 507adb1..02efb26 100644 --- a/ai_clients/client_with_syntax_error.py +++ b/ml/ml_play_template.py @@ -1,7 +1,6 @@ import random - class MLPlay: - def __init__(self, *args, **kwargs) + def __init__(self): print("Initial ml script") def update(self, scene_info: dict, *args, **kwargs): 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"} + ]