~ $ cd teaching/fishing-lagoon && cat README.md

The fishing lagoon

Tecnocampus, spring 2018, Laboratori de Software 1. Eighteen years after the fish auction I set a class the same shape of problem turned inside out. There, buyers competed for fish somebody else had caught. Here, the fish are still in the water, they breed if they are left alone, and the bots have to decide how much to take from a lagoon they share. The starter is public: fishing-lagoon-starter.

The rules fit in a paragraph. A round is a lagoon with some fish in it and a number of weeks. Before the round, each bot hands in its orders for every week — a number of fish, or a rest — knowing who else is on the lagoon and what happened in earlier rounds, but not what the others will order now. Each week the lagoon serves the smallest order first, whole, and splits what is there between equal orders when it does not stretch; then the fish that are left breed, half as many again. A bot's score is what it caught.

The lagoon has 100 fish, and 10 weeks ahead. Nobody has been out yet.

The season has not started
botlast roundseason
One00
Power00
10%00
Tit for tat00
Tat for tit00

Play a round and the board shows the week by week: what each bot caught, in grey when it got less than it asked for, and what was left in the water. Play five and the season builds; the tit-for-tats remember. The 40% bot starts on the bank. Seat your own bot below and it plays too.

What there is to see

Three fish left alone become four, six, nine, thirteen, nineteen, twenty-eight, forty-two, sixty-three, ninety-four. A hundred fished by nobody for nine weeks are over three thousand in the tenth. So the most a lagoon can give is everyone resting until the last week and splitting what grew — and every fish taken early is one that would have bred.

Play the first round as it is set. The lagoon grows all round, to about six hundred, and the two tit-for-tats rest and take their share the last week. But the bot that takes 10% of what it believes is there ends the round with the most, nearly three times what either of them got: it fed on their patience, a tenth a week of a lagoon they were letting grow. And in the last week, when the tit-for-tats finally order, the smaller orders are served first — they always are — and the two of them split what is left: a quarter of what they had planned on.

Now tick 40% and play again. It takes forty the first week and the lagoon is empty by the third; nobody catches anything after that, not the bot that only ever asked for one. Play a second round and watch the two tit-for-tats: they take a full share from the first week now, and the 40% bot ends with half of what it got before. That is the strategy the starter shipped as the one worth beating. Tit for tat rests every week but the last and takes one share. But whoever took a full share or more in the first week of a round is a traitor, for good, and on a lagoon with a traitor tit for tat takes a full share every week itself, so that the traitor cannot grow rich on its patience. Two of them cooperate; against a greedy bot they take back what they can. Its test is the first week only, which is why it never turns on Power, which rests the first week and takes everything in the last two — the kind of hole a student finds by losing to it.

Why a software lab

The subject was software, not game theory. What a student had to build was the strategy behind an interface of three methods — where to sit, what to order, what to learn from the round — against a server the class shared, and the lagoon itself came with its tests: the breeding sequence, the smallest order served first, a bot that fishes more than there is. The commons was there so that the strategy was worth testing: a bot's orders depend on what it believes the lagoon will hold, and that belief is a small simulation of the rules, which is wrong the first time everyone writes it.

Your own bot

Under the board is an editor with the body of a JavaScript function. It is given fish, what the lagoon starts with; weeks; bots, the names on the lagoon; me; and rounds, every round played so far, each with everyone's orders, the weeks as they went, and the totals. It returns your orders: one number a week, 0 to rest. It starts out as the cooperative half of tit for tat, so the first bot you seat is a good neighbour — the first thing to try is being a bad one, and then watching what the two tit-for-tats do to you in the round after. A mistake in it is shown in the engine's own words and your bot rests that round. It runs in your browser and stays there.

~/teaching/fishing-lagoon $

~/teaching/fishing-lagoon $