# This program computes creates simple feature to solve a linear
# gridworld type of problem. It comes with several positive and
# negative examples of when we should use primitive action move right.
# It generates a feature and tests to see if that feature separates the
# postive from the negative.

import string, random, operator

operators = ["lt","le","eq","ne","ge","gt"]
symbols = [" ","A","G"]

def generateFeature():
    part1 = "s.find(\"" + random.choice(symbols) + "\")"
    part2 = "s.find(\"" + random.choice(symbols) + "\")" 
    feature = "operator." + random.choice(operators) + \
              "(" + part1 + "," + part2 + ")"
    return feature

pos = ["  AG  ","AG   ","      AG","   AG"]
neg = ["  GA  ","GA   ","      GA","   GA"]

print "Seeking to find a feature which satisfies all positive examples: "
print pos
print "And to not satisfy any negative examples: "
print neg

while True:
    # Generate a Possible feature
    feat = generateFeature()
    
    gotPosExamples = True
    gotNegExamples = True

    # Check Positive Examples
    for s in pos:
        if eval(feat) == False:
            gotPosExamples = False

    # Check Negative Examples
    for s in neg:
        if eval(feat) == True:
            gotNegExamples = False

    if gotPosExamples and gotNegExamples:
        print "Found Feature Satisfying Requirements: " + feat
        break



