Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in PyAPI #151

Merged
merged 10 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CAPI/cpp/API/src/AI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vector>
#include <thread>
#include <array>
#include <map>
#include "AI.h"
#include "constants.h"
// 注意不要使用conio.h,Windows.h等非标准库
Expand All @@ -23,24 +24,27 @@ void AI::play(ISweeperAPI& api)
{
api.Move(10, 2.1);
api.PrintSelfInfo();
api.Attack(1.1);
}
else if (this->playerID == 2)
{
// 玩家2执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}

else if (this->playerID == 3)
{
// 玩家3执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}
else if (this->playerID == 4)
{
// 玩家4执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}
}

void AI::play(ITeamAPI& api) // 默认team playerID 为0
{
auto self = api.GetSelfInfo();
api.PrintSelfInfo();
}
2 changes: 1 addition & 1 deletion CAPI/cpp/API/src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
logger->debug("Update Home!");
}
}
else if (AssistFunction::HaveView(x, y, item.home_message().x(), item.home_message().y(), viewRange, bufferState->gameMap))
else if (HaveOverView(item.home_message().x(), item.home_message().y()))
{
auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y()));
if (bufferState->mapInfo->homeState.count(pos) == 0)
Expand Down
8 changes: 4 additions & 4 deletions CAPI/python/PyAPI/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def GetPlayerGUIDs(self) -> List[int]:
def GetSelfInfo(self) -> THUAI7.Sweeper:
return cast(THUAI7.Sweepers, self.__logic.GetSelfInfo())

def GetMoney(self) -> int:
return self.__logic.GetMoney()
def GetEnergy(self) -> int:
return self.__logic.GetEnergy()

def GetScore(self) -> int:
return self.__logic.GetScore()
Expand Down Expand Up @@ -208,8 +208,8 @@ def GetSelfInfo(self) -> THUAI7.Home:
def GetScore(self) -> int:
return self.__logic.GetScore()

def GetMoney(self) -> int:
return self.__logic.GetMoney()
def GetEnergy(self) -> int:
return self.__logic.GetEnergy()

def InstallModule(self, ID: int, type: THUAI7.ModuleType) -> Future[bool]:
return self.__pool.submit(self.__logic.InstallModule, ID, type)
Expand Down
2 changes: 1 addition & 1 deletion CAPI/python/PyAPI/Communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def result():

class Communication:
def __init__(self, sIP: str, sPort: str):
aim = sIP + ':' + sPort
aim = sIP + ":" + sPort
channel = grpc.insecure_channel(aim)
self.__THUAI7Stub = Services.AvailableServiceStub(channel)
self.__haveNewMessage = False
Expand Down
Loading
Loading