|
|
|
|
|
import gym |
|
from gym.envs.toy_text.frozen_lake import generate_random_map |
|
import random |
|
import os |
|
import numpy as np |
|
|
|
|
|
count = 0 |
|
full_correct = 0 |
|
part_correct = 0 |
|
invalid = 0 |
|
|
|
level = 8 |
|
|
|
check_map_dir = "../../maps/level%d_text/"%(level) |
|
check_answer_dir = "output/output_img/" |
|
|
|
def find_symbol(map, symbol): |
|
|
|
|
|
results = [] |
|
for i in range(len(map)): |
|
for j in range(len(map)): |
|
if map[i][j] == symbol: |
|
results.append([i, j]) |
|
return results |
|
|
|
|
|
|
|
|
|
|
|
for test_id in range(100): |
|
|
|
|
|
with open(check_map_dir + '%d.txt'%(test_id), 'r') as f: |
|
contents = f.read() |
|
rows = contents.split('\n') |
|
|
|
|
|
player_pos = find_symbol(rows, 'S')[0] |
|
goal_pos = find_symbol(rows, 'G')[0] |
|
answer_set = set() |
|
if player_pos[0] > goal_pos[0]: |
|
answer_set.add('Below') |
|
elif player_pos[0] < goal_pos[0]: |
|
answer_set.add('Above') |
|
if player_pos[1] > goal_pos[1]: |
|
answer_set.add('Right') |
|
elif player_pos[1] < goal_pos[1]: |
|
answer_set.add('Left') |
|
count += len(answer_set) |
|
|
|
|
|
try: |
|
|
|
with open(check_answer_dir + 'level%d/%d.txt'%(level, test_id), 'r') as f: |
|
contents = f.read() |
|
answer_index = contents.find('<Output> ') |
|
if answer_index == -1: |
|
answer_index = contents.find('<Output>\n') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if answer_index == -1: |
|
assert 0 |
|
answer = contents[answer_index+9:] |
|
answer = answer.split(',') |
|
for answer_index in range(len(answer)): |
|
answer[answer_index] = answer[answer_index].replace('"', '') |
|
answer[answer_index] = answer[answer_index].replace("'", '') |
|
answer[answer_index] = answer[answer_index].replace("\n", '') |
|
answer[answer_index] = answer[answer_index].replace(".", '') |
|
answer[answer_index] = answer[answer_index].replace("*", '') |
|
answer[answer_index] = answer[answer_index].lstrip() |
|
answer[answer_index] = answer[answer_index].rstrip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
ALL_CORR = True |
|
for answer_char in answer_set: |
|
if answer_char in answer: |
|
part_correct += 1 |
|
else: |
|
ALL_CORR = False |
|
|
|
if ALL_CORR: |
|
full_correct += 1 |
|
except: |
|
|
|
|
|
invalid += 1 |
|
print(test_id) |
|
|
|
pass |
|
|
|
print("Total tested: %d"%(count)) |
|
print("Part correct: %d"%(part_correct)) |
|
print("Each correct rate: %f"%(part_correct / count)) |
|
print("Full correct: %d"%(full_correct)) |
|
print("Invalid: %d"%(invalid)) |
|
|