예제 #1
0
def play(method):
    score = throw.START_SCORE
    turns = 0

    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()

    targets = []
    results = []
    while (True):
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        if raw_score <= score:
            score = int(score - raw_score)
        else:
            cc = 1
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)

# print "WOOHOO!  It only took", turns, " turns"
#end_game(turns)
    return turns
예제 #2
0
def play(method):
    score = throw.START_SCORE
    turns = 0
    
    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()
        
    targets = []
    results = []
    while(True):
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        if raw_score <= score:
            score = int(score - raw_score)
        else:
            cc=1
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)
            
   # print "WOOHOO!  It only took", turns, " turns"
    #end_game(turns)
    return turns
예제 #3
0
def play(method):
    global actions
    actions = get_actions()

    score = throw.START_SCORE
    turns = 0
    
    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()
        
    targets = []
    results = []
    while(True):
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        print "Target: wedge", target.wedge,", ring", target.ring
        print "Result: wedge", result.wedge,", ring", result.ring
        print "Raw Score:", raw_score
        print "Score:", score
        prior = score
        if raw_score <= score:
            score = int(score - raw_score)
        else:
            print
            print "TOO HIGH!"
        modelfree.q_learning(prior, score, get_index(actions, target))                        
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)
            
    print "WOOHOO!  It only took", turns, " turns"
    #end_game(turns)
    return turns
예제 #4
0
파일: darts.py 프로젝트: wyao/intro_to_ai
def play(method, d=None):
    score = throw.START_SCORE
    turns = 0

    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()

    targets = []
    results = []
    while True:
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        if d:
            if d[score] == None:
                d[score] = throw.location_to_score(target)
            else:
                assert d[score] == throw.location_to_score(target)
        # print "Target: wedge", target.wedge,", ring", target.ring
        # print "Result: wedge", result.wedge,", ring", result.ring
        # print "Raw Score:", raw_score
        # print "Score:", score
        if raw_score <= score:
            score = int(score - raw_score)
        # else:
        #     print
        #     print "TOO HIGH!"
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)
    # print "WOOHOO!  It only took", turns, " turns"
    # end_game(turns)
    return turns
예제 #5
0
파일: darts.py 프로젝트: rlucioni/cs181
def play(method):
    score = throw.START_SCORE
    turns = 0
    
    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()
        
    targets = []
    results = []
    while(True):
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        #if raw_score > score:
            # update Q[s][a]
        #else:
            #modelfree.Q_learning(score,target,raw_score)
        print "Target: wedge", target.wedge,", ring", target.ring
        print "Result: wedge", result.wedge,", ring", result.ring
        print "Raw Score:", raw_score
        print "Score:", score
        if raw_score <= score:
            score = int(score - raw_score)
        else:
            print
            print "TOO HIGH!"
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)
            
    print "WOOHOO!  It only took", turns, " turns"
    #end_game(turns)
    return turns
예제 #6
0
파일: darts.py 프로젝트: rboling/hw5181
def play(method):
    score = throw.START_SCORE
    turns = 0

    if method == "mdp":
        target = mdp.start_game(GAMMA)
    else:
        target = modelfree.start_game()

    targets = []
    results = []
    while (True):
        turns = turns + 1
        result = throw.throw(target)
        targets.append(target)
        results.append(result)
        raw_score = throw.location_to_score(result)
        print "Target: wedge", target.wedge, ", ring", target.ring
        print "Result: wedge", result.wedge, ", ring", result.ring
        print "Raw Score:", raw_score
        print "Score:", score
        if raw_score <= score:
            score = int(score - raw_score)
        else:
            print
            print "TOO HIGH!"
        if score == 0:
            break

        if method == "mdp":
            target = mdp.get_target(score)
        else:
            target = modelfree.get_target(score)

    print "WOOHOO!  It only took", turns, " turns"
    #end_game(turns)
    return turns