A recursive definition would be $f(0)=1$ and
$$
f(x+1)=\begin{cases}
f(x)+1 & \text{if $3\nmid f(x)+1$}\\[4px]
f(x)+2 & \text{if $3\mid f(x)+1$}
\end{cases}
$$
Let's examine your function $f$.
We should have
$$
0
We have
$$
f(x+1)-f(x)=
3\left(\left\lfloor\frac{x+1}{2}\right\rfloor-
\left\lfloor\frac{x}{2}\right\rfloor
\right)+
((x+1)\bmod 2)-(x\bmod 2)
$$
If $x$ is even, then $\lfloor(x+1)/2\rfloor=\lfloor x/2\rfloor$ and $((x+1)\bmod 2)-(x\bmod 2)=1$, so $f(x+1)-f(x)=1$.
If $x$ is odd, say $x=2k+1$, we have
$$
3\left(\left\lfloor\frac{2y+2}{2}\right\rfloor-
\left\lfloor\frac{2y+1}{2}\right\rfloor
\right)=3(y+1)-3y=3
$$
and $((x+1)\bmod 2)-(x\bmod 2)=-1$, so $f(x+1)-f(x)=2$.
Now suppose that $f(x)+1$ is a multiple of $3$, so
$$
3\left\lfloor\frac{x}{2}\right\rfloor+
(x\bmod 2)+1+1=3k
$$
This means that $x\bmod2=1$, that is, $x$ is odd. In this case, $f(x+1)=f(x)+2$, as required.