10
10
11
11
12
12
class ShipDebugAPI (IShipAPI , IGameTimer ):
13
- def __init__ (self , logic : ILogic , file : bool , screen : bool , warnOnly : bool , playerID : int ) -> None :
13
+ def __init__ (self , logic : ILogic ,
14
+ file : bool , screen : bool , warnOnly : bool ,
15
+ playerID : int , teamID : int ) -> None :
14
16
self .__logic = logic
15
17
self .__pool = ThreadPoolExecutor (20 )
16
18
self .__startPoint = datetime .datetime .now ()
@@ -25,11 +27,9 @@ def __init__(self, logic: ILogic, file: bool, screen: bool, warnOnly: bool, play
25
27
26
28
fileHandler = logging .FileHandler (
27
29
os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))
28
- + "/logs/api-"
29
- + str (playerID )
30
- + "-log.txt" ,
30
+ + f"/logs/api-{ teamID } -{ playerID } -log.txt" ,
31
31
mode = "w+" ,
32
- encoding = "utf-8" ,
32
+ encoding = "utf-8"
33
33
)
34
34
screenHandler = logging .StreamHandler ()
35
35
if file :
@@ -224,17 +224,16 @@ def GetScore(self) -> int:
224
224
225
225
def HaveView (self , gridX : int , gridY : int ) -> bool :
226
226
return self .__logic .HaveView (
227
- gridX ,
228
- gridY ,
229
- self .GetSelfInfo ().x ,
230
- self .GetSelfInfo ().y ,
227
+ gridX , gridY ,
228
+ self .GetSelfInfo ().x , self .GetSelfInfo ().y ,
231
229
self .GetSelfInfo ().viewRange ,
232
230
)
233
231
234
232
def Print (self , cont : str ) -> None :
235
233
self .__logger .info (cont )
236
234
237
235
def PrintShip (self ) -> None :
236
+ self .__logger .info ("START PrintShip" )
238
237
for ship in self .__logic .GetShips ():
239
238
self .__logger .info ("******ship Info******" )
240
239
self .__logger .info (
@@ -253,6 +252,7 @@ def PrintShip(self) -> None:
253
252
f"armorType:{ ship .armorType } shieldType:{ ship .shieldType } weaponType:{ ship .weaponType } "
254
253
)
255
254
self .__logger .info ("************************\n " )
255
+ self .__logger .info ("END PrintShip" )
256
256
257
257
def PrintTeam (self ) -> None :
258
258
pass
@@ -295,33 +295,26 @@ def Play(self, ai: IAI) -> None:
295
295
296
296
297
297
class TeamDebugAPI (ITeamAPI , IGameTimer ):
298
- def __init__ (
299
- self , logic : ILogic , file : bool , screen : bool , warnOnly : bool , playerID : int
300
- ) -> None :
298
+ def __init__ (self , logic : ILogic ,
299
+ file : bool , screen : bool , warnOnly : bool ,
300
+ playerID : int , teamID : int ) -> None :
301
301
self .__logic = logic
302
302
self .__pool = ThreadPoolExecutor (20 )
303
303
self .__startPoint = datetime .datetime .now ()
304
304
self .__logger = logging .getLogger ("api " + str (playerID ))
305
305
self .__logger .setLevel (logging .DEBUG )
306
306
formatter = logging .Formatter (
307
- "[%(name)s] [%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s" ,
308
- "%H:%M:%S" ,
307
+ "[%(name)s] [%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s" , "%H:%M:%S"
309
308
)
310
309
# 确保文件存在
311
- if not os .path .exists (
312
- os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) + "/logs"
313
- ):
314
- os .makedirs (
315
- os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) + "/logs"
316
- )
310
+ if not os .path .exists (os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) + "/logs" ):
311
+ os .makedirs (os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) + "/logs" )
317
312
318
313
fileHandler = logging .FileHandler (
319
314
os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))
320
- + "/logs/api-"
321
- + str (playerID )
322
- + "-log.txt" ,
315
+ + f"/logs/api-{ teamID } -{ playerID } -log.txt" ,
323
316
mode = "w+" ,
324
- encoding = "utf-8" ,
317
+ encoding = "utf-8"
325
318
)
326
319
screenHandler = logging .StreamHandler ()
327
320
if file :
@@ -469,6 +462,7 @@ def Print(self, cont: str) -> None:
469
462
self .__logger .info (cont )
470
463
471
464
def PrintShip (self ) -> None :
465
+ self .__logger .info ("START PrintShip" )
472
466
for ship in self .__logic .GetShips ():
473
467
self .__logger .info ("******ship Info******" )
474
468
self .__logger .info (
@@ -487,6 +481,7 @@ def PrintShip(self) -> None:
487
481
f"armorType:{ ship .armorType } shieldType:{ ship .shieldType } weaponType:{ ship .weaponType } "
488
482
)
489
483
self .__logger .info ("************************\n " )
484
+ self .__logger .info ("END PrintShip" )
490
485
491
486
def PrintTeam (self ) -> None :
492
487
self .PrintSelfInfo ()
@@ -499,9 +494,7 @@ def PrintSelfInfo(self) -> None:
499
494
self .__logger .info ("************************\n " )
500
495
501
496
def __GetTime (self ) -> float :
502
- return (datetime .datetime .now () - self .__startPoint ) / datetime .timedelta (
503
- milliseconds = 1
504
- )
497
+ return (datetime .datetime .now () - self .__startPoint ) / datetime .timedelta (milliseconds = 1 )
505
498
506
499
def StartTimer (self ) -> None :
507
500
self .__startPoint = datetime .datetime .now ()
@@ -512,4 +505,4 @@ def EndTimer(self) -> None:
512
505
self .__logger .info (f"Time elapsed: { self .__GetTime ()} ms" )
513
506
514
507
def Play (self , ai : IAI ) -> None :
515
- ai .ShipPlay (self )
508
+ ai .TeamPlay (self )
0 commit comments