Rather Unspecific Error

Rather Unspecific Error

Return to topic list

Sat Feb 21 22:35:55 2015   by   Leichensack
Players:= 7;
DistanceAB:= Players / 2;
DistanceBA:= Players -1 / 2;

n:= 0;
\battle:= 0;

repeat battle:=
  RollAa:= d6;
  RollAb:= d6;
  RollBa:= d6;
  RollBb:= d6;

  n:=
    if RollAa = RollAb & RollBa = RollBb then
      n + 1
    else if RollAa = RollAb then
      DistanceAB := DistanceAB -1;
      DistanceBA := DistanceBA +1;
      n + 1
    else if RollBa = RollBb then
      DistanceAB := DistanceAB +1;
      DistanceBA := DistanceBA -1;
      n +1
    else n+1
  ;

  \battle:=
    if DistanceAB = 0 then
      1
    else if DistanceBA = 0 then
      -1
    else 0

while battle = 0

\ * n

Hey,
I wish the weekend of anyone who is reading this is/has been/will be adventurous, exiting or at least entertaining.
The game described here is quite simple: Roll two dice until you see doubles, after that pass the dice as possible to your left neighbor who'll do the same. There is another pair of dice going round in the same direction. If both pairs end up at the same player, he has to drink.

Now Troll tells me:
An error occurred during calculation

While I kind of expected a deadlock I know that Troll tries for one minute prior to resigning and that the message is different. Yet it's quite striking that it's related to the repeat .. while part.

I'd be glad for any helping hand someone might be able to lend.
 
Mon Feb 23 11:11:10 2015   by   Torben
The error message is caused by (among other things) infinite loops.

The reason your loop is infinite is that you treat a local redefinition as if it is an assignment: When you write

DistanceAB := DistanceAB -1;

this creates a new local variable DistanceAB that is visible only until the following else, and it does not change the values of the DistanceAB variable that is used in the test.  Similarly, the n := ... n+1 does not change a global counter.

Troll is a functional language, so you can not make assignments that modify a global variable.  To get what you want, you should define a function that takes the variables you want to change as parameters and modifies them in the recursive calls.

Also, you probably mean (Players - 1)/2 in the third line.  Players -1/2 means subtracting one half from Players, which because 1/2 is rounded down, has no effect.
 

Return to topic list



New message:
Topic:
Posted by:

Type the values of the dice shown below:

Return to topic list