function ttt_drawboard(S);
% draw_board(S)
% 
% draws the Tic-Tac-Toe board corresponding to the state S. See 
%    help ttt_states
% regarding the representation of the state.
    
    bit=int32(16);
    fprintf('  ');
    for row=1:3
        for col=1:3
            switch bitand(idivide(S,2^bit),3)
              case 0
                fprintf('   ');
              case 1
                fprintf(' X ');
              case 2
                    fprintf(' O ');
              otherwise
                fprintf(' ? ');
            end
            bit=bit-2;
            if col<3
                fprintf('|');
            end
        end
        if row<3
            fprintf('\n  ---+---+---\n  ');
        else
            fprintf('\n');
        end
    end
end
    
    