Aktionen 5 – Neue Aktionen (Ein letzter Würfel)

Okay. Wenn man den Würfel anschaut, erfährt man, welche Zahl oben liegt. Wenn man den Würfel wirft, landet eine neue Zahl oben. Unschön ist noch, dass a) diese Zahl sich nicht ändert, auch wenn wir den Würfel fallen lassen oder werfen, sondern nur beim Würfeln, und b) der Würfel immer eine sichtbare Zahl als oben liegend zeigt, auch wenn wir den Würfel zum Beispiel in der Jacke herumtragen. Da sollte man nicht davon sprechen können, dass eine Zahl oben ist.


Problem a) kann man lösen, indem man das Fallenlassen eines Würfels abfängt und ihn vorher heimlich leise mit unserer neuen Aktion würfelt:

Instead of dropping a die:
	silently try rolling the noun;
	say "Dropped."

“Try” deshalb, weil die Aktion ja aus anderen Gründen immer schiefgehen kann, und weil das grammatisch schön zur ing-Form passt. “Silently” deshalb, beim Würfeln ja eigentlich auch Text ausgegeben wird, das wollen wir hier aber gar nicht. Der Textausgabeteil des Würfelns interessiert uns hier gar nicht, der Würfel soll einfach auf dem Boden landen und seine Zahl ändern und das war es.

Das geht so aber noch eleganter. Anstatt der Codezeilen oben schreiben wir:

After dropping a die:
	roll the noun;
	continue the action.

Nach dem regulären Ausführen des Fallenlassens, aber vor dessen üblicher Textausgabe, soll der Würfel gerollt werden. Erst danach geht es mit der üblichen Textausgabe weiter, also “Dropped.”

Dieses roll + direktes Objekt ist etwas Neues, eine selbst geschriebene Funktion. Die brauchen wir natürlich auch:

To roll (x - a die):
	now the face of x is a random number from 1 to the side number of x.

Damit können wir dann auch unsere Carry-out-rolling-Regel verschönern:

Carry out rolling:
	roll the noun;
	now the noun is in the location of the player.

Eine Methode ist ja vor allem dann sinnvoll, wenn man sie gleich mehrfach einsetzt. Wann soll sich die Würfelzahl denn noch ändern?

After taking, dropping, pushing or turning a die:
	roll the noun;
	continue the action.

Das geht natürlich nur, weil wir uns die Methode roll (x - a die) selbst geschrieben haben.


Wir legen für Problem b) mal fest, dass ein Würfel nur dann eine Zahl oben hat, wenn man ihn nicht mit sich führt. Deshalb ergänzen wir unsere Examine-Regel etwas:

Instead of examining a die:
	If the noun is enclosed by the player:
		continue the action;
	otherwise:
		If the description of the noun is not "":
			Say the description of the noun;
			Say " ";
		Say  "Currently, the [side number in words]-faced die shows a [face]."

Dann kriegen wir immer, wenn wir den Würfel bei uns haben (unmittelbar oder in einem Behälter, den wir haben) die kurze Antwort ohne Nennung der Zahl, und wenn der Würfel anderswo ist, kriegen wir die Zahl gesagt.

Das ging natürlich auch über ein zusätzliches Attribut des Würfels. Den Attributwert müsste man immer anpassen, und sich in der Examine-Regel darauf beziehen.
Oder man definiert ein Adjektiv (quasi eine boolesche Funktion):

Definition: A die is resting if it is not enclosed by the player.

Dann können wir unsere Examine-Regel wieder vereinfachen:

Instead of examining a resting die:
	If the description of the noun is not "":
		Say the description of the noun;
		Say " ";
	Say  "Currently, the [side number in words]-faced die shows a [face]."

Unsere Ausnahmeregel gilt nur für Würfel, die resting sind, die anderen werden regulär beschrieben.


Außerdem brauchen wir noch zehnseitige Würfel.

A ten-sided die is a kind of die. The side number is always 10.

Der fertige Code:

"Dice 3" by Herr Rau

Chapter 1 - Kinds

A die is a kind of thing.
It has a number called side number. The side number is usually 6.
It has a number called face. The face is usually 1.
Understand "dice" as the plural of die.

A ten-sided die is a kind of die. The side number is always 10.

Chapter 2 - Actions & Methods

Rolling is an action applying to one carried thing and requiring light.

Understand "roll [things]" as rolling.
Understand "shake [things]" as rolling.

Check rolling:
	If the noun is not a die, say "You can do that with dice only." instead.
Carry out rolling:
	roll the noun;
	now the noun is in the location of the player.
Report rolling:
	Say "You roll [the noun]. When it comes to rest on the ground, it shows a [face]."

Instead of examining a resting die:
	If the description of the noun is not "":
		Say the description of the noun;
		Say " ";
	Say  "Currently, the [side number in words]-faced die shows a [face]."

After taking, dropping, pushing or turning a die:
	roll the noun;
	continue the action.

To roll (x - a die):
	now the face of x is a random number from 1 to the side number of x.

Definition: A die is resting if it is not enclosed by the player.

Chapter 3 - The World

The Casino is a room.
The green die is a ten-sided die in the Casino. The description is "A beautiful jade die. Possibly quite valuable."
The red die is a die in the Casino. The description is "A perfect plastic cube, sharp-edged with white dots."
The basket is a container in the Casino.

Test me with "x green die / take dice / x green die / roll green die / x green die / put red die in basket / x red die / take basket /x red die."

Schreibe einen Kommentar