You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

logic.py 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. from abc import abstractmethod
  2. from typing import List, Union, Callable
  3. import threading
  4. from Interface import ILogic, IGameTimer
  5. from State import State
  6. import structures as THUAI6
  7. import proto.Message2Clients_pb2 as Message2Clients
  8. import proto.Message2Server_pb2 as Message2Server
  9. import proto.MessageType_pb2 as MessageType
  10. class Logic(ILogic):
  11. def __init__(self, playerType: THUAI6.PlayerType, playerID: int, humanType: THUAI6.HumanType, butcherType: THUAI6.ButcherType) -> None:
  12. # 类型、ID
  13. self.__playerType: THUAI6.PlayerType = playerType
  14. self.__playerID: int = playerID
  15. self.__humanType: THUAI6.HumanType = humanType
  16. self.__butcherType: THUAI6.ButcherType = butcherType
  17. # 存储状态
  18. self.__currentState: State
  19. self.__bufferState: State
  20. # timer,用于实际运行AI
  21. self.__timer: IGameTimer
  22. # AI线程
  23. self.__threadAI: threading.Thread
  24. # 互斥锁
  25. self.__mtxAI: threading.Lock
  26. self.__mtxBuffer: threading.Lock
  27. self.__mtxTimer: threading.Lock
  28. # 条件变量
  29. self.__cvBuffer: threading.Condition
  30. self.__cvAI: threading.Condition
  31. # 保存缓冲区数
  32. self.__counterState: int
  33. self.__counterBuffer: int
  34. # 记录游戏状态
  35. self.__gameState: THUAI6.GameState = THUAI6.GameState.NullGameState
  36. # 是否应该执行player()
  37. self.__AILoop: bool = True
  38. # buffer是否更新完毕
  39. self.__bufferUpdated: bool = False
  40. # 是否应当启动AI
  41. self.__AIStart: bool = False
  42. # asynchronous为true时控制内容更新的变量
  43. self.__freshed: bool = False
  44. # IAPI统一可用的接口
  45. def GetButchers(self) -> List[THUAI6.Butcher]:
  46. pass
  47. def GetHumans(self) -> List[THUAI6.Human]:
  48. pass
  49. def GetProps(self) -> List[THUAI6.Prop]:
  50. pass
  51. def GetSelfInfo(self) -> Union[THUAI6.Human, THUAI6.Butcher]:
  52. pass
  53. def GetFullMap(self) -> List[List[THUAI6.PlaceType]]:
  54. pass
  55. def GetPlaceType(self, x: int, y: int) -> THUAI6.PlaceType:
  56. pass
  57. def Move(self, time: int, angle: float) -> bool:
  58. pass
  59. def PickProp(self, propType: THUAI6.PropType) -> bool:
  60. pass
  61. def UseProp(self) -> bool:
  62. pass
  63. def UseSkill(self) -> bool:
  64. pass
  65. def SendMessage(self, toID: int, message: str) -> bool:
  66. pass
  67. def HaveMessage(self) -> bool:
  68. pass
  69. def GetMessage(self) -> tuple[int, str]:
  70. pass
  71. def WaitThread(self) -> bool:
  72. pass
  73. def GetCounter(self) -> int:
  74. pass
  75. def GetPlayerGUIDs(self) -> List[int]:
  76. pass
  77. # IHumanAPI使用的接口
  78. def Escape(self) -> bool:
  79. pass
  80. def StartFixMachine(self) -> bool:
  81. pass
  82. def EndFixMachine(self) -> bool:
  83. pass
  84. def StartSaveHuman(self) -> bool:
  85. pass
  86. def EndSaveHuman(self) -> bool:
  87. pass
  88. # Butcher使用的接口
  89. def Attack(self, angle: float) -> bool:
  90. pass
  91. def CarryHuman(self) -> bool:
  92. pass
  93. def ReleaseHuman(self) -> bool:
  94. pass
  95. def HangHuman(self) -> bool:
  96. pass
  97. # Logic内部逻辑
  98. def __TryConnection(self) -> bool:
  99. pass
  100. def __ProcessMessage(self) -> None:
  101. pass
  102. def __LoadBuffer(self) -> None:
  103. pass
  104. def __UnBlockBuffer(self) -> None:
  105. pass
  106. def __UnBlockAI(self) -> None:
  107. pass
  108. def __Update(self) -> None:
  109. pass
  110. def __Wait(self) -> None:
  111. pass
  112. def Main(self, createAI: Callable, IP: str, port: str, file: bool, print: bool, warnOnly: bool) -> None:
  113. pass