function drawBoard(D) 
% clears the current figure and 
% draws the drawboard on the current figure window
% which is assumed to be open and with hold on
% D - is  matrix containing the codified  draw board design 
% each entry is the code for one zone in the board 
%  0 - leave zone white 
%  1 - color zone blue 
%  2 - color zone red 
%  3 - color zone orange 

% makes use of sub-function drawZone to draw each of the zones

clf; 

hold on; 

[numRows, numCols] = size(D);  

for (i= 1:numRows ) 
    for (j= 1:numCols) 
        if (D(i,j) == 1) 
            thisColor = 'b';
        elseif (D(i,j) == 2) 
            thisColor = 'g';
        elseif (D(i,j) == 3) 
            thisColor = 'r';
        else 
            thisColor = 'w';
        end
        drawZone( j,i,  thisColor); 
    end
end

axis equal; 

axis([0 numRows 0 numCols]); 

end


function drawZone( x,y, c)
% draws a square with upper-left corner at (x-1,y-1) and 
% lower-right corner at (x, y) , with color 'c' 

fill( [x-1  x x x-1] , [y-1 y-1 y y] , c, 'EdgeColor', 'none' ); 

end
    

