feat:提供玩家的速度尺寸給AI
This commit is contained in:
parent
29c7463fe7
commit
35bcd39023
12
README.md
12
README.md
|
@ -101,8 +101,10 @@ class MLPlay:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"frame": 25,
|
"frame": 25,
|
||||||
"ball_x": 425,
|
"player_x": 425,
|
||||||
"ball_y": 306,
|
"player_y": 306,
|
||||||
|
"player_size": 90,
|
||||||
|
"player_vel": 16,
|
||||||
"foods": [
|
"foods": [
|
||||||
{
|
{
|
||||||
"x": 656,
|
"x": 656,
|
||||||
|
@ -125,8 +127,10 @@ class MLPlay:
|
||||||
```
|
```
|
||||||
|
|
||||||
- `frame`:遊戲畫面更新的編號
|
- `frame`:遊戲畫面更新的編號
|
||||||
- `ball_x`:主角方塊的X座標,表示方塊的左邊座標值。
|
- `player_x`:主角方塊的X座標,表示方塊的`中心點`座標值,單位 pixel。
|
||||||
- `ball_y`:主角方塊的Y座標,表示方塊的上方座標值。
|
- `player_y`:主角方塊的Y座標,表示方塊的`中心點`座標值,單位 pixel。
|
||||||
|
- `player_size`:主角方塊的大小,表示方塊的長寬,單位 pixel。
|
||||||
|
- `player_vel`:主角方塊的速度,表示方塊每幀移動的像素,單位 pixel。
|
||||||
- `foods`:食物的清單,清單內每一個物件都是一個食物的左上方座標值,也會提供此食物是什麼類型和分數多少。
|
- `foods`:食物的清單,清單內每一個物件都是一個食物的左上方座標值,也會提供此食物是什麼類型和分數多少。
|
||||||
- `type` 食物類型: `GOOD_1`, `GOOD_2`, `GOOD_3`, `BAD_1`, `BAD_2`, `BAD_3`
|
- `type` 食物類型: `GOOD_1`, `GOOD_2`, `GOOD_3`, `BAD_1`, `BAD_2`, `BAD_3`
|
||||||
- `score`:目前得到的分數
|
- `score`:目前得到的分數
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
"SCENE_INFO": [
|
"SCENE_INFO": [
|
||||||
["scene_info['frame']", "# frame", "# 幀數"],
|
["scene_info['frame']", "# frame", "# 幀數"],
|
||||||
["scene_info['status']", "game status", "遊戲狀態"],
|
["scene_info['status']", "game status", "遊戲狀態"],
|
||||||
["scene_info['ball_x']", "x coordinate of ball", "球的 x 座標"],
|
["scene_info['player_x']", "x coordinate of player", "玩家角色的 x 座標"],
|
||||||
["scene_info['ball_y']", "y coordinate of ball", "球的 y 座標"],
|
["scene_info['player_y']", "y coordinate of player", "玩家角色的 y 座標"],
|
||||||
|
["scene_info['player_size']", "y coordinate of player", "玩家角色的大小"],
|
||||||
|
["scene_info['player_vel']", "velocity of player", "玩家角色的速度"],
|
||||||
["scene_info['score']", "score", "目前的分數"],
|
["scene_info['score']", "score", "目前的分數"],
|
||||||
["scene_info['foods']", "list of foods positions", "點點的位置清單"],
|
["scene_info['foods']", "list of foods positions", "點點的位置清單"],
|
||||||
["scene_info['score_to_pass']", "the score for next level", "通關分數"],
|
["scene_info['score_to_pass']", "the score for next level", "通關分數"],
|
||||||
|
@ -21,8 +23,7 @@
|
||||||
[800, "right boundary", "右邊界"],
|
[800, "right boundary", "右邊界"],
|
||||||
[0, "top boundary", "上邊界"],
|
[0, "top boundary", "上邊界"],
|
||||||
[600, "bottom boundary", "下邊界"],
|
[600, "bottom boundary", "下邊界"],
|
||||||
[30, "ball width", "球身的寬度"],
|
[30, "player size", "玩家角色的初始大小"],
|
||||||
[30, "ball height", "球身的高度"],
|
|
||||||
[8, "food lv1 size", "等級一食物的寬高度"],
|
[8, "food lv1 size", "等級一食物的寬高度"],
|
||||||
[12, "food lv2 size", "等級二食物的高度"],
|
[12, "food lv2 size", "等級二食物的高度"],
|
||||||
[16, "food lv3 size", "等級三食物的高度"]
|
[16, "food lv3 size", "等級三食物的高度"]
|
||||||
|
|
13
src/game.py
13
src/game.py
|
@ -82,7 +82,6 @@ class EasyGame(PaiaGame):
|
||||||
self.ball = Ball()
|
self.ball = Ball()
|
||||||
self.foods.empty()
|
self.foods.empty()
|
||||||
|
|
||||||
# todo validate food count
|
|
||||||
if not isinstance(self._good_food_count,list) or len(self._good_food_count)<3:
|
if not isinstance(self._good_food_count,list) or len(self._good_food_count)<3:
|
||||||
raise Exception("你的關卡檔案格式有誤,請在'good_food_count' 欄位後面填入一個長度為3的陣列,舉例: [1,2,3]")
|
raise Exception("你的關卡檔案格式有誤,請在'good_food_count' 欄位後面填入一個長度為3的陣列,舉例: [1,2,3]")
|
||||||
elif not isinstance(self._bad_food_count, list) or len(self._bad_food_count) < 3:
|
elif not isinstance(self._bad_food_count, list) or len(self._bad_food_count) < 3:
|
||||||
|
@ -148,16 +147,18 @@ class EasyGame(PaiaGame):
|
||||||
to_players_data = {}
|
to_players_data = {}
|
||||||
foods_data = []
|
foods_data = []
|
||||||
for food in self.foods:
|
for food in self.foods:
|
||||||
|
# TODO 確認要提供中心點座標還是左上角座標。
|
||||||
foods_data.append({"x": food.rect.x, "y": food.rect.y, "type": food.type, "score": food.score})
|
foods_data.append({"x": food.rect.x, "y": food.rect.y, "type": food.type, "score": food.score})
|
||||||
# TODO add velocity and ball_size
|
|
||||||
# TODO change ball to player
|
|
||||||
|
|
||||||
data_to_1p = {
|
data_to_1p = {
|
||||||
"frame": self.frame_count,
|
"frame": self.frame_count,
|
||||||
"ball_x": self.ball.rect.centerx,
|
# TODO 確認要提供中心點座標還是左上角座標。
|
||||||
"ball_y": self.ball.rect.centery,
|
"player_x": self.ball.rect.centerx,
|
||||||
|
"player_y": self.ball.rect.centery,
|
||||||
|
"player_size":self.ball.rect.width,
|
||||||
|
"player_vel":self.ball.vel,
|
||||||
"foods": foods_data,
|
"foods": foods_data,
|
||||||
|
|
||||||
"score": self.ball.score,
|
"score": self.ball.score,
|
||||||
"score_to_pass":self._score_to_pass,
|
"score_to_pass":self._score_to_pass,
|
||||||
"status": self.get_game_status()
|
"status": self.get_game_status()
|
||||||
|
|
|
@ -19,7 +19,6 @@ class Ball(pygame.sprite.Sprite):
|
||||||
self._score = 0
|
self._score = 0
|
||||||
self._vel = BALL_VEL
|
self._vel = BALL_VEL
|
||||||
|
|
||||||
|
|
||||||
def update(self, motion):
|
def update(self, motion):
|
||||||
# for motion in motions:
|
# for motion in motions:
|
||||||
if motion == "UP":
|
if motion == "UP":
|
||||||
|
@ -33,7 +32,6 @@ class Ball(pygame.sprite.Sprite):
|
||||||
self.rect.centerx += self._vel
|
self.rect.centerx += self._vel
|
||||||
# self.angle -= 5
|
# self.angle -= 5
|
||||||
|
|
||||||
|
|
||||||
# self.image = pygame.transform.rotate(self.origin_image, self.angle)
|
# self.image = pygame.transform.rotate(self.origin_image, self.angle)
|
||||||
# print(self.angle)
|
# print(self.angle)
|
||||||
# center = self.rect.center
|
# center = self.rect.center
|
||||||
|
@ -58,7 +56,10 @@ class Ball(pygame.sprite.Sprite):
|
||||||
self.rect.height = min(BALL_H + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX)
|
self.rect.height = min(BALL_H + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX)
|
||||||
self._vel = min(BALL_VEL + lv * BALL_GROWTH_VEL_STEP, BALL_VEL_MAX)
|
self._vel = min(BALL_VEL + lv * BALL_GROWTH_VEL_STEP, BALL_VEL_MAX)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def score(self):
|
def score(self):
|
||||||
return self._score
|
return self._score
|
||||||
|
@property
|
||||||
|
def vel(self):
|
||||||
|
return self._vel
|
Loading…
Reference in New Issue