To answer your general question, there is a way to find such functions without just guessing and checking...sort of. One way is to say "I'd like to find a function that satisfies some differential equation, like Laplace's equation, on the interior of this square, but takes on these values on the boundary." That's a classic problem in heat-transfer, electrostatics, and many other fields, and is much studied.
One of the great ways to solve such a problem is to find a map from your domain to some other domain, solve the problem there, and then map back. If your map happens to be complex-analytic (the complex variables analog of "differentiable"), then it will carry solutions of Laplace's equation from one domain back to the other.
So if we can find a map that takes two sides of your square to the $v = 0$ line in the $u+ i v$ plane, and the other two side to the $v = 1$ line, then transforming the function "$v$" back to your square will give a solution.
The only problem is that building the analytic transform from your problem to an easier problem is not always easy. On the good side, many smart people have catalogued a bunch of approaches -- search for "conformal mapping" to get an idea of how they're done.
I don't have my complex variables book handy here, so I can't find a good map doing what I suggested for the square, but perhaps I can look it up tomorrow. If you look in Churchill's Complex Analysis, solving problems like this is in one of the last sections of the book.
There's one more approach: Letting $C$ denote the contour that's the boundary of the square, you can define
$$
f(z) = \int_C \frac{h(u)}{z-u} du
$$
where $h$ is your function (the $+1/0$ function you described). (Warning: I might be off by a minus-sign, or have simply mis-remembered the formula entirely!).
The function $f$ will then be a solution of Laplace's equation subject to the given boundary conditions. It's just possible that the integral I've written down is evaluatable by mere mortals, which gives you a solution.