You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. #!/usr/bin/env python
  2. import subprocess
  3. import sys
  4. import json
  5. def stringToCommandSequence(string):
  6. commandsSequence = ""
  7. phrase = ""
  8. string = string.lower()
  9. for char in string:
  10. found = False
  11. for i in range(0, len(characters)):
  12. if char in characters[i]:
  13. phrase += characters[i][0]
  14. commandsSequence += commands[i]
  15. found = True
  16. continue
  17. if found == False:
  18. print "error in conversion: %s, %s"%(string, char)
  19. sys.exit(1)
  20. return phrase
  21. commands = ['MoveW',
  22. 'MoveE',
  23. 'MoveSW',
  24. 'MoveSE',
  25. 'RotateClockwise',
  26. 'RotateCounterclockwise']
  27. characters = [['p', "'", '!', '.', '0', '3'],
  28. ['b', 'c', 'e', 'f', 'y', '2'],
  29. ['a', 'g', 'h', 'i', 'j', '4'],
  30. ['l', 'm', 'n', 'o', ' ', '5'],
  31. ['d', 'q', 'r', 'v', 'z', '1'],
  32. ['k', 's', 't', 'u', 'w', 'x']]
  33. with open('Phrases of power') as f:
  34. phrases = f.readlines()
  35. f.close()
  36. process = subprocess.Popen(['curl --user :2aaFCkjNIDHAsAIh9iQHc+Y+FGhkM5Z0RQgpO6TL6EA= -X GET https://davar.icfpcontest.org/teams/235/solutions'], shell = True, stdout=subprocess.PIPE)
  37. out, err = process.communicate()
  38. if err == None:
  39. serverResults = json.loads(out)
  40. else:
  41. print "unable to fetch server"
  42. sys.exit(1)
  43. powerPhrases = []
  44. for phrase in phrases:
  45. if phrase != "\n" and phrase[0] != '#':
  46. phrase = phrase.lower()[:-1]
  47. found = False
  48. for serverResult in serverResults:
  49. if serverResult['solution'].encode('ascii','replace') == phrase :
  50. found = True
  51. if serverResult['powerScore'] > 0:
  52. print "Eureka! %s powerScore: %s score: %s"%(phrase , serverResult['powerScore'], serverResult['score'])
  53. powerPhrases.append(phrase )
  54. break
  55. elif serverResult['powerScore'] is None:
  56. print " Evaluation pending on %s"%phrase
  57. break
  58. if found:
  59. continue
  60. for i in range (0, 25):
  61. process = subprocess.Popen(['src/TestSolution -f sample_problems/problem_'+str(i)+'.json -n 0 -p ' + stringToCommandSequence(phrase )], shell = True, stdout=subprocess.PIPE)
  62. out, err = process.communicate()
  63. if err == None and out.find("Error") == -1 and out.find("Irrefutable") == -1:
  64. break
  65. if err == None and out.find("Error") == -1 and out.find("Irrefutable") == -1:
  66. OUTPUT=('[{"seed":0,"tag":"shapeShifter","solution":"%s","problemId":12}]'%phrase ).replace('"', "\\\"")
  67. process = subprocess.Popen(['curl --user :2aaFCkjNIDHAsAIh9iQHc+Y+FGhkM5Z0RQgpO6TL6EA= -X POST -H "Content-Type: application/json" -d "' + OUTPUT + '" https://davar.icfpcontest.org/teams/235/solutions'], shell = True, stdout=subprocess.PIPE)
  68. out, err = process.communicate()
  69. if err == None and out == "created":
  70. print "%s sended"%phrase
  71. else:
  72. print out
  73. print " %s unable to comunicate with server"%phrase
  74. else:
  75. print " %s return error"%phrase
  76. print "\n%d power phrases found:"%len(powerPhrases)
  77. for powerPhrase in powerPhrases:
  78. print powerPhrase
  79. #print "\n%d power phrases found only on server:"%len(powerPhrases)
  80. #for serverResult in serverResults:
  81. # if serverResult['powerScore'] > 0:
  82. # if serverResult['solution'].replace('\n', '') not in powerPhrases:
  83. # print serverResult['solution'], serverResult['powerScore']