def menu(player): os.system('cls') choice = "" while choice != "load" or choice != "play" or choice != "quit": choice = input("What do you want to do ?\n play \n load \n rules \n quit \n >>> ") player = character.Character() if choice == "load": save.load(player) if choice == "play": return; elif choice == "quit": sys.exit("good bye") elif choice == "rules": os.system('cls') utils.printFile("text/rules")
def printTicket(self): if self.filePath is None: self.filePath = self.ticketToPdf() printFile(self.filePath)
import log import utils import save import menu import os # INIT player = character.Character() menu.menu(player) random.seed(); # random event order = "go" success = True # DAEMON os.system('cls') utils.printFile("text/intro") while player._life > 0 and order!="quit": order = input("What do you want to do ? [move - repare - status - save - load - quit]\n >>> ") if order == "move": if player.isEnergyEmpty(): log.failure("You have no more energy. You will die alone, drifting in space") event.gameOver() break; else: player._energy = player._energy-1 rand_event = random.randint(1,3) if rand_event == 1: success = event.eventNothing() elif rand_event == 2:
def loadfromstring(self, string, env): threads = env.threads rounds = env.rounds unwind = env.unwind backend = env.format self.__threadbound = threads super(Labeler, self).loadfromstring(string, env) ''' print "THREADS!\n" for t in self.__threadName: print "thread %s, index %s" %(t, self.Parser.threadIndex[t]) ''' # Add the new main(). # self.output += self.__createMain(rounds) # Thread sizes (i.e. number of visible statements) comma separated. # lines = '' #lines += str(self.__lines['main']) i = 0 maxsize = 0 for t in self.__threadName: if i <= self.__threadbound: if i>0: lines += ', ' lines += str(self.__lines[t]) maxsize = max(int(maxsize), int(self.__lines[t])) #print "CONFRONTO %s %s " % (int(maxsize), int(self.__lines[t])) #print " max: %s " % maxsize i +=1 # Generate the header. # header = utils.printFile('include/newseq-include.c') header = header.replace('<insert-version-here>', '0.0.0.0.0.0') header = header.replace('<insert-maxthreads-here>', str(threads)) header = header.replace('<insert-maxrounds-here>', str(rounds)) header = header.replace('<insert-unwind-here>', str(unwind)) header = header.replace('<insert-backend-here>', str(backend)) header = header.replace('<insert-date-here>', strftime("%Y-%m-%d %H:%M:%S", gmtime())) header = header.replace('<insert-threads-params-here>', '') # other thread parameters, they are transformed to global vars... # Instrumentation. # if backend == 'esbmc': header = header.replace('<insert-extraheaders-here>\n', '') header = header.replace('<insert-assume-here>', '__ESBMC_assume') header = header.replace('<insert-assert-here>', 'assert') header = header.replace('<insert-nondet_int-here>', 'nondet_int') header = header.replace('<insert-nondet_uint-here>', 'nondet_uint') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int();') header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint();') elif backend == 'cbmc': header = header.replace('<insert-extraheaders-here>\n', '') header = header.replace('<insert-assume-here>', '__CPROVER_assume') header = header.replace('<insert-assert-here>', 'assert') header = header.replace('<insert-nondet_int-here>', 'nondet_int') header = header.replace('<insert-nondet_uint-here>', 'nondet_uint') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int();') header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint();') # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - k = int(math.floor(math.log(maxsize,2)))+1 header = header.replace('<insert-active_thread-type-here>', '__CPROVER_bitvector[1]') header = header.replace('<insert-pc-type-here>', '__CPROVER_bitvector[%s]' % (k)) header = header.replace('<insert-pc_cs-type-here>', '__CPROVER_bitvector[%s]' % (k+1)) # pc_cs stores the sum of two bitvectors of size (k+1), needs to be one bit wider header = header.replace('<insert-thread_index-type-here>', 'int') header = header.replace('<insert-thread_lines-type-here>', '__CPROVER_bitvector[%s]' % (k)) elif backend == 'smack': header = header.replace('<insert-extraheaders-here>\n', '#define SMACK_H_\n#define __VERIFIER_assume __SMACK_assume\n#define __VERIFIER_assert __SMACK_assert\n#define assert __SMACK_assert\nvoid __SMACK_assert(int val);\nvoid __SMACK_assume(int val);\nint __SMACK_nondet(void);\n\n') header = header.replace('<insert-assume-here>', '__SMACK_assume') header = header.replace('<insert-assert-here>', 'assert') header = header.replace('<insert-nondet_int-here>', '__SMACK_nondet') header = header.replace('<insert-nondet_uint-here>', '__SMACK_nondet') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int();') ## TODO: see how it was done in the manual translation header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint();') elif backend == 'llbmc': header = header.replace('<insert-extraheaders-here>\n', '') header = header.replace('<insert-assume-here>', '__llbmc_assume') header = header.replace('<insert-assert-here>', 'assert') header = header.replace('<insert-nondet_int-here>', 'nondet_int') header = header.replace('<insert-nondet_uint-here>', 'nondet_uint') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int();') header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint();') elif backend == 'satabs': header = header.replace('<insert-extraheaders-here>\n', '') header = header.replace('<insert-assume-here>', '__CPROVER_assume') header = header.replace('<insert-assert-here>', 'assert') header = header.replace('<insert-nondet_int-here>', 'nondet_int') header = header.replace('<insert-nondet_uint-here>', 'nondet_uint') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int();') header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint();') elif backend == 'klee': header = header.replace('<insert-extraheaders-here>\n', '#include <klee/klee.h>\n') header = header.replace('<insert-assume-here>', 'klee_assume') header = header.replace('<insert-assert-here>', 'klee_assert') header = header.replace('<insert-nondet_int-here>', 'nondet_int') header = header.replace('<insert-nondet_uint-here>', 'nondet_uint') header = header.replace('<insert-nondet_int-body-here>', 'int nondet_int() { int x; klee_make_symbolic(&x, sizeof(x), "x"); return x; }') header = header.replace('<insert-nondet_uint-body-here>', 'unsigned int nondet_uint() { unsigned int x; klee_make_symbolic(&x, sizeof(x), "x"); return x; }') header = header.replace('<insert-threadsizes-here>', lines); # Fix gotos by inserting ASS_GOTO(..) blocks before each goto, # excluding gotos which destination is the line below. # for (a,b) in self.__labelLine: if (a,b) in self.__gotoLine and (self.__labelLine[a,b] == self.__gotoLine[a,b]+1): self.output = self.output.replace('<%s,%s>' % (a, b), '') else: self.output = self.output.replace('<%s,%s>' % (a, b), 'ASS_GOTO(%s)' % self.__labelLine[a,b]) # Fix indentation. # new = '' for line in self.output.splitlines(): if len(line) > 0 and (line[0] == self.__startChar or line.startswith('IF(')): #if len(line) > 0 and re.search(r'[a-zA-Z0-9]+', line[0]): new += line + '\n' else: new += self.__labelLength*' ' + line + '\n' ''' if self.Parser.funcBlockIn['main'] not in ('', 'void'): # forward main() parameters to main_thread() self.output = self.output.replace('<insert-main-params-here>', self.Parser.funcBlockIn['main'].replace(',', ';')+ ';') else: self.output = self.output.replace('<insert-main-params-here>', '') ''' self.output = header + '\n\n' + new