From e6b017985eea4f3f8b28dc48dbb820440ba95725 Mon Sep 17 00:00:00 2001 From: yanshaoting Date: Tue, 12 Mar 2024 15:01:54 +0800 Subject: [PATCH] 2P manual --- ml/ml_play_manual_2P.py | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ml/ml_play_manual_2P.py diff --git a/ml/ml_play_manual_2P.py b/ml/ml_play_manual_2P.py new file mode 100644 index 0000000..e814e87 --- /dev/null +++ b/ml/ml_play_manual_2P.py @@ -0,0 +1,42 @@ +import random +from pprint import pprint + +import orjson +import pygame + + +class MLPlay: + def __init__(self,ai_name,*args,**kwargs): + print("Initial ml script") + + def update(self, scene_info: dict, keyboard:list=[], *args, **kwargs): + """ + Generate the command according to the received scene information + """ + # pprint("AI received data from game :", orjson.dumps(scene_info)) + # pprint(scene_info) + actions = [] + + if pygame.K_w in keyboard: + actions.append("UP") + elif pygame.K_s in keyboard: + actions.append("DOWN") + + elif pygame.K_a in keyboard: + actions.append("LEFT") + + elif pygame.K_d in keyboard: + actions.append("RIGHT") + else: + actions.append("NONE") + + return actions + + + + def reset(self): + """ + Reset the status + """ + print("reset ml script") + pass