예제 #1
0
def main():
    if len(sys.argv) != 2:
        print "Usage: Lab4.py <Filename>"
        sys.exit(1)

    puzzle_file = open(sys.argv[1], "r")

    contents = puzzle_file.read()
    print "PUZZLE:"
    print contents

    # :)
    modified_contents = re.sub("\n\n", "\n", contents)

    p = Parser()
    statements, name_map = p.convert(modified_contents)
    results = evaluate_puzzle(statements)

    if results[0] == True:
        result = "A is a knight and B is a knave"
    elif results[1] == True:
        result = "A is a knave and B is a knight"
    elif results[2] == True:
        result = "A is a knight and B is a knight"
    elif results[3] == True:
        result = "A is a knave and B is a knave"
    else:
        result = "Indeterminate"

    aval = ""
    bval = ""

    for key, val in name_map.iteritems():
        if val == "A":
            aval = key
        if val == "B":
            bval = key

    result = re.sub("A", aval.lower(), result)
    result = re.sub("B", bval.lower(), result)

    print "\nRESULT:"
    print result

    puzzle_file.close()
예제 #2
0
def main():
   if len(sys.argv) != 2:
       print "Usage: Lab4.py <Filename>"
       sys.exit(1)

   puzzle_file = open(sys.argv[1], "r")

   contents = puzzle_file.read()
   print "PUZZLE:"
   print contents

   # :) 
   modified_contents = re.sub("\n\n", "\n", contents)
   
   p = Parser()
   statements, name_map = p.convert(modified_contents)
   results = evaluate_puzzle(statements)

   if results[0] == True:
      result =  "A is a knight and B is a knave"
   elif results[1] == True:
      result = "A is a knave and B is a knight"
   elif results[2] == True:
      result = "A is a knight and B is a knight"
   elif results[3] == True:
      result = "A is a knave and B is a knave"
   else:
      result = "Indeterminate"

   aval = ""
   bval = ""

   for key, val in name_map.iteritems():
      if val == "A":
         aval = key
      if val == "B":
         bval = key

   result = re.sub("A", aval.lower(), result)
   result = re.sub("B", bval.lower(), result)

   print "\nRESULT:"
   print result

   puzzle_file.close()
예제 #3
0
]

retrieved = []
p = Parser()

count = 0

calculated = []
for ndx, t in enumerate(list):
    statements, _ = p.convert(t)

    #    print t

    #    print "Testing results..." + str(ndx)
    try:
        results = evaluate_puzzle(statements)
#        print results
    except SyntaxError:
        print "Syntax Error on #%d" % (ndx), traceback.format_exc()
#    print
    trues = 0

    if results[0] == True:
        result = "A is a knight and B is a knave"
        trues += 1
    if results[1] == True:
        result = "A is a knave and B is a knight"
        trues += 1
    if results[2] == True:
        result = "A is a knight and B is a knight"
        trues += 1