Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- # A - Attack
- # B - Break
- # G - Guard
- # S - Skill
- # - - Wait
- # ? - Unknown
- # 6 commands
- # Allow user to input enemy name/identifier. Check if a f exists with that name in the directory the Python f was opened from; if there is a f of that name, open it. If there isn't, create it.
- # From there, allow user to add new patterns, attempt to match patterns, view all patterns, or save and quit that f.
- # Show how many sequences are recorded for the selected enemy.
- # When adding a pattern, show valid codes above text entry bit. '?' is not a valid code at this point. There are 6 commands in a sequence.
- # Check string for validity - each character should match '(?ABGS-)'
- # Confirm adding.
- # When matching, allow 'Unknown' code in addition to the rest above.
- # Use regex. Construct a string: '?' should become '.'
- exit = False
- input = "0"
- inputMatch = re.compile("(A|B|G|S|-)(A|B|G|S|-)(A|B|G|S|-)(A|B|G|S|-)(A|B|G|S|-)(A|B|G|S|-)")
- while True:
- print "Feldherren's Useful Fate/Extra Enemy Sequence Matching Tool\n"
- print "1. Enter enemy name"
- print "2. Quit"
- input = raw_input("> ")
- if input == "1":
- input = "0"
- print ""
- filename = raw_input("Enemy name: ")
- if os.path.exists(os.path.realpath(__file__)[:-28] + filename + ".txt"):
- print "Opening " + filename + ".txt"
- f = open(filename+'.txt', 'r+')
- else:
- print "Enemy f " + filename + ".txt not found - creating new file"
- f = open(filename+'.txt', 'a+')
- f.close()
- f = open(filename+'.txt', 'r+')
- while True:
- print "Enemy file: " + filename + ".txt\n"
- print "1. Add new sequence"
- print "2. Match sequence"
- print "3. Output all sequences"
- # print "4. Remove sequence"
- print "4. Return to main menu"
- input = raw_input("> ")
- if input == "1":
- input = "0"
- print "Enter new enemy action sequence. Valid characters:"
- print "A: Attack"
- print "B: Break"
- print "G: Guard"
- print "S: Skill"
- print "-: Wait"
- print ""
- s = raw_input("Sequence: ")
- if inputMatch.match(s) is not None:
- # checking for duplicates
- f = open(filename+'.txt', 'r+')
- l = f.readline()
- f.close
- l = l.split(",")
- duplicate = False
- for sequence in l:
- if s == sequence:
- duplicate = True
- if duplicate != True:
- f = open(filename+'.txt', 'a+')
- f.write(s + "," )
- f.close()
- else:
- print "Sequence already exists."
- else:
- print "Error: entered sequence is not valid pattern.\n"
- elif input == "2":
- input = "0"
- print "Enter enemy action sequence to match. Valid characters:"
- print "A: Attack"
- print "B: Break"
- print "G: Guard"
- print "S: Skill"
- print "-: Wait"
- print "?: Unknown"
- print ""
- input = raw_input("Sequence: ")
- matchSequence = input.replace("?", ".")
- matchSequence = re.compile(matchSequence)
- f = open(filename+'.txt', 'r+')
- l = f.readline()
- f.close
- l = l.split(",")
- for sequence in l:
- if matchSequence.match(sequence) is not None:
- print sequence
- input = "0"
- elif input == "3":
- input = "0"
- print "All sequences for " + filename + ":"
- f = open(filename+'.txt', 'r+')
- l = f.readline()
- f.close
- l = l.split(",")
- for sequence in l:
- print sequence
- # elif input == "4": # If you get curious, this was my attempt at removing
- # input = "0"
- # print "Enter enemy action sequence to remove. Valid characters:"
- # print "A: Attack"
- # print "B: Break"
- # print "G: Guard"
- # print "S: Skill"
- # print "-: Wait"
- # print ""
- # s = raw_input("Sequence: ")
- # if inputMatch.match(s) is not None:
- # f = open(filename+'.txt', 'r+')
- # l = f.readline()
- # f.close
- # l = l.split(",")
- # if s in l:
- # l.pop(l.index(s))
- #
- # for i in l: # here it starts petering out as I started wondering '...wait, does he really need this?' This would have made one comma-separated string from the list l again
- #
- # f = open(filename+'.txt', 'r+') # opening a file in mode 'r+' as opposed to 'a+' will simply have it write over all the contents. I basically went 'ehh' when I realised I'd have to make one string of the list for it to work.
- #
- # else:
- # print "Error: entered sequence is not valid pattern.\n"
- elif input == "4":
- input = "0"
- break
- elif input == "2":
- input = "0"
- break
- #print ""
Advertisement
Add Comment
Please, Sign In to add comment