AnonyCAD/test0611
076
1# read a map, receive a solution, determine if the solution reaches the goal2 3import gym4from gym.envs.toy_text.frozen_lake import generate_random_map5import random6import os7import numpy as np8# from PIL import Image9 10levels = [3,4,5,6,7,8]11for level in levels:12 count = 013 correct = 014 invalid = 015 16 yes_c = 017 yes_w = 018 19 gt_answer_dir = "maps/level%d/answer/"%(level)20 check_answer_dir = "output/output_pure_text/level%d/"%(level)21 22 # import ipdb; ipdb.set_trace()23 for test_id in range(100):24 try:25 # parse answer from the output26 output_path = check_answer_dir + "%d.txt"%(test_id)27 with open(output_path, "r") as f:28 contents = f.read()29 answer_index = contents.find("<Output>")30 answer = contents[answer_index+len("<Output>"):]31 # if answer_index == -1:32 # answer_index = contents.find("Answer:")33 # answer = contents[answer_index+len("Answer:"):]34 answer = answer.replace('"', '')35 answer = answer.replace("'", '')36 answer = answer.replace("\n", '')37 answer = answer.replace(".", '')38 answer = answer.replace("(", '')39 answer = answer.replace(")", '')40 answer = answer.lstrip()41 answer = answer.rstrip()42 answer = answer.lower()43 # import ipdb; ipdb.set_trace()44 assert answer in ['yes', 'no']45 # import ipdb; ipdb.set_trace()46 # parse GT from recorded file47 gt_path = gt_answer_dir + "%d.txt"%(test_id)48 with open(gt_path, "r") as f:49 gt = f.read()50 key_dict = {'Y': 'yes', 'N': 'no'}51 gt = key_dict[gt]52 if answer == gt:53 correct += 154 if answer == 'yes':55 yes_c += 156 else:57 if answer == 'yes':58 yes_w += 159 count += 160 # print(answer)61 except:62 # import ipdb; ipdb.set_trace()63 invalid += 164 count += 165 pass66 67 # print(yes_c)68 # print(yes_w)69 print("=====Curr Level: %d======"%(level))70 print("Total tested: %d"%(count))71 print("Total correct: %d"%(correct))72 print("Total invalid: %d"%(invalid))73 