Advertisement
Guest User

StarCraft minimalistic python bot examples

a guest
Dec 27th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. ### MINIMALISTIC BOT EXAMPLE 1 ###
  2. import cybw
  3. import time
  4.  
  5. client = cybw.BWAPIClient
  6. Broodwar = cybw.Broodwar
  7.  
  8. def connect():
  9.     while not client.connect():
  10.         time.sleep(0.5)
  11.  
  12. connect()
  13. while True:
  14.     while not Broodwar.isInGame():
  15.         client.update()
  16.         if not client.isConnected():
  17.             connect()
  18.     # >>> YOUR STARTING BOT CODE GOES HERE <<<
  19.     while Broodwar.isInGame():
  20.         # >>> YOUR MAIN BOT CODE GOES HERE <<<
  21.         client.update()
  22.     else:
  23.         # >>> YOUR POST-GAME CODE GOES HERE <<<
  24.         quit()
  25.  
  26. ### MINIMALISTIC BOT EXAMPLE 2 ###
  27. import cybw
  28. import time
  29.  
  30. client = cybw.BWAPIClient
  31. Broodwar = cybw.Broodwar
  32.  
  33. # Pre-game connection-establishing cycle
  34. while True:
  35.     if not client.isConnected():
  36.         # Trying to connect to the game
  37.         client.connect()
  38.         time.sleep(0.5)
  39.     elif not Broodwar.isInGame():
  40.         # Waiting in game menu for a match to commence
  41.         client.update()
  42.     else:
  43.         # Finishing cycle after successful connection and match commencing
  44.         break
  45.  
  46. while Broodwar.isInGame():
  47.     # >>> YOUR BOT GAME LOGIC CODE GOES HERE <<<
  48.     client.update()
  49.  
  50. ### MINIMALISTIC BOT EXAMPLE 3 ###
  51. import cybw
  52. import time
  53.  
  54. client = cybw.BWAPIClient
  55. Broodwar = cybw.Broodwar
  56.  
  57. # Trying to connect to the game
  58. while not client.connect():
  59.     time.sleep(0.5)
  60.  
  61. # Waiting in game menu for a match to commence
  62. while not Broodwar.isInGame():
  63.     client.update()
  64.  
  65. # Main bot logic loop
  66. while Broodwar.isInGame():
  67.     # >>> YOUR BOT GAME LOGIC CODE GOES HERE <<<
  68.     client.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement