Skip to content

Commit

Permalink
fix(PyAPI): fix name
Browse files Browse the repository at this point in the history
  • Loading branch information
asdawej committed Apr 3, 2024
1 parent 6d79011 commit 85a64aa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
8 changes: 4 additions & 4 deletions CAPI/python/PyAPI/Space.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def __init__(self, state: State):
self.fortInfo = np.array(
[[*key, *value] for key, value in state.mapInfo.communityState.items()]
)
self.bridgeInfo = np.array(
[[*key, value] for key, value in state.mapInfo.bridgeState.items()]
self.wormholeInfo = np.array(
[[*key, value] for key, value in state.mapInfo.wormholeState.items()]
)
self.garbageInfo = np.array(
[[*key, value] for key, value in state.mapInfo.garbageState.items()]
self.resourceInfo = np.array(
[[*key, value] for key, value in state.mapInfo.resourceState.items()]
)
self.gameInfo = np.array(self.__ObsGame(state.gameInfo))

Expand Down
56 changes: 28 additions & 28 deletions CAPI/python/PyAPI/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,23 @@ def GetConstructionHp(self, cellX: int, cellY: int) -> int:
def GetWormholeHp(self, cellX: int, cellY: int) -> int:
with self.__mtxState:
self.__logger.debug("Called GetWormholeHp")
if (cellX, cellY) not in self.__currentState.mapInfo.bridgeState:
if (cellX, cellY) not in self.__currentState.mapInfo.wormholeState:
self.__logger.warning("GetWormholeHp: Out of range")
return -1
else:
return copy.deepcopy(
self.__currentState.mapInfo.bridgeState[(cellX, cellY)]
self.__currentState.mapInfo.wormholeState[(cellX, cellY)]
)

def GetResourceState(self, cellX: int, cellY: int) -> int:
with self.__mtxState:
self.__logger.debug("Called GetResourceState")
if (cellX, cellY) not in self.__currentState.mapInfo.garbageState:
if (cellX, cellY) not in self.__currentState.mapInfo.resourceState:
self.__logger.warning("GetResourceState: Out of range")
return -1
else:
return copy.deepcopy(
self.__currentState.mapInfo.garbageState[(cellX, cellY)]
self.__currentState.mapInfo.resourceState[(cellX, cellY)]
)

def GetHomeHp(self) -> int:
Expand Down Expand Up @@ -523,20 +523,20 @@ def __LoadBufferCase(self, item: Message2Clients.MessageOfObj) -> None:
)
self.__logger.debug("Update Fort")

elif item.WhichOneof("message_of_obj") == "bridge_message":
elif item.WhichOneof("message_of_obj") == "wormhole_message":
if AssistFunction.HaveView(
self.__bufferState.self.viewRange,
self.__bufferState.self.x,
self.__bufferState.self.y,
item.bridge_message.x,
item.bridge_message.y,
item.wormhole_message.x,
item.wormhole_message.y,
self.__bufferState.gameMap,
):
pos = (
AssistFunction.GridToCell(item.bridge_message.x),
AssistFunction.GridToCell(item.bridge_message.y),
AssistFunction.GridToCell(item.wormhole_message.x),
AssistFunction.GridToCell(item.wormhole_message.y),
)
self.__bufferState.mapInfo.bridgeState[pos] = item.bridge_message.hp
self.__bufferState.mapInfo.wormholeState[pos] = item.wormhole_message.hp
self.__logger.debug("Update Wormhole")

elif item.WhichOneof("message_of_obj") == "home_message":
Expand All @@ -562,21 +562,21 @@ def __LoadBufferCase(self, item: Message2Clients.MessageOfObj) -> None:
self.__bufferState.mapInfo.homeState[pos] = item.home_message.hp
self.__logger.debug("Update Home")

elif item.WhichOneof("message_of_obj") == "garbage_message":
elif item.WhichOneof("message_of_obj") == "resource_message":
if AssistFunction.HaveView(
self.__bufferState.self.viewRange,
self.__bufferState.self.x,
self.__bufferState.self.y,
item.garbage_message.x,
item.garbage_message.y,
item.resource_message.x,
item.resource_message.y,
self.__bufferState.gameMap,
):
pos = (
AssistFunction.GridToCell(item.garbage_message.x),
AssistFunction.GridToCell(item.garbage_message.y),
AssistFunction.GridToCell(item.resource_message.x),
AssistFunction.GridToCell(item.resource_message.y),
)
self.__bufferState.mapInfo.garbageState[pos] = (
item.garbage_message.progress
self.__bufferState.mapInfo.resourceState[pos] = (
item.resource_message.progress
)
self.__logger.debug("Update Resource")

Expand Down Expand Up @@ -735,13 +735,13 @@ def HaveOverView(targetX: int, targetY: int):
)
self.__logger.debug("Update Fort")

elif item.WhichOneof("message_of_obj") == "bridge_message":
if HaveOverView(item.bridge_message.x, item.bridge_message.y):
elif item.WhichOneof("message_of_obj") == "wormhole_message":
if HaveOverView(item.wormhole_message.x, item.wormhole_message.y):
pos = (
AssistFunction.GridToCell(item.bridge_message.x),
AssistFunction.GridToCell(item.bridge_message.y),
AssistFunction.GridToCell(item.wormhole_message.x),
AssistFunction.GridToCell(item.wormhole_message.y),
)
self.__bufferState.mapInfo.bridgeState[pos] = item.bridge_message.hp
self.__bufferState.mapInfo.wormholeState[pos] = item.wormhole_message.hp
self.__logger.debug("Update Wormhole")

elif item.WhichOneof("message_of_obj") == "home_message":
Expand All @@ -760,14 +760,14 @@ def HaveOverView(targetX: int, targetY: int):
self.__bufferState.mapInfo.homeState[pos] = item.home_message.hp
self.__logger.debug("Update Home")

elif item.WhichOneof("message_of_obj") == "garbage_message":
if HaveOverView(item.garbage_message.x, item.garbage_message.y):
elif item.WhichOneof("message_of_obj") == "resource_message":
if HaveOverView(item.resource_message.x, item.resource_message.y):
pos = (
AssistFunction.GridToCell(item.garbage_message.x),
AssistFunction.GridToCell(item.garbage_message.y),
AssistFunction.GridToCell(item.resource_message.x),
AssistFunction.GridToCell(item.resource_message.y),
)
self.__bufferState.mapInfo.garbageState[pos] = (
item.garbage_message.progress
self.__bufferState.mapInfo.resourceState[pos] = (
item.resource_message.progress
)
self.__logger.debug("Update Resource")

Expand Down
4 changes: 2 additions & 2 deletions CAPI/python/PyAPI/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ def __init__(self):
self.communityState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.fortState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.homeState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.bridgeState: Dict[Tuple[int, int], int] = {}
self.garbageState: Dict[Tuple[int, int], int] = {}
self.wormholeState: Dict[Tuple[int, int], int] = {}
self.resourceState: Dict[Tuple[int, int], int] = {}


class GameInfo:
Expand Down
24 changes: 13 additions & 11 deletions CAPI/python/debug.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from typing import List
import subprocess
import time

commands = [
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 0 -t 0 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 1 -t 0 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 2 -t 0 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 3 -t 0 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 4 -t 0 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 0 -t 0 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 1 -t 0 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 2 -t 0 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 3 -t 0 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 4 -t 0 -o",

"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 0 -t 1 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 1 -t 1 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 2 -t 1 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 3 -t 1 -o",
"python PyAPI\main.py -I 127.0.0.1 -P 8888 -p 4 -t 1 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 0 -t 1 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 1 -t 1 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 2 -t 1 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 3 -t 1 -o",
"python PyAPI/main.py -I 127.0.0.1 -P 8888 -p 4 -t 1 -o",
]

processes = []
processes: List[subprocess.Popen] = []
for cmd in commands:
processes.append(subprocess.Popen(cmd, shell=True))
time.sleep(0.5)
Expand Down

0 comments on commit 85a64aa

Please sign in to comment.