Living Museum of Learning

Where real moments become exhibits
← Prev Next →
Why Are We Torturing the Pieces?

Why Are We Torturing the Pieces?

She learned to make a small experiment, isolate one thing, and then discover that a seemingly magical number was actually carrying a state.

Situation

Tianjing was building a Chinese-chess game in Swift.

The game rules were coming together, but there was one problem:

When she moved a piece, it simply jumped from one square to another.

No animation.

A few days earlier, we had experimented with dragging chess pieces. Tianjing remembered the experiment, but couldn't find the code.

“Maybe we did it in chess.”

“Oh. Right.”

She switched to the other project and found it.

Turning Point

“We have a very good thing to do today. Guess what?”

The answer was already there.

Let's make the piece move properly.

Why wait until every game rule is finished?

Why should we torture ourselves by debugging a game whose pieces teleport around the board?

So we decided to add the animation now.

Not all of it.

Just one piece.

A ma.

The Experiment

There were about ten small steps to make the dragging work.

We completed roughly half of them.

First, we used one fixed image:

black_ma

Then we made a temporary moving ma follow the finger.

When dragging began, the original piece had to disappear.

When dragging ended, the move went back to the existing game rules.

And something interesting happened.

Other pieces started flickering because our experimental code was still rough.

Tianjing noticed it.

But we didn't fix it.

“That’s fine. We deliberately let them be there. Our question is only this: Does dragging and moving a ma work?”

“Yes, good!”

One question.

One experiment.

One thing working.

The Little Magic Number

At one point, the ma mysteriously appeared when the app first launched.

Why?

Tianjing had:

var movingFingerY: CGFloat = -1

But -1 was being used by the drawing logic as if it meant something else.

We changed it to:

var movingFingerY: CGFloat = -1000

The “magic” disappeared.

But -1000 wasn't magic.

It was a state.

When:

movingFingerY == -1000

there is no dragging, so the fixed ma is shown.

When:

movingFingerY > -1000

we are dragging, so the fixed ma is hidden and the temporary moving ma is shown.

The number is both an off-screen position and a signal:

-1000 means: we are not moving a piece.

A number can carry meaning far beyond its numerical value.

Learning

Tianjing was not just learning how to animate a chess piece.

She was learning how to work with a program that is still unfinished.

Don't fix everything at once.

Don't wait until everything is perfect.

Choose one small question.

Make that one thing work.

And when something looks like magic, ask what meaning the program has given that number.

Theme

Good debugging is not about eliminating every problem.

Sometimes it is about deliberately ignoring nine problems so you can understand the tenth.

And good programming does not have to torture us.

We can make the pieces move while we are still building the game.

What Is Possible?

A game can become alive before all its rules are finished.

How Does It Happen?

Through small experiments, clear states, and one question at a time.

Why Does It Matter?

Because programming is much more enjoyable when we don't torture ourselves along the way.