| @@ -13,17 +13,21 @@ public: | |||||
| virtual void play(ITrickerAPI& api) = 0; | virtual void play(ITrickerAPI& api) = 0; | ||||
| }; | }; | ||||
| using CreateAIFunc = std::unique_ptr<IAI> (*)(); | |||||
| using CreateAIFunc = std::unique_ptr<IAI> (*)(int64_t playerID); | |||||
| class AI : public IAI | class AI : public IAI | ||||
| { | { | ||||
| public: | public: | ||||
| AI() : | |||||
| IAI() | |||||
| AI(int64_t pID) : | |||||
| IAI(), | |||||
| playerID(pID) | |||||
| { | { | ||||
| } | } | ||||
| void play(IStudentAPI& api) override; | void play(IStudentAPI& api) override; | ||||
| void play(ITrickerAPI& api) override; | void play(ITrickerAPI& api) override; | ||||
| private: | |||||
| int64_t playerID; | |||||
| }; | }; | ||||
| #endif | #endif | ||||
| @@ -1,24 +1,44 @@ | |||||
| #include <vector> | #include <vector> | ||||
| #include <thread> | #include <thread> | ||||
| #include <array> | |||||
| #include "AI.h" | #include "AI.h" | ||||
| #include "constants.h" | #include "constants.h" | ||||
| // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 | // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 | ||||
| extern const bool asynchronous = false; | extern const bool asynchronous = false; | ||||
| // 选手必须定义该变量来选择自己的阵营 | |||||
| extern const THUAI6::PlayerType playerType = THUAI6::PlayerType::TrickerPlayer; | |||||
| // 选手需要依次将player0到player4的职业在这里定义 | |||||
| // 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可 | |||||
| extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin; | |||||
| extern const std::array<THUAI6::StudentType, 4> studentType = { | |||||
| THUAI6::StudentType::Athlete, | |||||
| THUAI6::StudentType::Teacher, | |||||
| THUAI6::StudentType::StraightAStudent, | |||||
| THUAI6::StudentType::Sunshine}; | |||||
| extern const THUAI6::StudentType studentType = THUAI6::StudentType::Athlete; | |||||
| extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin; | |||||
| // 选手只需写一个即可,为了调试方便写了两个的话也不会有影响 | // 选手只需写一个即可,为了调试方便写了两个的话也不会有影响 | ||||
| void AI::play(IStudentAPI& api) | void AI::play(IStudentAPI& api) | ||||
| { | { | ||||
| auto self = api.GetSelfInfo(); | |||||
| // 公共操作 | |||||
| if (this->playerID == 0) | |||||
| { | |||||
| // 玩家0执行操作 | |||||
| } | |||||
| else if (this->playerID == 1) | |||||
| { | |||||
| // 玩家1执行操作 | |||||
| } | |||||
| else if (this->playerID == 2) | |||||
| { | |||||
| // 玩家2执行操作 | |||||
| } | |||||
| else if (this->playerID == 3) | |||||
| { | |||||
| // 玩家3执行操作 | |||||
| } | |||||
| // 公共操作 | |||||
| } | } | ||||
| void AI::play(ITrickerAPI& api) | void AI::play(ITrickerAPI& api) | ||||
| @@ -863,7 +863,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f | |||||
| cvAI.wait(lock, [this]() | cvAI.wait(lock, [this]() | ||||
| { return AIStart; }); | { return AIStart; }); | ||||
| } | } | ||||
| auto ai = createAI(); | |||||
| auto ai = createAI(playerID); | |||||
| while (AILoop) | while (AILoop) | ||||
| { | { | ||||
| @@ -2,6 +2,7 @@ | |||||
| #include "logic.h" | #include "logic.h" | ||||
| #include "structures.h" | #include "structures.h" | ||||
| #include <tclap/CmdLine.h> | #include <tclap/CmdLine.h> | ||||
| #include <array> | |||||
| #ifdef _MSC_VER | #ifdef _MSC_VER | ||||
| #pragma warning(disable : 4996) | #pragma warning(disable : 4996) | ||||
| @@ -15,9 +16,8 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder) | |||||
| bool file = false; | bool file = false; | ||||
| bool print = false; | bool print = false; | ||||
| bool warnOnly = false; | bool warnOnly = false; | ||||
| extern const THUAI6::PlayerType playerType; | |||||
| extern const THUAI6::TrickerType trickerType; | extern const THUAI6::TrickerType trickerType; | ||||
| extern const THUAI6::StudentType studentType; | |||||
| extern const std::array<THUAI6::StudentType, 4> studentType; | |||||
| // { | // { | ||||
| // file = true; | // file = true; | ||||
| // print = true; | // print = true; | ||||
| @@ -71,7 +71,12 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder) | |||||
| } | } | ||||
| try | try | ||||
| { | { | ||||
| Logic logic(playerType, pID, trickerType, studentType); | |||||
| THUAI6::PlayerType playerType; | |||||
| if (pID == 4) | |||||
| playerType = THUAI6::PlayerType::TrickerPlayer; | |||||
| else | |||||
| playerType = THUAI6::PlayerType::StudentPlayer; | |||||
| Logic logic(playerType, pID, trickerType, studentType[pID]); | |||||
| logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly); | logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly); | ||||
| } | } | ||||
| catch (const std::exception& e) | catch (const std::exception& e) | ||||
| @@ -81,9 +86,9 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder) | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| std::unique_ptr<IAI> CreateAI() | |||||
| std::unique_ptr<IAI> CreateAI(int64_t pID) | |||||
| { | { | ||||
| return std::make_unique<AI>(); | |||||
| return std::make_unique<AI>(pID); | |||||
| } | } | ||||
| int main(int argc, char* argv[]) | int main(int argc, char* argv[]) | ||||
| @@ -16,14 +16,18 @@ | |||||
| #include <google/protobuf/port_def.inc> | #include <google/protobuf/port_def.inc> | ||||
| PROTOBUF_PRAGMA_INIT_SEG | PROTOBUF_PRAGMA_INIT_SEG | ||||
| namespace _pb = ::PROTOBUF_NAMESPACE_ID; | |||||
| namespace _pbi = _pb::internal; | |||||
| namespace protobuf | namespace protobuf | ||||
| { | { | ||||
| } // namespace protobuf | } // namespace protobuf | ||||
| static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_MessageType_2eproto[11]; | |||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_MessageType_2eproto = nullptr; | |||||
| static const ::_pb::EnumDescriptor* file_level_enum_descriptors_MessageType_2eproto[11]; | |||||
| static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_MessageType_2eproto = nullptr; | |||||
| const uint32_t TableStruct_MessageType_2eproto::offsets[1] = {}; | const uint32_t TableStruct_MessageType_2eproto::offsets[1] = {}; | ||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema* schemas = nullptr; | |||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::Message* const* file_default_instances = nullptr; | |||||
| static constexpr ::_pbi::MigrationSchema* schemas = nullptr; | |||||
| static constexpr ::_pb::Message* const* file_default_instances = nullptr; | |||||
| const char descriptor_table_protodef_MessageType_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = | const char descriptor_table_protodef_MessageType_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = | ||||
| "\n\021MessageType.proto\022\010protobuf*\202\001\n\nBullet" | "\n\021MessageType.proto\022\010protobuf*\202\001\n\nBullet" | ||||
| @@ -82,13 +86,13 @@ const ::_pbi::DescriptorTable descriptor_table_MessageType_2eproto = { | |||||
| file_level_enum_descriptors_MessageType_2eproto, | file_level_enum_descriptors_MessageType_2eproto, | ||||
| file_level_service_descriptors_MessageType_2eproto, | file_level_service_descriptors_MessageType_2eproto, | ||||
| }; | }; | ||||
| PROTOBUF_ATTRIBUTE_WEAK const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable* descriptor_table_MessageType_2eproto_getter() | |||||
| PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_MessageType_2eproto_getter() | |||||
| { | { | ||||
| return &descriptor_table_MessageType_2eproto; | return &descriptor_table_MessageType_2eproto; | ||||
| } | } | ||||
| // Force running AddDescriptors() at dynamic initialization time. | // Force running AddDescriptors() at dynamic initialization time. | ||||
| PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_MessageType_2eproto(&descriptor_table_MessageType_2eproto); | |||||
| PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_MessageType_2eproto(&descriptor_table_MessageType_2eproto); | |||||
| namespace protobuf | namespace protobuf | ||||
| { | { | ||||
| const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* BulletType_descriptor() | const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* BulletType_descriptor() | ||||
| @@ -8,12 +8,12 @@ | |||||
| #include <string> | #include <string> | ||||
| #include <google/protobuf/port_def.inc> | #include <google/protobuf/port_def.inc> | ||||
| #if PROTOBUF_VERSION < 3019000 | |||||
| #if PROTOBUF_VERSION < 3021000 | |||||
| #error This file was generated by a newer version of protoc which is | #error This file was generated by a newer version of protoc which is | ||||
| #error incompatible with your Protocol Buffer headers. Please update | #error incompatible with your Protocol Buffer headers. Please update | ||||
| #error your headers. | #error your headers. | ||||
| #endif | #endif | ||||
| #if 3019004 < PROTOBUF_MIN_PROTOC_VERSION | |||||
| #if 3021005 < PROTOBUF_MIN_PROTOC_VERSION | |||||
| #error This file was generated by an older version of protoc which is | #error This file was generated by an older version of protoc which is | ||||
| #error incompatible with your Protocol Buffer headers. Please | #error incompatible with your Protocol Buffer headers. Please | ||||
| #error regenerate this file with a newer version of protoc. | #error regenerate this file with a newer version of protoc. | ||||
| @@ -23,7 +23,6 @@ | |||||
| #include <google/protobuf/io/coded_stream.h> | #include <google/protobuf/io/coded_stream.h> | ||||
| #include <google/protobuf/arena.h> | #include <google/protobuf/arena.h> | ||||
| #include <google/protobuf/arenastring.h> | #include <google/protobuf/arenastring.h> | ||||
| #include <google/protobuf/generated_message_table_driven.h> | |||||
| #include <google/protobuf/generated_message_util.h> | #include <google/protobuf/generated_message_util.h> | ||||
| #include <google/protobuf/metadata_lite.h> | #include <google/protobuf/metadata_lite.h> | ||||
| #include <google/protobuf/generated_message_reflection.h> | #include <google/protobuf/generated_message_reflection.h> | ||||
| @@ -43,11 +42,6 @@ PROTOBUF_NAMESPACE_CLOSE | |||||
| // Internal implementation detail -- do not use these members. | // Internal implementation detail -- do not use these members. | ||||
| struct TableStruct_MessageType_2eproto | struct TableStruct_MessageType_2eproto | ||||
| { | { | ||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; | |||||
| static const uint32_t offsets[]; | static const uint32_t offsets[]; | ||||
| }; | }; | ||||
| extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_MessageType_2eproto; | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_MessageType_2eproto; | ||||
| @@ -16,14 +16,18 @@ | |||||
| #include <google/protobuf/port_def.inc> | #include <google/protobuf/port_def.inc> | ||||
| PROTOBUF_PRAGMA_INIT_SEG | PROTOBUF_PRAGMA_INIT_SEG | ||||
| namespace _pb = ::PROTOBUF_NAMESPACE_ID; | |||||
| namespace _pbi = _pb::internal; | |||||
| namespace protobuf | namespace protobuf | ||||
| { | { | ||||
| } // namespace protobuf | } // namespace protobuf | ||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_Services_2eproto = nullptr; | |||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_Services_2eproto = nullptr; | |||||
| static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_Services_2eproto = nullptr; | |||||
| static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_Services_2eproto = nullptr; | |||||
| const uint32_t TableStruct_Services_2eproto::offsets[1] = {}; | const uint32_t TableStruct_Services_2eproto::offsets[1] = {}; | ||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema* schemas = nullptr; | |||||
| static constexpr ::PROTOBUF_NAMESPACE_ID::Message* const* file_default_instances = nullptr; | |||||
| static constexpr ::_pbi::MigrationSchema* schemas = nullptr; | |||||
| static constexpr ::_pb::Message* const* file_default_instances = nullptr; | |||||
| const char descriptor_table_protodef_Services_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = | const char descriptor_table_protodef_Services_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = | ||||
| "\n\016Services.proto\022\010protobuf\032\025Message2Clie" | "\n\016Services.proto\022\010protobuf\032\025Message2Clie" | ||||
| @@ -54,12 +58,12 @@ const char descriptor_table_protodef_Services_2eproto[] PROTOBUF_SECTION_VARIABL | |||||
| "tOpenChest\022\017.protobuf.IDMsg\032\021.protobuf.B" | "tOpenChest\022\017.protobuf.IDMsg\032\021.protobuf.B" | ||||
| "oolRes\0222\n\014EndAllAction\022\017.protobuf.IDMsg\032" | "oolRes\0222\n\014EndAllAction\022\017.protobuf.IDMsg\032" | ||||
| "\021.protobuf.BoolResb\006proto3"; | "\021.protobuf.BoolResb\006proto3"; | ||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable* const descriptor_table_Services_2eproto_deps[2] = { | |||||
| static const ::_pbi::DescriptorTable* const descriptor_table_Services_2eproto_deps[2] = { | |||||
| &::descriptor_table_Message2Clients_2eproto, | &::descriptor_table_Message2Clients_2eproto, | ||||
| &::descriptor_table_Message2Server_2eproto, | &::descriptor_table_Message2Server_2eproto, | ||||
| }; | }; | ||||
| static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_Services_2eproto_once; | |||||
| const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_Services_2eproto = { | |||||
| static ::_pbi::once_flag descriptor_table_Services_2eproto_once; | |||||
| const ::_pbi::DescriptorTable descriptor_table_Services_2eproto = { | |||||
| false, | false, | ||||
| false, | false, | ||||
| 1106, | 1106, | ||||
| @@ -76,13 +80,13 @@ const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_Servic | |||||
| file_level_enum_descriptors_Services_2eproto, | file_level_enum_descriptors_Services_2eproto, | ||||
| file_level_service_descriptors_Services_2eproto, | file_level_service_descriptors_Services_2eproto, | ||||
| }; | }; | ||||
| PROTOBUF_ATTRIBUTE_WEAK const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable* descriptor_table_Services_2eproto_getter() | |||||
| PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_Services_2eproto_getter() | |||||
| { | { | ||||
| return &descriptor_table_Services_2eproto; | return &descriptor_table_Services_2eproto; | ||||
| } | } | ||||
| // Force running AddDescriptors() at dynamic initialization time. | // Force running AddDescriptors() at dynamic initialization time. | ||||
| PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_Services_2eproto(&descriptor_table_Services_2eproto); | |||||
| PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_Services_2eproto(&descriptor_table_Services_2eproto); | |||||
| namespace protobuf | namespace protobuf | ||||
| { | { | ||||
| @@ -8,12 +8,12 @@ | |||||
| #include <string> | #include <string> | ||||
| #include <google/protobuf/port_def.inc> | #include <google/protobuf/port_def.inc> | ||||
| #if PROTOBUF_VERSION < 3019000 | |||||
| #if PROTOBUF_VERSION < 3021000 | |||||
| #error This file was generated by a newer version of protoc which is | #error This file was generated by a newer version of protoc which is | ||||
| #error incompatible with your Protocol Buffer headers. Please update | #error incompatible with your Protocol Buffer headers. Please update | ||||
| #error your headers. | #error your headers. | ||||
| #endif | #endif | ||||
| #if 3019004 < PROTOBUF_MIN_PROTOC_VERSION | |||||
| #if 3021005 < PROTOBUF_MIN_PROTOC_VERSION | |||||
| #error This file was generated by an older version of protoc which is | #error This file was generated by an older version of protoc which is | ||||
| #error incompatible with your Protocol Buffer headers. Please | #error incompatible with your Protocol Buffer headers. Please | ||||
| #error regenerate this file with a newer version of protoc. | #error regenerate this file with a newer version of protoc. | ||||
| @@ -23,7 +23,6 @@ | |||||
| #include <google/protobuf/io/coded_stream.h> | #include <google/protobuf/io/coded_stream.h> | ||||
| #include <google/protobuf/arena.h> | #include <google/protobuf/arena.h> | ||||
| #include <google/protobuf/arenastring.h> | #include <google/protobuf/arenastring.h> | ||||
| #include <google/protobuf/generated_message_table_driven.h> | |||||
| #include <google/protobuf/generated_message_util.h> | #include <google/protobuf/generated_message_util.h> | ||||
| #include <google/protobuf/metadata_lite.h> | #include <google/protobuf/metadata_lite.h> | ||||
| #include <google/protobuf/generated_message_reflection.h> | #include <google/protobuf/generated_message_reflection.h> | ||||
| @@ -44,11 +43,6 @@ PROTOBUF_NAMESPACE_CLOSE | |||||
| // Internal implementation detail -- do not use these members. | // Internal implementation detail -- do not use these members. | ||||
| struct TableStruct_Services_2eproto | struct TableStruct_Services_2eproto | ||||
| { | { | ||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1] PROTOBUF_SECTION_VARIABLE(protodesc_cold); | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; | |||||
| static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; | |||||
| static const uint32_t offsets[]; | static const uint32_t offsets[]; | ||||
| }; | }; | ||||
| extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_Services_2eproto; | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_Services_2eproto; | ||||
| @@ -1,6 +1,6 @@ | |||||
| import PyAPI.structures as THUAI6 | import PyAPI.structures as THUAI6 | ||||
| from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI | from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI | ||||
| from typing import Union, Final, cast | |||||
| from typing import Union, Final, cast, List | |||||
| from PyAPI.constants import Constants | from PyAPI.constants import Constants | ||||
| import queue | import queue | ||||
| @@ -13,15 +13,10 @@ class Setting: | |||||
| def asynchronous() -> bool: | def asynchronous() -> bool: | ||||
| return True | return True | ||||
| # 选手必须修改该函数的返回值来选择自己的阵营 | |||||
| # 选手需要依次将player0到player4的职业都定义 | |||||
| @staticmethod | @staticmethod | ||||
| def playerType() -> THUAI6.PlayerType: | |||||
| return THUAI6.PlayerType.StudentPlayer | |||||
| # 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可 | |||||
| @staticmethod | |||||
| def studentType() -> THUAI6.StudentType: | |||||
| return THUAI6.StudentType.Athlete | |||||
| def studentType() -> List[THUAI6.StudentType]: | |||||
| return [THUAI6.StudentType.Athlete, THUAI6.StudentType.Teacher, THUAI6.StudentType.StraightAStudent, THUAI6.StudentType.Sunshine] | |||||
| @staticmethod | @staticmethod | ||||
| def trickerType() -> THUAI6.TrickerType: | def trickerType() -> THUAI6.TrickerType: | ||||
| @@ -44,10 +39,23 @@ class AssistFunction: | |||||
| class AI(IAI): | class AI(IAI): | ||||
| def __init__(self, pID: int): | |||||
| self.__playerID = pID | |||||
| # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致 | # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致 | ||||
| def StudentPlay(self, api: IStudentAPI) -> None: | def StudentPlay(self, api: IStudentAPI) -> None: | ||||
| selfInfo = api.GetSelfInfo() | |||||
| api.PrintSelfInfo() | |||||
| if self.__playerID == 0: | |||||
| # 玩家0执行操作 | |||||
| return | |||||
| elif self.__playerID == 1: | |||||
| # 玩家1执行操作 | |||||
| return | |||||
| elif self.__playerID == 2: | |||||
| # 玩家2执行操作 | |||||
| return | |||||
| elif self.__playerID == 3: | |||||
| # 玩家3执行操作 | |||||
| return | |||||
| return | return | ||||
| def TrickerPlay(self, api: ITrickerAPI) -> None: | def TrickerPlay(self, api: ITrickerAPI) -> None: | ||||
| @@ -198,11 +198,15 @@ class Communication: | |||||
| self.__haveNewMessage = False | self.__haveNewMessage = False | ||||
| return self.__message2Client | return self.__message2Client | ||||
| def AddPlayer(self, playerID: int) -> None: | |||||
| def AddPlayer(self, playerID: int, playerType: THUAI6.PlayerType) -> None: | |||||
| def tMessage(): | def tMessage(): | ||||
| try: | try: | ||||
| if playerType == THUAI6.PlayerType.StudentPlayer: | |||||
| studentType = Setting.studentType()[playerID] | |||||
| else: | |||||
| studentType = THUAI6.StudentType.NullStudentType | |||||
| playerMsg = THUAI62Proto.THUAI62ProtobufPlayer( | playerMsg = THUAI62Proto.THUAI62ProtobufPlayer( | ||||
| playerID, Setting.playerType(), Setting.studentType(), Setting.trickerType()) | |||||
| playerID, playerType, studentType, Setting.trickerType()) | |||||
| for msg in self.__THUAI6Stub.AddPlayer(playerMsg): | for msg in self.__THUAI6Stub.AddPlayer(playerMsg): | ||||
| with self.__cvMessage: | with self.__cvMessage: | ||||
| self.__haveNewMessage = True | self.__haveNewMessage = True | ||||
| @@ -18,12 +18,14 @@ from PyAPI.Interface import ILogic, IGameTimer | |||||
| class Logic(ILogic): | class Logic(ILogic): | ||||
| def __init__(self, playerID: int) -> None: | |||||
| def __init__(self, playerID: int, playerType: THUAI6.PlayerType) -> None: | |||||
| # ID | # ID | ||||
| self.__playerID: int = playerID | self.__playerID: int = playerID | ||||
| self.__playerGUIDs: List[int] = [] | self.__playerGUIDs: List[int] = [] | ||||
| self.__playerType: THUAI6.PlayerType = playerType | |||||
| # 通信 | # 通信 | ||||
| self.__comm: Communication | self.__comm: Communication | ||||
| @@ -268,7 +270,7 @@ class Logic(ILogic): | |||||
| def __ProcessMessage(self) -> None: | def __ProcessMessage(self) -> None: | ||||
| def messageThread(): | def messageThread(): | ||||
| self.__logger.info("Message thread start!") | self.__logger.info("Message thread start!") | ||||
| self.__comm.AddPlayer(self.__playerID) | |||||
| self.__comm.AddPlayer(self.__playerID, self.__playerType) | |||||
| self.__logger.info("Join the player!") | self.__logger.info("Join the player!") | ||||
| while self.__gameState != THUAI6.GameState.GameEnd: | while self.__gameState != THUAI6.GameState.GameEnd: | ||||
| @@ -344,7 +346,7 @@ class Logic(ILogic): | |||||
| self.__logger.debug("Buffer cleared!") | self.__logger.debug("Buffer cleared!") | ||||
| self.__bufferState.gameInfo = Proto2THUAI6.Protobuf2THUAI6GameInfo( | self.__bufferState.gameInfo = Proto2THUAI6.Protobuf2THUAI6GameInfo( | ||||
| message.all_message) | message.all_message) | ||||
| if Setting.playerType() == THUAI6.PlayerType.StudentPlayer: | |||||
| if self.__playerType == THUAI6.PlayerType.StudentPlayer: | |||||
| for item in message.obj_message: | for item in message.obj_message: | ||||
| if item.WhichOneof("message_of_obj") == "student_message": | if item.WhichOneof("message_of_obj") == "student_message": | ||||
| if item.student_message.player_id == self.__playerID: | if item.student_message.player_id == self.__playerID: | ||||
| @@ -590,20 +592,20 @@ class Logic(ILogic): | |||||
| self.__logger.info("asynchronous: %s", Setting.asynchronous()) | self.__logger.info("asynchronous: %s", Setting.asynchronous()) | ||||
| self.__logger.info("server: %s:%s", IP, port) | self.__logger.info("server: %s:%s", IP, port) | ||||
| self.__logger.info("playerID: %s", self.__playerID) | self.__logger.info("playerID: %s", self.__playerID) | ||||
| self.__logger.info("player type: %s", Setting.playerType().name) | |||||
| self.__logger.info("player type: %s", self.__playerType.name) | |||||
| self.__logger.info("****************************") | self.__logger.info("****************************") | ||||
| # 建立通信组件 | # 建立通信组件 | ||||
| self.__comm = Communication(IP, port) | self.__comm = Communication(IP, port) | ||||
| # 构造timer | # 构造timer | ||||
| if Setting.playerType() == THUAI6.PlayerType.StudentPlayer: | |||||
| if self.__playerType == THUAI6.PlayerType.StudentPlayer: | |||||
| if not file and not screen: | if not file and not screen: | ||||
| self.__timer = StudentAPI(self) | self.__timer = StudentAPI(self) | ||||
| else: | else: | ||||
| self.__timer = StudentDebugAPI( | self.__timer = StudentDebugAPI( | ||||
| self, file, screen, warnOnly, self.__playerID) | self, file, screen, warnOnly, self.__playerID) | ||||
| elif Setting.playerType() == THUAI6.PlayerType.TrickerPlayer: | |||||
| elif self.__playerType == THUAI6.PlayerType.TrickerPlayer: | |||||
| if not file and not screen: | if not file and not screen: | ||||
| self.__timer = TrickerAPI(self) | self.__timer = TrickerAPI(self) | ||||
| else: | else: | ||||
| @@ -615,7 +617,7 @@ class Logic(ILogic): | |||||
| with self.__cvAI: | with self.__cvAI: | ||||
| self.__cvAI.wait_for(lambda: self.__AIStart) | self.__cvAI.wait_for(lambda: self.__AIStart) | ||||
| ai = createAI() | |||||
| ai = createAI(self.__playerID) | |||||
| while self.__AILoop: | while self.__AILoop: | ||||
| if Setting.asynchronous(): | if Setting.asynchronous(): | ||||
| self.__Wait() | self.__Wait() | ||||
| @@ -9,6 +9,7 @@ from PyAPI.AI import AI | |||||
| from PyAPI.logic import Logic | from PyAPI.logic import Logic | ||||
| from typing import List, Callable | from typing import List, Callable | ||||
| import argparse | import argparse | ||||
| import PyAPI.structures as THUAI6 | |||||
| def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None: | def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None: | ||||
| @@ -39,12 +40,17 @@ def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None: | |||||
| file = args.file | file = args.file | ||||
| screen = args.screen | screen = args.screen | ||||
| warnOnly = args.warnOnly | warnOnly = args.warnOnly | ||||
| logic = Logic(pID) | |||||
| playerType = THUAI6.PlayerType.NullPlayerType | |||||
| if pID == 4: | |||||
| playerType = THUAI6.PlayerType.TrickerPlayer | |||||
| else: | |||||
| playerType = THUAI6.PlayerType.StudentPlayer | |||||
| logic = Logic(pID, playerType) | |||||
| logic.Main(AIBuilder, sIP, sPort, file, screen, warnOnly) | logic.Main(AIBuilder, sIP, sPort, file, screen, warnOnly) | ||||
| def CreateAI() -> IAI: | |||||
| return AI() | |||||
| def CreateAI(pID: int) -> IAI: | |||||
| return AI(pID) | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| @@ -1,6 +1,7 @@ | |||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||
| python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 0 -d -o & | python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 0 -d -o & | ||||
| # python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 1 -d & | |||||
| # python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 2 -d & | |||||
| # python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 3 -d & | |||||
| python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 1 -d & | |||||
| python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 2 -d & | |||||
| python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 3 -d & | |||||
| python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 4 -d & | |||||