get_action(...) and BotFail - ArtemisFowlJnr/KotH GitHub Wiki

Syntax:

def get_action(filename, retry=1, timeout=5,
               validate=lambda _, _: True, get_input=lambda _: ''):

Parameters:

  • filename - the name of the file to run
  • retry - the maximum number of times to rerun the program if we don't get an valid output (including the first try). If it is 0, we run forever
  • timeout - the maximum time, in seconds, to give a program to run
  • validate - a function that should accept the filename and output, and return boolean to indicate wether or not the output was valid. The default always returns True
  • get_input - a function that, given the filname, returns a string to pass to the program. Default returns empty string

Output

It returns either the action, if it got a successful one, or an instanc of the BotFail class, containing details.

BotFail

Contains four fields:

  • filename - the filename of the failed bot
  • timeout - True if the bot ran out of time on its last run, False otherwise
  • error - None if the bot did not give an error last run, the error (a string) otherwise
  • invalid - True if the bot gave an invalid response last run, False otherwise