diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index d5ec828..3b23b1e 100644 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -52,7 +52,7 @@ namespace THUAI6 Key5 = 2, Key6 = 3, AddSpeed = 4, - AddLifeOrAp = 5, + AddLifeOrClairaudience = 5, AddHpOrAp = 6, ShieldOrSpear = 7, RecoveryFromDizziness = 8, @@ -83,7 +83,8 @@ namespace THUAI6 Athlete = 1, Teacher = 2, StraightAStudent = 3, - StudentType4 = 4, + Robot = 4, + TechOtaku = 5, }; // 捣蛋鬼类型 @@ -282,12 +283,15 @@ namespace THUAI6 {StudentType::Athlete, "Athlete"}, {StudentType::Teacher, "Teacher"}, {StudentType::StraightAStudent, "StraightAStudent"}, + {StudentType::Robot, "Robot"}, + {StudentType::TechOtaku, "TechOtaku"}, }; inline std::map trickerTypeDict{ {TrickerType::NullTrickerType, "NullTrickerType"}, {TrickerType::Assassin, "Assassin"}, {TrickerType::Klee, "Klee"}, + {TrickerType::ANoisyPerson, "ANoisyPerson"}, }; inline std::map playerStateDict{ @@ -339,7 +343,7 @@ namespace THUAI6 {PropType::Key5, "Key5"}, {PropType::Key6, "Key6"}, {PropType::AddSpeed, "AddSpeed"}, - {PropType::AddLifeOrAp, "AddLifeOrAp"}, + {PropType::AddLifeOrClairaudience, "AddLifeOrClairaudience"}, {PropType::AddHpOrAp, "AddHpOrAp"}, {PropType::ShieldOrSpear, "ShieldOrSpear"}, {PropType::RecoveryFromDizziness, "RecoveryFromDizziness"}, diff --git a/CAPI/cpp/API/include/utils.hpp b/CAPI/cpp/API/include/utils.hpp index 0323109..fb06ece 100644 --- a/CAPI/cpp/API/include/utils.hpp +++ b/CAPI/cpp/API/include/utils.hpp @@ -4,6 +4,7 @@ #define UTILS_HPP #include +#include #include "Message2Clients.pb.h" #include "Message2Server.pb.h" #include "MessageType.pb.h" @@ -93,7 +94,7 @@ namespace Proto2THUAI6 {protobuf::PropType::KEY6, THUAI6::PropType::Key6}, {protobuf::PropType::ADD_SPEED, THUAI6::PropType::AddSpeed}, {protobuf::PropType::ADD_HP_OR_AP, THUAI6::PropType::AddHpOrAp}, - {protobuf::PropType::ADD_LIFE_OR_AP, THUAI6::PropType::AddLifeOrAp}, + {protobuf::PropType::ADD_LIFE_OR_CLAIRAUDIENCE, THUAI6::PropType::AddLifeOrClairaudience}, {protobuf::PropType::SHIELD_OR_SPEAR, THUAI6::PropType::ShieldOrSpear}, {protobuf::PropType::RECOVERY_FROM_DIZZINESS, THUAI6::PropType::RecoveryFromDizziness}, }; @@ -107,34 +108,35 @@ namespace Proto2THUAI6 inline std::map studentTypeDict{ {protobuf::StudentType::NULL_STUDENT_TYPE, THUAI6::StudentType::NullStudentType}, {protobuf::StudentType::ATHLETE, THUAI6::StudentType::Athlete}, - {protobuf::StudentType::STUDENTTYPE2, THUAI6::StudentType::Teacher}, - {protobuf::StudentType::STUDENTTYPE3, THUAI6::StudentType::StraightAStudent}, - {protobuf::StudentType::STUDENTTYPE4, THUAI6::StudentType::StudentType4}, + {protobuf::StudentType::TEACHER, THUAI6::StudentType::Teacher}, + {protobuf::StudentType::STRAIGHT_A_STUDENT, THUAI6::StudentType::StraightAStudent}, + {protobuf::StudentType::ROBOT, THUAI6::StudentType::Robot}, + {protobuf::StudentType::TECH_OTAKU, THUAI6::StudentType::TechOtaku}, }; inline std::map trickerTypeDict{ {protobuf::TrickerType::NULL_TRICKER_TYPE, THUAI6::TrickerType::NullTrickerType}, {protobuf::TrickerType::ASSASSIN, THUAI6::TrickerType::Assassin}, - {protobuf::TrickerType::TRICKERTYPE2, THUAI6::TrickerType::Klee}, - {protobuf::TrickerType::TRICKERTYPE3, THUAI6::TrickerType::ANoisyPerson}, + {protobuf::TrickerType::KLEE, THUAI6::TrickerType::Klee}, + {protobuf::TrickerType::A_NOISY_PERSON, THUAI6::TrickerType::ANoisyPerson}, {protobuf::TrickerType::TRICKERTYPE4, THUAI6::TrickerType::TrickerType4}, }; inline std::map studentBuffTypeDict{ {protobuf::StudentBuffType::NULL_SBUFF_TYPE, THUAI6::StudentBuffType::NullStudentBuffType}, - {protobuf::StudentBuffType::SBUFFTYPE1, THUAI6::StudentBuffType::AddSpeed}, - {protobuf::StudentBuffType::SBUFFTYPE2, THUAI6::StudentBuffType::AddLife}, - {protobuf::StudentBuffType::SBUFFTYPE3, THUAI6::StudentBuffType::Shield}, - {protobuf::StudentBuffType::SBUFFTYPE4, THUAI6::StudentBuffType::Invisible}, + {protobuf::StudentBuffType::STUDENT_ADD_SPEED, THUAI6::StudentBuffType::AddSpeed}, + {protobuf::StudentBuffType::ADD_LIFE, THUAI6::StudentBuffType::AddLife}, + {protobuf::StudentBuffType::SHIELD, THUAI6::StudentBuffType::Shield}, + {protobuf::StudentBuffType::STUDENT_INVISIBLE, THUAI6::StudentBuffType::Invisible}, }; inline std::map trickerBuffTypeDict{ {protobuf::TrickerBuffType::NULL_TBUFF_TYPE, THUAI6::TrickerBuffType::NullTrickerBuffType}, - {protobuf::TrickerBuffType::TBUFFTYPE1, THUAI6::TrickerBuffType::AddSpeed}, - {protobuf::TrickerBuffType::TBUFFTYPE2, THUAI6::TrickerBuffType::Spear}, - {protobuf::TrickerBuffType::TBUFFTYPE3, THUAI6::TrickerBuffType::AddAp}, - {protobuf::TrickerBuffType::TBUFFTYPE4, THUAI6::TrickerBuffType::Clairaudience}, - {protobuf::TrickerBuffType::INVISIBLE, THUAI6::TrickerBuffType::Invisible}, + {protobuf::TrickerBuffType::TRICKER_ADD_SPEED, THUAI6::TrickerBuffType::AddSpeed}, + {protobuf::TrickerBuffType::SPEAR, THUAI6::TrickerBuffType::Spear}, + {protobuf::TrickerBuffType::ADD_AP, THUAI6::TrickerBuffType::AddAp}, + {protobuf::TrickerBuffType::CLAIRAUDIENCE, THUAI6::TrickerBuffType::Clairaudience}, + {protobuf::TrickerBuffType::TRICKER_INVISIBLE, THUAI6::TrickerBuffType::Invisible}, }; inline std::map playerStateDict{ @@ -170,8 +172,8 @@ namespace Proto2THUAI6 {protobuf::BulletType::NULL_BULLET_TYPE, THUAI6::BulletType::NullBulletType}, {protobuf::BulletType::FLYING_KNIFE, THUAI6::BulletType::FlyingKnife}, {protobuf::BulletType::COMMON_ATTACK_OF_TRICKER, THUAI6::BulletType::CommonAttackOfTricker}, - {protobuf::BulletType::FAST_BULLET, THUAI6::BulletType::BombBomb}, - {protobuf::BulletType::ORDINARY_BULLET, THUAI6::BulletType::JumpyDumpty}, + {protobuf::BulletType::BOMB_BOMB, THUAI6::BulletType::BombBomb}, + {protobuf::BulletType::JUMPY_DUMPTY, THUAI6::BulletType::JumpyDumpty}, {protobuf::BulletType::ATOM_BOMB, THUAI6::BulletType::AtomBomb}, }; @@ -350,7 +352,7 @@ namespace THUAI62Proto {THUAI6::PropType::Key5, protobuf::PropType::KEY5}, {THUAI6::PropType::Key6, protobuf::PropType::KEY6}, {THUAI6::PropType::AddHpOrAp, protobuf::PropType::ADD_HP_OR_AP}, - {THUAI6::PropType::AddLifeOrAp, protobuf::PropType::ADD_LIFE_OR_AP}, + {THUAI6::PropType::AddLifeOrClairaudience, protobuf::PropType::ADD_LIFE_OR_CLAIRAUDIENCE}, {THUAI6::PropType::AddSpeed, protobuf::PropType::ADD_SPEED}, {THUAI6::PropType::ShieldOrSpear, protobuf::PropType::SHIELD_OR_SPEAR}, }; @@ -364,14 +366,15 @@ namespace THUAI62Proto inline std::map studentTypeDict{ {THUAI6::StudentType::NullStudentType, protobuf::StudentType::NULL_STUDENT_TYPE}, {THUAI6::StudentType::Athlete, protobuf::StudentType::ATHLETE}, - {THUAI6::StudentType::Teacher, protobuf::StudentType::STUDENTTYPE2}, - {THUAI6::StudentType::StraightAStudent, protobuf::StudentType::STUDENTTYPE3}, - {THUAI6::StudentType::StudentType4, protobuf::StudentType::STUDENTTYPE4}, + {THUAI6::StudentType::Teacher, protobuf::StudentType::TEACHER}, + {THUAI6::StudentType::StraightAStudent, protobuf::StudentType::STRAIGHT_A_STUDENT}, + {THUAI6::StudentType::Robot, protobuf::StudentType::ROBOT}, + {THUAI6::StudentType::TechOtaku, protobuf::StudentType::TECH_OTAKU}, }; // inline std::map studentBuffTypeDict{ // {THUAI6::StudentBuffType::NullStudentBuffType, protobuf::StudentBuffType::NULL_SBUFF_TYPE}, - // {THUAI6::StudentBuffType::StudentBuffType1, protobuf::StudentBuffType::SBUFFTYPE1}, + // {THUAI6::StudentBuffType::StudentBuffType1, protobuf::StudentBuffType::ADD_SPEED}, // {THUAI6::StudentBuffType::StudentBuffType2, protobuf::StudentBuffType::SBUFFTYPE2}, // {THUAI6::StudentBuffType::StudentBuffType3, protobuf::StudentBuffType::SBUFFTYPE3}, // {THUAI6::StudentBuffType::StudentBuffType4, protobuf::StudentBuffType::SBUFFTYPE4}, @@ -380,8 +383,8 @@ namespace THUAI62Proto inline std::map trickerTypeDict{ {THUAI6::TrickerType::NullTrickerType, protobuf::TrickerType::NULL_TRICKER_TYPE}, {THUAI6::TrickerType::Assassin, protobuf::TrickerType::ASSASSIN}, - {THUAI6::TrickerType::Klee, protobuf::TrickerType::TRICKERTYPE2}, - {THUAI6::TrickerType::ANoisyPerson, protobuf::TrickerType::TRICKERTYPE3}, + {THUAI6::TrickerType::Klee, protobuf::TrickerType::KLEE}, + {THUAI6::TrickerType::ANoisyPerson, protobuf::TrickerType::A_NOISY_PERSON}, {THUAI6::TrickerType::TrickerType4, protobuf::TrickerType::TRICKERTYPE4}, }; diff --git a/CAPI/cpp/API/src/AI.cpp b/CAPI/cpp/API/src/AI.cpp index e49c1e1..79c408b 100644 --- a/CAPI/cpp/API/src/AI.cpp +++ b/CAPI/cpp/API/src/AI.cpp @@ -6,7 +6,7 @@ extern const bool asynchronous = false; // 选手必须定义该变量来选择自己的阵营 -extern const THUAI6::PlayerType playerType = THUAI6::PlayerType::StudentPlayer; +extern const THUAI6::PlayerType playerType = THUAI6::PlayerType::TrickerPlayer; // 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可 extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin; @@ -17,15 +17,14 @@ extern const THUAI6::StudentType studentType = THUAI6::StudentType::Athlete; void AI::play(IStudentAPI& api) { - api.SendMessage(1, "Hello, I'm player 0 using C++ interface!"); - if (api.HaveMessage()) - { - auto msg = api.GetMessage(); - api.Print("Player " + std::to_string(msg.first) + " says: " + msg.second); - } + api.PrintTricker(); } void AI::play(ITrickerAPI& api) { - api.Move(100, 1); + if (api.HaveMessage()) + { + auto msg = api.GetMessage(); + api.Print("Message from " + std::to_string(msg.first) + ": " + msg.second); + } } diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 894e0de..7d75de5 100644 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -215,7 +215,6 @@ bool Communication::TryConnection(int64_t playerID) auto status = THUAI6Stub->TryConnection(&context, request, &reply); if (status.ok()) { - std::cout << "Connection success!" << std::endl; return true; } else diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 5fefcc3..b6a85b4 100644 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -75,6 +75,11 @@ std::vector> Logic::GetFullMap() const THUAI6::PlaceType Logic::GetPlaceType(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); + if (cellX < 0 || cellX >= currentState->gameMap.size() || cellY < 0 || cellY >= currentState->gameMap[0].size()) + { + logger->warn("Invalid position!"); + return THUAI6::PlaceType::NullPlaceType; + } logger->debug("Called GetPlaceType"); return currentState->gameMap[cellX][cellY]; } diff --git a/CAPI/cpp/API/src/main.cpp b/CAPI/cpp/API/src/main.cpp index 9965bd7..ea8d2df 100644 --- a/CAPI/cpp/API/src/main.cpp +++ b/CAPI/cpp/API/src/main.cpp @@ -18,13 +18,13 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder) extern const THUAI6::PlayerType playerType; extern const THUAI6::TrickerType trickerType; extern const THUAI6::StudentType studentType; - { - file = true; - print = true; - Logic logic(playerType, pID, trickerType, studentType); - logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly); - return 0; - } + // { + // file = true; + // print = true; + // Logic logic(playerType, pID, trickerType, studentType); + // logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly); + // return 0; + // } // 使用cmdline的正式版本 try diff --git a/CAPI/cpp/proto/MessageType.pb.cc b/CAPI/cpp/proto/MessageType.pb.cc index e9978af..af6c6cc 100644 --- a/CAPI/cpp/proto/MessageType.pb.cc +++ b/CAPI/cpp/proto/MessageType.pb.cc @@ -30,48 +30,49 @@ 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) = - "\n\021MessageType.proto\022\010protobuf*\207\001\n\nBullet" + "\n\021MessageType.proto\022\010protobuf*\202\001\n\nBullet" "Type\022\024\n\020NULL_BULLET_TYPE\020\000\022\020\n\014FLYING_KNI" - "FE\020\001\022\034\n\030COMMON_ATTACK_OF_TRICKER\020\002\022\017\n\013FA" - "ST_BULLET\020\003\022\023\n\017ORDINARY_BULLET\020\004\022\r\n\tATOM" - "_BOMB\020\005*\241\001\n\tPlaceType\022\023\n\017NULL_PLACE_TYPE" - "\020\000\022\010\n\004LAND\020\001\022\010\n\004WALL\020\002\022\t\n\005GRASS\020\003\022\r\n\tCLA" - "SSROOM\020\004\022\010\n\004GATE\020\005\022\017\n\013HIDDEN_GATE\020\006\022\n\n\006W" - "INDOW\020\007\022\t\n\005DOOR3\020\010\022\t\n\005DOOR5\020\t\022\t\n\005DOOR6\020\n" - "\022\t\n\005CHEST\020\013*8\n\tShapeType\022\023\n\017NULL_SHAPE_T" - "YPE\020\000\022\n\n\006CIRCLE\020\001\022\n\n\006SQUARE\020\002*\243\001\n\010PropTy" - "pe\022\022\n\016NULL_PROP_TYPE\020\000\022\r\n\tADD_SPEED\020\001\022\022\n" - "\016ADD_LIFE_OR_AP\020\002\022\020\n\014ADD_HP_OR_AP\020\003\022\023\n\017S" - "HIELD_OR_SPEAR\020\004\022\010\n\004KEY3\020\005\022\010\n\004KEY5\020\006\022\010\n\004" - "KEY6\020\007\022\033\n\027RECOVERY_FROM_DIZZINESS\020\010*f\n\017S" - "tudentBuffType\022\023\n\017NULL_SBUFF_TYPE\020\000\022\016\n\nS" - "BUFFTYPE1\020\001\022\016\n\nSBUFFTYPE2\020\002\022\016\n\nSBUFFTYPE" - "3\020\003\022\016\n\nSBUFFTYPE4\020\004*\251\002\n\013PlayerState\022\017\n\013N" - "ULL_STATUS\020\000\022\010\n\004IDLE\020\001\022\014\n\010LEARNING\020\002\022\014\n\010" - "ADDICTED\020\003\022\010\n\004QUIT\020\004\022\r\n\tGRADUATED\020\005\022\013\n\007T" - "REATED\020\006\022\013\n\007RESCUED\020\007\022\013\n\007STUNNED\020\010\022\014\n\010TR" - "EATING\020\t\022\014\n\010RESCUING\020\n\022\014\n\010SWINGING\020\013\022\r\n\t" - "ATTACKING\020\014\022\013\n\007LOCKING\020\r\022\r\n\tRUMMAGING\020\016\022" - "\014\n\010CLIMBING\020\017\022\023\n\017OPENING_A_CHEST\020\020\022\027\n\023US" - "ING_SPECIAL_SKILL\020\021\022\022\n\016OPENING_A_GATE\020\022*" - "u\n\017TrickerBuffType\022\023\n\017NULL_TBUFF_TYPE\020\000\022" - "\016\n\nTBUFFTYPE1\020\001\022\016\n\nTBUFFTYPE2\020\002\022\016\n\nTBUFF" - "TYPE3\020\003\022\016\n\nTBUFFTYPE4\020\004\022\r\n\tINVISIBLE\020\005*J" - "\n\nPlayerType\022\024\n\020NULL_PLAYER_TYPE\020\000\022\022\n\016ST" - "UDENT_PLAYER\020\001\022\022\n\016TRICKER_PLAYER\020\002*g\n\013St" - "udentType\022\025\n\021NULL_STUDENT_TYPE\020\000\022\013\n\007ATHL" - "ETE\020\001\022\020\n\014STUDENTTYPE2\020\002\022\020\n\014STUDENTTYPE3\020" - "\003\022\020\n\014STUDENTTYPE4\020\004*h\n\013TrickerType\022\025\n\021NU" - "LL_TRICKER_TYPE\020\000\022\014\n\010ASSASSIN\020\001\022\020\n\014TRICK" - "ERTYPE2\020\002\022\020\n\014TRICKERTYPE3\020\003\022\020\n\014TRICKERTY" - "PE4\020\004*P\n\tGameState\022\023\n\017NULL_GAME_STATE\020\000\022" - "\016\n\nGAME_START\020\001\022\020\n\014GAME_RUNNING\020\002\022\014\n\010GAM" - "E_END\020\003b\006proto3"; + "FE\020\001\022\034\n\030COMMON_ATTACK_OF_TRICKER\020\002\022\r\n\tBO" + "MB_BOMB\020\003\022\020\n\014JUMPY_DUMPTY\020\004\022\r\n\tATOM_BOMB" + "\020\005*\241\001\n\tPlaceType\022\023\n\017NULL_PLACE_TYPE\020\000\022\010\n" + "\004LAND\020\001\022\010\n\004WALL\020\002\022\t\n\005GRASS\020\003\022\r\n\tCLASSROO" + "M\020\004\022\010\n\004GATE\020\005\022\017\n\013HIDDEN_GATE\020\006\022\n\n\006WINDOW" + "\020\007\022\t\n\005DOOR3\020\010\022\t\n\005DOOR5\020\t\022\t\n\005DOOR6\020\n\022\t\n\005C" + "HEST\020\013*8\n\tShapeType\022\023\n\017NULL_SHAPE_TYPE\020\000" + "\022\n\n\006CIRCLE\020\001\022\n\n\006SQUARE\020\002*\256\001\n\010PropType\022\022\n" + "\016NULL_PROP_TYPE\020\000\022\r\n\tADD_SPEED\020\001\022\035\n\031ADD_" + "LIFE_OR_CLAIRAUDIENCE\020\002\022\020\n\014ADD_HP_OR_AP\020" + "\003\022\023\n\017SHIELD_OR_SPEAR\020\004\022\010\n\004KEY3\020\005\022\010\n\004KEY5" + "\020\006\022\010\n\004KEY6\020\007\022\033\n\027RECOVERY_FROM_DIZZINESS\020" + "\010*n\n\017StudentBuffType\022\023\n\017NULL_SBUFF_TYPE\020" + "\000\022\025\n\021STUDENT_ADD_SPEED\020\001\022\014\n\010ADD_LIFE\020\002\022\n" + "\n\006SHIELD\020\003\022\025\n\021STUDENT_INVISIBLE\020\004*\251\002\n\013Pl" + "ayerState\022\017\n\013NULL_STATUS\020\000\022\010\n\004IDLE\020\001\022\014\n\010" + "LEARNING\020\002\022\014\n\010ADDICTED\020\003\022\010\n\004QUIT\020\004\022\r\n\tGR" + "ADUATED\020\005\022\013\n\007TREATED\020\006\022\013\n\007RESCUED\020\007\022\013\n\007S" + "TUNNED\020\010\022\014\n\010TREATING\020\t\022\014\n\010RESCUING\020\n\022\014\n\010" + "SWINGING\020\013\022\r\n\tATTACKING\020\014\022\013\n\007LOCKING\020\r\022\r" + "\n\tRUMMAGING\020\016\022\014\n\010CLIMBING\020\017\022\023\n\017OPENING_A" + "_CHEST\020\020\022\027\n\023USING_SPECIAL_SKILL\020\021\022\022\n\016OPE" + "NING_A_GATE\020\022*~\n\017TrickerBuffType\022\023\n\017NULL" + "_TBUFF_TYPE\020\000\022\025\n\021TRICKER_ADD_SPEED\020\001\022\t\n\005" + "SPEAR\020\002\022\n\n\006ADD_AP\020\003\022\021\n\rCLAIRAUDIENCE\020\004\022\025" + "\n\021TRICKER_INVISIBLE\020\005*J\n\nPlayerType\022\024\n\020N" + "ULL_PLAYER_TYPE\020\000\022\022\n\016STUDENT_PLAYER\020\001\022\022\n" + "\016TRICKER_PLAYER\020\002*q\n\013StudentType\022\025\n\021NULL" + "_STUDENT_TYPE\020\000\022\013\n\007ATHLETE\020\001\022\013\n\007TEACHER\020" + "\002\022\026\n\022STRAIGHT_A_STUDENT\020\003\022\t\n\005ROBOT\020\004\022\016\n\n" + "TECH_OTAKU\020\005*b\n\013TrickerType\022\025\n\021NULL_TRIC" + "KER_TYPE\020\000\022\014\n\010ASSASSIN\020\001\022\010\n\004KLEE\020\002\022\022\n\016A_" + "NOISY_PERSON\020\003\022\020\n\014TRICKERTYPE4\020\004*P\n\tGame" + "State\022\023\n\017NULL_GAME_STATE\020\000\022\016\n\nGAME_START" + "\020\001\022\020\n\014GAME_RUNNING\020\002\022\014\n\010GAME_END\020\003b\006prot" + "o3"; static ::_pbi::once_flag descriptor_table_MessageType_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_MessageType_2eproto = { false, false, - 1455, + 1482, descriptor_table_protodef_MessageType_2eproto, "MessageType.proto", &descriptor_table_MessageType_2eproto_once, @@ -291,6 +292,7 @@ namespace protobuf case 2: case 3: case 4: + case 5: return true; default: return false; diff --git a/CAPI/cpp/proto/MessageType.pb.h b/CAPI/cpp/proto/MessageType.pb.h index 22022b6..7f7cfc9 100644 --- a/CAPI/cpp/proto/MessageType.pb.h +++ b/CAPI/cpp/proto/MessageType.pb.h @@ -55,8 +55,8 @@ namespace protobuf NULL_BULLET_TYPE = 0, FLYING_KNIFE = 1, COMMON_ATTACK_OF_TRICKER = 2, - FAST_BULLET = 3, - ORDINARY_BULLET = 4, + BOMB_BOMB = 3, + JUMPY_DUMPTY = 4, ATOM_BOMB = 5, BulletType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), BulletType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() @@ -156,7 +156,7 @@ namespace protobuf { NULL_PROP_TYPE = 0, ADD_SPEED = 1, - ADD_LIFE_OR_AP = 2, + ADD_LIFE_OR_CLAIRAUDIENCE = 2, ADD_HP_OR_AP = 3, SHIELD_OR_SPEAR = 4, KEY3 = 5, @@ -191,16 +191,16 @@ namespace protobuf enum StudentBuffType : int { NULL_SBUFF_TYPE = 0, - SBUFFTYPE1 = 1, - SBUFFTYPE2 = 2, - SBUFFTYPE3 = 3, - SBUFFTYPE4 = 4, + STUDENT_ADD_SPEED = 1, + ADD_LIFE = 2, + SHIELD = 3, + STUDENT_INVISIBLE = 4, StudentBuffType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), StudentBuffType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; bool StudentBuffType_IsValid(int value); constexpr StudentBuffType StudentBuffType_MIN = NULL_SBUFF_TYPE; - constexpr StudentBuffType StudentBuffType_MAX = SBUFFTYPE4; + constexpr StudentBuffType StudentBuffType_MAX = STUDENT_INVISIBLE; constexpr int StudentBuffType_ARRAYSIZE = StudentBuffType_MAX + 1; const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* StudentBuffType_descriptor(); @@ -269,17 +269,17 @@ namespace protobuf enum TrickerBuffType : int { NULL_TBUFF_TYPE = 0, - TBUFFTYPE1 = 1, - TBUFFTYPE2 = 2, - TBUFFTYPE3 = 3, - TBUFFTYPE4 = 4, - INVISIBLE = 5, + TRICKER_ADD_SPEED = 1, + SPEAR = 2, + ADD_AP = 3, + CLAIRAUDIENCE = 4, + TRICKER_INVISIBLE = 5, TrickerBuffType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), TrickerBuffType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; bool TrickerBuffType_IsValid(int value); constexpr TrickerBuffType TrickerBuffType_MIN = NULL_TBUFF_TYPE; - constexpr TrickerBuffType TrickerBuffType_MAX = INVISIBLE; + constexpr TrickerBuffType TrickerBuffType_MAX = TRICKER_INVISIBLE; constexpr int TrickerBuffType_ARRAYSIZE = TrickerBuffType_MAX + 1; const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* TrickerBuffType_descriptor(); @@ -333,15 +333,16 @@ namespace protobuf { NULL_STUDENT_TYPE = 0, ATHLETE = 1, - STUDENTTYPE2 = 2, - STUDENTTYPE3 = 3, - STUDENTTYPE4 = 4, + TEACHER = 2, + STRAIGHT_A_STUDENT = 3, + ROBOT = 4, + TECH_OTAKU = 5, StudentType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), StudentType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; bool StudentType_IsValid(int value); constexpr StudentType StudentType_MIN = NULL_STUDENT_TYPE; - constexpr StudentType StudentType_MAX = STUDENTTYPE4; + constexpr StudentType StudentType_MAX = TECH_OTAKU; constexpr int StudentType_ARRAYSIZE = StudentType_MAX + 1; const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* StudentType_descriptor(); @@ -365,8 +366,8 @@ namespace protobuf { NULL_TRICKER_TYPE = 0, ASSASSIN = 1, - TRICKERTYPE2 = 2, - TRICKERTYPE3 = 3, + KLEE = 2, + A_NOISY_PERSON = 3, TRICKERTYPE4 = 4, TrickerType_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), TrickerType_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() diff --git a/CAPI/python/PyAPI/AI.py b/CAPI/python/PyAPI/AI.py index 5c2a442..791ee7f 100644 --- a/CAPI/python/PyAPI/AI.py +++ b/CAPI/python/PyAPI/AI.py @@ -2,6 +2,8 @@ import PyAPI.structures as THUAI6 from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI from typing import Union, Final, cast +import time + class Setting: # 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 @@ -39,20 +41,49 @@ class AssistFunction: return grid // numOfGridPerCell +arrive: bool = False + + class AI(IAI): # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致 def StudentPlay(self, api: IStudentAPI) -> None: - studentSelfInfo = api.GetSelfInfo() - - if studentSelfInfo.playerID == 0: - api.SendMessage(1, "Hello, I'm player 0 using python interface!") - if studentSelfInfo.playerID == 1: - api.SendMessage(0, "Hello, I'm player 1 using python interface!") + api.Attack(float('nan')) + time.sleep(0.5) + api.PrintSelfInfo() + # api.SendMessage(4, "Hello World!") + # api.PrintSelfInfo() + # global arrive + # if not arrive: + # if api.GetSelfInfo().x < 25500: + # api.MoveDown(50) + # return + # if api.GetSelfInfo().y > 10500: + # api.MoveLeft(50) + # return + # arrive = True + # else: + # api.SkipWindow() + # # time.sleep(1) + + # api.PrintSelfInfo() + + # if api.GetSelfInfo().y < 18500: + # api.MoveRight(50) + # return + # api.StartLearning() + + # if api.GetSelfInfo().y > 7000: + # api.MoveLeft(50) + # return + # if api.GetSelfInfo().x > 20500: + # api.MoveUp(50) + # return + # if api.GetSelfInfo().y > 4500: + # api.MoveLeft(50) + # return + + api.PrintTricker() - if api.HaveMessage(): - message = api.GetMessage() - api.Print( - f"Recieved Message from player {message[0]}: {message[1]}") return def TrickerPlay(self, api: ITrickerAPI) -> None: diff --git a/CAPI/python/PyAPI/API.py b/CAPI/python/PyAPI/API.py index 3425871..d9cba6e 100644 --- a/CAPI/python/PyAPI/API.py +++ b/CAPI/python/PyAPI/API.py @@ -2,7 +2,7 @@ import PyAPI.structures as THUAI6 from PyAPI.Interface import ILogic, IStudentAPI, ITrickerAPI, IGameTimer, IAI from math import pi from concurrent.futures import ThreadPoolExecutor, Future -from typing import List, cast +from typing import List, cast, Tuple class StudentAPI(IStudentAPI, IGameTimer): @@ -71,7 +71,7 @@ class StudentAPI(IStudentAPI, IGameTimer): def HaveMessage(self) -> bool: return self.__logic.HaveMessage() - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: return self.__logic.GetMessage() # 等待下一帧 @@ -238,7 +238,7 @@ class TrickerAPI(ITrickerAPI, IGameTimer): def HaveMessage(self) -> bool: return self.__logic.HaveMessage() - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: return self.__logic.GetMessage() # 等待下一帧 diff --git a/CAPI/python/PyAPI/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index 123cf83..98c4710 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -1,6 +1,6 @@ from math import pi from concurrent.futures import ThreadPoolExecutor, Future -from typing import List, cast +from typing import List, cast, Tuple import logging import os import datetime @@ -18,7 +18,7 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): self.__logger = logging.getLogger("api " + str(playerID)) self.__logger.setLevel(logging.DEBUG) formatter = logging.Formatter( - "[%(name)s] [%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S.%e") + "[%(name)s] [%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s", '%H:%M:%S') # 确保文件存在 if not os.path.exists(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/logs"): os.makedirs(os.path.dirname(os.path.dirname( @@ -225,7 +225,7 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): f"HaveMessage: failed at {self.__GetTime()}ms") return result - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: self.__logger.info( f"GetMessage: called at {self.__GetTime()}ms") result = self.__logic.GetMessage() @@ -452,7 +452,7 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): self.__logger = logging.getLogger("api " + str(playerID)) self.__logger.setLevel(logging.DEBUG) formatter = logging.Formatter( - "[%(name)s] [%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S.%e") + "[%(name)s] [%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s", '%H:%M:%S') # 确保文件存在 if not os.path.exists(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/logs"): os.makedirs(os.path.dirname(os.path.dirname( @@ -661,7 +661,7 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): f"HaveMessage: failed at {self.__GetTime()}ms") return result - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: self.__logger.info( f"GetMessage: called at {self.__GetTime()}ms") result = self.__logic.GetMessage() diff --git a/CAPI/python/PyAPI/Interface.py b/CAPI/python/PyAPI/Interface.py index 95ca2ea..732d1de 100644 --- a/CAPI/python/PyAPI/Interface.py +++ b/CAPI/python/PyAPI/Interface.py @@ -1,4 +1,4 @@ -from typing import List, Union +from typing import List, Union, Tuple from concurrent.futures import Future from abc import abstractmethod, ABCMeta import PyAPI.structures as THUAI6 @@ -85,7 +85,7 @@ class ILogic(metaclass=ABCMeta): pass @abstractmethod - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: pass @abstractmethod @@ -227,7 +227,7 @@ class IAPI(metaclass=ABCMeta): pass @abstractmethod - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: pass # 等待下一帧 diff --git a/CAPI/python/PyAPI/logic.py b/CAPI/python/PyAPI/logic.py index 1ff9d22..42d9b3a 100644 --- a/CAPI/python/PyAPI/logic.py +++ b/CAPI/python/PyAPI/logic.py @@ -1,6 +1,5 @@ import os -from abc import abstractmethod -from typing import List, Union, Callable +from typing import List, Union, Callable, Tuple import threading import logging import proto.MessageType_pb2 as MessageType @@ -96,6 +95,9 @@ class Logic(ILogic): def GetPlaceType(self, x: int, y: int) -> THUAI6.PlaceType: with self.__mtxState: + if x < 0 or x >= len(self.__currentState.gameMap) or y < 0 or y >= len(self.__currentState.gameMap[0]): + self.__logger.warning("Invalid position") + return THUAI6.PlaceType.NullPlaceType self.__logger.debug("Called GetPlaceType") return self.__currentState.gameMap[x][y] @@ -182,7 +184,7 @@ class Logic(ILogic): self.__logger.debug("Called HaveMessage") return not self.__messageQueue.empty() - def GetMessage(self) -> tuple[int, str]: + def GetMessage(self) -> Tuple[int, str]: self.__logger.debug("Called GetMessage") if self.__messageQueue.empty(): self.__logger.warning("Message queue is empty!") @@ -544,7 +546,7 @@ class Logic(ILogic): # 建立日志组件 self.__logger.setLevel(logging.DEBUG) formatter = logging.Formatter( - "[%(name)s] [%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S.%e") + "[%(name)s] [%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s", '%H:%M:%S') # 确保文件存在 if not os.path.exists(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/logs"): os.makedirs(os.path.dirname(os.path.dirname( diff --git a/CAPI/python/PyAPI/main.py b/CAPI/python/PyAPI/main.py index 64f3ae2..d717884 100644 --- a/CAPI/python/PyAPI/main.py +++ b/CAPI/python/PyAPI/main.py @@ -26,12 +26,12 @@ def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None: help="Server`s Port 8888 in default", dest="sPort", default="8888") parser.add_argument("-p", type=int, required=True, help="Player`s ID", dest="pID", choices=[0, 1, 2, 3, 4]) - parser.add_argument("-d", type=bool, required=False, - help="Set this flag to save the debug log to ./logs folder", dest="file", default=False, const=True, nargs='?') - parser.add_argument("-o", type=bool, required=False, - help="Set this flag to print the debug log to the screen", dest="screen", default=False, const=True, nargs='?') - parser.add_argument("-w", type=bool, required=False, - help="Set this flag to only print warning on the screen", dest="warnOnly", default=False, const=True, nargs='?') + parser.add_argument("-d", action='store_true', + help="Set this flag to save the debug log to ./logs folder", dest="file") + parser.add_argument("-o", action='store_true', + help="Set this flag to print the debug log to the screen", dest="screen") + parser.add_argument("-w", action='store_true', + help="Set this flag to only print warning on the screen", dest="warnOnly") args = parser.parse_args() pID = args.pID sIP = args.sIP @@ -39,6 +39,7 @@ def THUAI6Main(argv: List[str], AIBuilder: Callable) -> None: file = args.file screen = args.screen warnOnly = args.warnOnly + print(warnOnly) logic = Logic(pID) logic.Main(AIBuilder, sIP, sPort, file, screen, warnOnly) diff --git a/CAPI/python/PyAPI/structures.py b/CAPI/python/PyAPI/structures.py index a3f649d..5920f9e 100644 --- a/CAPI/python/PyAPI/structures.py +++ b/CAPI/python/PyAPI/structures.py @@ -1,6 +1,11 @@ from enum import Enum -from typing import List, Dict, Tuple +from typing import List, Dict +import sys +if sys.version_info < (3, 9): + from typing import Tuple +else: + Tuple = tuple class GameState(Enum): NullGameState = 0 @@ -42,7 +47,7 @@ class PropType(Enum): Key5 = 2 Key6 = 3 AddSpeed = 4 - AddLifeOrAp = 5 + AddLifeOrClairaudience = 5 AddHpOrAp = 6 ShieldOrSpear = 7 RecoveryFromDizziness = 8 @@ -62,6 +67,8 @@ class StudentType(Enum): Athlete = 1 Teacher = 2 StraightAStudent = 3 + Robot = 4 + TechOtaku = 5 class TrickerType(Enum): @@ -200,12 +207,12 @@ class BombedBullet: class GameMap: - classroomState: Dict[tuple[int, int], int] = {} - gateState: Dict[tuple[int, int], int] = {} - chestState: Dict[tuple[int, int], int] = {} - doorState: Dict[tuple[int, int], bool] = {} - doorProgress: Dict[tuple[int, int], int] = {} - hiddenGateState: Dict[tuple[int, int], HiddenGateState] = {} + classroomState: Dict[Tuple[int, int], int] = {} + gateState: Dict[Tuple[int, int], int] = {} + chestState: Dict[Tuple[int, int], int] = {} + doorState: Dict[Tuple[int, int], bool] = {} + doorProgress: Dict[Tuple[int, int], int] = {} + hiddenGateState: Dict[Tuple[int, int], HiddenGateState] = {} class GameInfo: diff --git a/CAPI/python/PyAPI/utils.py b/CAPI/python/PyAPI/utils.py index 440e725..305ad7b 100644 --- a/CAPI/python/PyAPI/utils.py +++ b/CAPI/python/PyAPI/utils.py @@ -90,7 +90,7 @@ class Proto2THUAI6(NoInstance): MessageType.KEY6: THUAI6.PropType.Key6, MessageType.ADD_SPEED: THUAI6.PropType.AddSpeed, MessageType.ADD_HP_OR_AP: THUAI6.PropType.AddHpOrAp, - MessageType.ADD_LIFE_OR_AP: THUAI6.PropType.AddLifeOrAp, + MessageType.ADD_LIFE_OR_CLAIRAUDIENCE: THUAI6.PropType.AddLifeOrClairaudience, MessageType.SHIELD_OR_SPEAR: THUAI6.PropType.ShieldOrSpear, MessageType.RECOVERY_FROM_DIZZINESS: THUAI6.PropType.RecoveryFromDizziness, } @@ -102,29 +102,31 @@ class Proto2THUAI6(NoInstance): studentTypeDict: Final[dict] = { MessageType.NULL_STUDENT_TYPE: THUAI6.StudentType.NullStudentType, MessageType.ATHLETE: THUAI6.StudentType.Athlete, - MessageType.STUDENTTYPE2: THUAI6.StudentType.Teacher, - MessageType.STUDENTTYPE3: THUAI6.StudentType.StraightAStudent, } + MessageType.TEACHER: THUAI6.StudentType.Teacher, + MessageType.STRAIGHT_A_STUDENT: THUAI6.StudentType.StraightAStudent, + MessageType.ROBOT: THUAI6.StudentType.Robot, + MessageType.TECH_OTAKU: THUAI6.StudentType.TechOtaku, } trickerTypeDict: Final[dict] = { MessageType.NULL_TRICKER_TYPE: THUAI6.TrickerType.NullTrickerType, MessageType.ASSASSIN: THUAI6.TrickerType.Assassin, - MessageType.TRICKERTYPE2: THUAI6.TrickerType.Klee, - MessageType.TRICKERTYPE3: THUAI6.TrickerType.ANoisyPerson, } + MessageType.KLEE: THUAI6.TrickerType.Klee, + MessageType.A_NOISY_PERSON: THUAI6.TrickerType.ANoisyPerson, } studentBuffTypeDict: Final[dict] = { MessageType.NULL_SBUFF_TYPE: THUAI6.StudentBuffType.NullStudentBuffType, - MessageType.SBUFFTYPE1: THUAI6.StudentBuffType.AddSpeed, - MessageType.SBUFFTYPE2: THUAI6.StudentBuffType.AddLife, - MessageType.SBUFFTYPE3: THUAI6.StudentBuffType.Shield, - MessageType.SBUFFTYPE4: THUAI6.StudentBuffType.Invisible, } + MessageType.STUDENT_ADD_SPEED: THUAI6.StudentBuffType.AddSpeed, + MessageType.ADD_LIFE: THUAI6.StudentBuffType.AddLife, + MessageType.SHIELD: THUAI6.StudentBuffType.Shield, + MessageType.STUDENT_INVISIBLE: THUAI6.StudentBuffType.Invisible, } trickerBuffTypeDict: Final[dict] = { MessageType.NULL_TBUFF_TYPE: THUAI6.TrickerBuffType.NullTrickerBuffType, - MessageType.TBUFFTYPE1: THUAI6.TrickerBuffType.AddSpeed, - MessageType.TBUFFTYPE2: THUAI6.TrickerBuffType.Spear, - MessageType.TBUFFTYPE3: THUAI6.TrickerBuffType.AddAp, - MessageType.TBUFFTYPE4: THUAI6.TrickerBuffType.Clairaudience, - MessageType.INVISIBLE: THUAI6.TrickerBuffType.Invisible, } + MessageType.TRICKER_ADD_SPEED: THUAI6.TrickerBuffType.AddSpeed, + MessageType.SPEAR: THUAI6.TrickerBuffType.Spear, + MessageType.ADD_AP: THUAI6.TrickerBuffType.AddAp, + MessageType.CLAIRAUDIENCE: THUAI6.TrickerBuffType.Clairaudience, + MessageType.TRICKER_INVISIBLE: THUAI6.TrickerBuffType.Invisible, } playerStateDict: Final[dict] = { MessageType.NULL_STATUS: THUAI6.PlayerState.NullState, @@ -156,9 +158,9 @@ class Proto2THUAI6(NoInstance): bulletTypeDict: Final[dict] = { MessageType.NULL_BULLET_TYPE: THUAI6.BulletType.NullBulletType, MessageType.FLYING_KNIFE: THUAI6.BulletType.FlyingKnife, - MessageType.FAST_BULLET: THUAI6.BulletType.BombBomb, + MessageType.BOMB_BOMB: THUAI6.BulletType.BombBomb, MessageType.COMMON_ATTACK_OF_TRICKER: THUAI6.BulletType.CommonAttackOfTricker, - MessageType.ORDINARY_BULLET: THUAI6.BulletType.JumpyDumpty, + MessageType.JUMPY_DUMPTY: THUAI6.BulletType.JumpyDumpty, MessageType.ATOM_BOMB: THUAI6.BulletType.AtomBomb, } # 用于将Proto的对象转为THUAI6的对象 @@ -303,14 +305,16 @@ class THUAI62Proto(NoInstance): studentTypeDict: Final[dict] = { THUAI6.StudentType.NullStudentType: MessageType.NULL_STUDENT_TYPE, THUAI6.StudentType.Athlete: MessageType.ATHLETE, - THUAI6.StudentType.Teacher: MessageType.STUDENTTYPE2, - THUAI6.StudentType.StraightAStudent: MessageType.STUDENTTYPE3, } + THUAI6.StudentType.Teacher: MessageType.TEACHER, + THUAI6.StudentType.StraightAStudent: MessageType.STRAIGHT_A_STUDENT, + THUAI6.StudentType.Robot: MessageType.ROBOT, + THUAI6.StudentType.TechOtaku: MessageType.TECH_OTAKU, } trickerTypeDict: Final[dict] = { THUAI6.TrickerType.NullTrickerType: MessageType.NULL_TRICKER_TYPE, THUAI6.TrickerType.Assassin: MessageType.ASSASSIN, - THUAI6.TrickerType.Klee: MessageType.TRICKERTYPE2, - THUAI6.TrickerType.ANoisyPerson: MessageType.TRICKERTYPE3, } + THUAI6.TrickerType.Klee: MessageType.KLEE, + THUAI6.TrickerType.ANoisyPerson: MessageType.A_NOISY_PERSON, } propTypeDict: Final[dict] = { THUAI6.PropType.NullPropType: MessageType.NULL_PROP_TYPE, @@ -318,7 +322,7 @@ class THUAI62Proto(NoInstance): THUAI6.PropType.Key5: MessageType.KEY5, THUAI6.PropType.Key6: MessageType.KEY6, THUAI6.PropType.AddHpOrAp: MessageType.ADD_HP_OR_AP, - THUAI6.PropType.AddLifeOrAp: MessageType.ADD_LIFE_OR_AP, + THUAI6.PropType.AddLifeOrClairaudience: MessageType.ADD_LIFE_OR_CLAIRAUDIENCE, THUAI6.PropType.AddSpeed: MessageType.ADD_SPEED, THUAI6.PropType.ShieldOrSpear: MessageType.SHIELD_OR_SPEAR, } diff --git a/CAPI/python/generate_proto.sh b/CAPI/python/generate_proto.sh new file mode 100755 index 0000000..8b917c4 --- /dev/null +++ b/CAPI/python/generate_proto.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +python3 -m pip install -r requirements.txt + +mkdir -p proto + +python3 -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto MessageType.proto +python3 -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto Message2Clients.proto +python3 -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto Message2Server.proto +python3 -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto --grpc_python_out=./proto Services.proto + + diff --git a/CAPI/python/requirements.txt b/CAPI/python/requirements.txt index 02776c6..1e31ecf 100644 --- a/CAPI/python/requirements.txt +++ b/CAPI/python/requirements.txt @@ -1,2 +1,2 @@ -grpcio==1.53.0 -grpcio-tools==1.53.0 +grpcio==1.52.0 +grpcio-tools==1.52.0 diff --git a/CAPI/python/run.sh b/CAPI/python/run.sh old mode 100644 new mode 100755 index 36dee5f..00de795 --- a/CAPI/python/run.sh +++ b/CAPI/python/run.sh @@ -1,2 +1,4 @@ +#!/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 1 -d -o & \ No newline at end of file +# python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 1 -d -o & \ No newline at end of file diff --git a/logic/Client/MainWindow.xaml.cs b/logic/Client/MainWindow.xaml.cs index 0d0a918..190e49f 100644 --- a/logic/Client/MainWindow.xaml.cs +++ b/logic/Client/MainWindow.xaml.cs @@ -999,6 +999,7 @@ namespace Client TreatAndRescueMsg msgR = new() { PlayerId = playerID, + ToPlayerId = -1, }; client.StartRescueMate(msgR); break; @@ -1006,6 +1007,7 @@ namespace Client TreatAndRescueMsg msgT = new() { PlayerId = playerID, + ToPlayerId = -1, }; client.StartTreatMate(msgT); break; diff --git a/logic/Client/Properties/launchSettings.json b/logic/Client/Properties/launchSettings.json index 0d108bf..e1c868c 100644 --- a/logic/Client/Properties/launchSettings.json +++ b/logic/Client/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Client": { "commandName": "Project", - "commandLineArgs": " --cl --port 8888 --characterID 0 --type 1 --occupation 1" + "commandLineArgs": "--ip 183.172.235.138 --cl --port 8888 --characterID 0 --type 1 --occupation 1" } } } \ No newline at end of file diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index 26c8b64..6a6744c 100644 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -202,8 +202,6 @@ namespace Gaming playerTreated.HP == playerTreated.MaxHp || !GameData.ApproachToInteract(playerTreated.Position, player.Position)) return false; - Preparation.Utility.Debugger.Output(player, "treat " + playerTreated.ToString()); - if (playerTreated.HP + playerTreated.DegreeOfTreatment >= playerTreated.MaxHp) { playerTreated.HP = playerTreated.MaxHp; diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index 6316e32..e5601f5 100644 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -54,6 +54,22 @@ namespace Server semaDict.Add(request.PlayerId, temp); } } + do + { + semaDict[request.PlayerId].Item1.Wait(); + try + { + if (currentGameInfo != null) + { + await responseStream.WriteAsync(currentGameInfo); + //Console.WriteLine("Send!"); + } + } + finally + { + semaDict[request.PlayerId].Item2.Release(); + } + } while (game.GameMap.Timer.IsGaming); return; } @@ -112,9 +128,19 @@ namespace Server #if DEBUG Console.WriteLine($"Attack ID: {request.PlayerId}"); #endif + BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } + if (request.Angle == double.NaN) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; game.Attack(gameID, request.Angle); - BoolRes boolRes = new(); boolRes.ActSuccess = true; return Task.FromResult(boolRes); } @@ -125,8 +151,18 @@ namespace Server #if DEBUG Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}"); #endif - var gameID = communicationToGameID[request.PlayerId]; MoveRes moveRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + moveRes.ActSuccess = false; + return Task.FromResult(moveRes); + } + if (request.Angle == double.NaN) + { + moveRes.ActSuccess = false; + return Task.FromResult(moveRes); + } + var gameID = communicationToGameID[request.PlayerId]; game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle); // 之后game.MovePlayer可能改为bool类 moveRes.ActSuccess = true; @@ -137,6 +173,11 @@ namespace Server public override Task SendMessage(SendMsg request, ServerCallContext context) { var boolRes = new BoolRes(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } if (!ValidPlayerID(request.PlayerId) || !ValidPlayerID(request.ToPlayerId) || PlayerIDToTeamID(request.PlayerId) != PlayerIDToTeamID(request.ToPlayerId) || request.PlayerId == request.ToPlayerId) { @@ -174,6 +215,11 @@ namespace Server Console.WriteLine($"PickProp ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.PickProp(gameID, CopyInfo.ToPropType(request.PropType)); return Task.FromResult(boolRes); @@ -185,6 +231,11 @@ namespace Server Console.WriteLine($"UseProp ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; game.UseProp(gameID, CopyInfo.ToPropType(request.PropType)); boolRes.ActSuccess = true; @@ -196,6 +247,11 @@ namespace Server Console.WriteLine($"ThrowProp ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; game.ThrowProp(gameID, CopyInfo.ToPropType(request.PropType)); boolRes.ActSuccess = true; @@ -207,6 +263,11 @@ namespace Server Console.WriteLine($"UseSkill ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.UseActiveSkill(gameID, request.SkillId); return Task.FromResult(boolRes); @@ -218,6 +279,11 @@ namespace Server Console.WriteLine($"Graduate ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.Escape(gameID); return Task.FromResult(boolRes); @@ -228,9 +294,22 @@ namespace Server Console.WriteLine($"StartRescueMate ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; - var toGameID = communicationToGameID[request.ToPlayerId]; - boolRes.ActSuccess = game.Rescue(gameID, toGameID); + if (request.ToPlayerId >= 0 && request.ToPlayerId < options.MaxStudentCount) + { + var toGameID = communicationToGameID[request.ToPlayerId]; + boolRes.ActSuccess = game.Rescue(gameID, toGameID); + } + else + { + boolRes.ActSuccess = game.Rescue(gameID); + } + return Task.FromResult(boolRes); } public override Task StartTreatMate(TreatAndRescueMsg request, ServerCallContext context) @@ -239,9 +318,22 @@ namespace Server Console.WriteLine($"StartTreatMate ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; - var toGameID = communicationToGameID[request.ToPlayerId]; - boolRes.ActSuccess = game.Treat(gameID, toGameID); + if (request.ToPlayerId >= 0 && request.ToPlayerId < options.MaxStudentCount) + { + var toGameID = communicationToGameID[request.ToPlayerId]; + boolRes.ActSuccess = game.Treat(gameID, toGameID); + } + else + { + boolRes.ActSuccess = game.Treat(gameID); + } + return Task.FromResult(boolRes); } public override Task StartLearning(IDMsg request, ServerCallContext context) @@ -250,6 +342,11 @@ namespace Server Console.WriteLine($"StartLearning ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.Fix(gameID); return Task.FromResult(boolRes); @@ -260,6 +357,11 @@ namespace Server Console.WriteLine($"StartOpenChest ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.OpenChest(gameID); return Task.FromResult(boolRes); @@ -271,6 +373,11 @@ namespace Server Console.WriteLine($"StartOpenGate ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.OpenDoorway(gameID); return Task.FromResult(boolRes); @@ -281,6 +388,11 @@ namespace Server Console.WriteLine($"OpenDoor ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.LockOrOpenDoor(gameID); return Task.FromResult(boolRes); @@ -292,6 +404,11 @@ namespace Server Console.WriteLine($"CloseDoor ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.LockOrOpenDoor(gameID); return Task.FromResult(boolRes); @@ -303,6 +420,11 @@ namespace Server Console.WriteLine($"EndAllAction ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.Stop(gameID); return Task.FromResult(boolRes); @@ -315,6 +437,11 @@ namespace Server Console.WriteLine($"SkipWindow ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } var gameID = communicationToGameID[request.PlayerId]; boolRes.ActSuccess = game.ClimbingThroughWindow(gameID); return Task.FromResult(boolRes); diff --git a/logic/cmd/gameServer.cmd b/logic/cmd/gameServer.cmd index aaca460..69be363 100644 --- a/logic/cmd/gameServer.cmd +++ b/logic/cmd/gameServer.cmd @@ -6,12 +6,10 @@ ping -n 2 127.0.0.1 > NUL start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 4 --type 2 --occupation 1 -ping -n 2 127.0.0.1 > NUL - -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 0 --type 1 --occupation 2 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 0 --type 1 --occupation 1 ping -n 2 127.0.0.1 > NUL -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 1 --type 1 --occupation 5 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 1 --type 1 --occupation 3 ping -n 2 127.0.0.1 > NUL \ No newline at end of file diff --git a/logic/规则Logic.md b/logic/规则Logic.md index 9706a85..8514bce 100644 --- a/logic/规则Logic.md +++ b/logic/规则Logic.md @@ -532,6 +532,10 @@ } ~~~ +#### 喧哗者 + + + ### 学生(&老师) #### 运动员