function [park, cellID, obs] = plotRobotSim(simfile, numrow, numcol, discdynfile)

fid = fopen(simfile, 'r');
park = [];
cellID = [];
obs = [];

while (~feof(fid))
    tline = fgetl(fid);
    [s f t]=regexp(tline,'(\w+):(\d+)');
    for i=1:length(t)
        var = tline([t{i}(1,1):t{i}(1,2)]);
        value = str2num(tline([t{i}(2,1):t{i}(2,2)]));    
        if (strcmp(var, 'park'))
            park = [park value];
        elseif (strcmp(var, 'cellID'))
            cellID = [cellID value];
        elseif (strcmp(var, 'obs'))
            obs = [obs value];
        end
    end
end

fclose(fid);

if (nargin > 3)
    disc_dynamics = [];
    fid = fopen(discdynfile, 'r');
    tline = fgetl(fid);
    [s f t]=regexp(tline,'X(\d+)');
    list_prop = [];
    for i = 1:length(t)
        list_prop = [list_prop str2num(tline([t{i}(1,1):t{i}(1,2)]))];
    end
    while (~feof(fid))
        tline = fgetl(fid);
        disc_dynamics = [disc_dynamics; str2num(tline)];
    end
    fclose(fid);
    for i = 1:length(cellID)
        cellID(i) = list_prop(find(disc_dynamics(cellID(i)+1, :)==1, 1, 'first'));
    end
end

figure;

for i=1:min(length(park), length(cellID))
    clf;
    hplot = plot([0 numcol], [0 0],'LineWidth',3,'Color','k');
    hold on;
    for row = 1:numrow
        plot([0 numcol], [row row],'LineWidth',3,'Color','k');
    end
    for col = 0:numcol
        plot([col col], [0 numrow],'LineWidth',3,'Color','k');
    end
    patch([numcol-1 numcol numcol numcol-1], [numrow-1 numrow-1 numrow numrow], 'b');
    lastpark = find(park(1:i), 1, 'last');
    if (~isempty(lastpark) && isempty(find(cellID(lastpark:i) == 0, 1)))
        patch([0 1 1 0], [0 0 1 1], 'g');
    end
    if (length(obs) >= i)
        obsx = mod(obs(i), numcol);
        obsy = floor(obs(i)/numcol);
        patch([obsx obsx+1 obsx+1 obsx], [obsy obsy obsy+1 obsy+1], 'r');
    end
    x = mod(cellID(1:max(1, i-1)), numcol) + 0.5;
    y = floor(cellID(1:max(1, i-1))/numcol) + 0.5;
    plot(x, y, 'k:','LineWidth', 2);
    x = mod(cellID(max(1, i-1):i), numcol) + 0.5;
    y = floor(cellID(max(1, i-1):i)/numcol) + 0.5;
    plot(x, y, 'k-','LineWidth', 2);
    plot(x(end), y(end), 'ro','LineWidth', 2,'MarkerSize', 8);
    set(gca,'XTick',[],'YTick',[]);
    pause;
end