forked from nickMont/VerSynthProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslugsParser.m
56 lines (51 loc) · 1.62 KB
/
slugsParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%clear;clc;
%tested for:
% "variables": ["[email protected]", "evader@1", "evader@2", "evader@3", "[email protected]", "pursuer@1", "pursuer@2", "pursuer@3"],
%NOTE: CANNOT HAVE WHITESPACE OR TRAILING WHITESPACE
fname='PE_20_readready.txt';
fid=fopen(fname,'r');
tline=fgetl(fid);
n=0; j=0;
cont=true;
stateno={};
N=5; %length of binary encode in map
evaPos={}; purPos={};
successors={};
nOffset=1; %offset difference between 0 (entry in SLUGS) and lowest numerical value in map
while cont
if mod(n,5)==0 %ID #
j=j+1;
k=strfind(tline,'"');
%stateno{j}=str2num(tline(k(1)+1:k(2)-1))+1;
stateno{j}=j;
elseif mod(n,5)==1 %rank, ignore
elseif mod(n,5)==2 %state eva/pur, unpack from binary
tline2=strsplit(tline);
tempsum=0;
for i=3:2+N
tt=tline2{i}; tt=strrep(tt,'[',''); tt=strrep(tt,',',''); %remove OPEN bracket
tempsum=tempsum+2^(i-3)*str2num(tt);
evaPos{j}=tempsum+nOffset;
end
tempsum=0;
for i=3+N:2*N+2
tt=tline2{i}; tt=strrep(tt,']',''); tt=strrep(tt,',',''); %remove CLOSE bracket
tempsum=tempsum+2^(i-3-N)*str2num(tt);
purPos{j}=tempsum+nOffset;
end
elseif mod(n,5)==3 %possible successors
successors{j}=[];
tline2=strsplit(tline);
for i=2:length(tline2)
tt=tline2{i}; tt=strrep(tt,'[',''); tt=strrep(tt,',',''); tt=strrep(tt,']','');
successors{j}=[successors{j} str2num(tt)+1];
end
elseif mod(n,5)==0 %blankline
end
n=n+1;
tline=fgetl(fid);
if tline==-1
cont=false;
end
end
fclose(fid);