#include <perms.h>
void Wumpus(_imp_string Parmzzz) {
  auto int Fnr(int I);
  int R[20 /*1:20*/][3 /*1:3*/];
  int Bog[20 /*1:20*/];
  void Drain(void) {
    while (Nextsymbol() != Nl) Skipsymbol();
    Skipsymbol();
  }
  int Getans(void) {
    int Sym;
    while ('N' != (Nextsymbol() & 95) && (Nextsymbol() & 95) != 'Y') Skipsymbol();
    Sym = Nextsymbol() & 95;
    Drain();
    return (Sym);
  }
  void Getrequest(int *Sym) {
    for (;;) {
      *Sym = Nextch();
      if ('0' <= *Sym && *Sym <= '9') break;
      if (*Sym == 's' || *Sym == 'S') break;
      Skipsymbol();
    }
    if (*Sym == 's') *Sym = 'S';
    if (*Sym != 'S') Read(*Sym);
    Drain();
  }
  int Noofarrows;
  int Moveto;
  int W;
  int H;
  int B1;
  int B2;
  int P1;
  int P2;
  int Wo;
  int Po;
  int Bo;
  int N1;
  int N2;
  int I;
  int J;
  int K;
  int L;
  int P;
  int T;
  int A1;
  int Ans;
  _imp_string Line;
  void Randomise(void) {
    int Temp;
    N1 = 0;
    Line = Time();
    for (I = 1; I <= *Length(Line); I++) N1 += *Charno(Line, I);
    N2 = 10000 - N1;
    for (I = 1; I <= 20; I++) {
      Temp = Fnr(20);
      Bog[I] = 0;
    }
    for (I = 1; I <= 20; I++)
      for (J = 1; J <= 3; J++) R[I][J] = 0;
    P = 1;
    R[1][1] = 99;
    for (I = 1; I <= 19; I++) {
      do
        T = Fnr(20);
      while (R[T][1]);
      R[P][2] = T;
      R[T][1] = P;
      P = T;
    }
    R[P][2] = 1;
    R[1][1] = P;
    P2 = Fnr(20);
    R[P2][3] = 99;
    R[R[P2][2]][3] = 99;
    P = 1;
    for (I = 1; I <= 8; I++) {
      while (R[P][3] > 0) P++;
      do
        T = Fnr(20);
      while (R[T][1] == P || R[T][2] == P || P == T || R[T][3] != 0);
      R[P][3] = T;
      R[T][3] = P;
      P++;
    }
  Label:
    do
      T = Fnr(20);
    while (P2 == T || R[P2][1] == T || R[P2][2] == T || R[T][3] != 0);
    P = R[P2][2];
    R[P2][3] = T;
    R[T][3] = P2;
    if (R[R[P][1]][3] == 0 || R[R[P][2]][3] == 0) {
      R[T][3] = 0;
      goto Label;
    }
    do
      T = Fnr(20);
    while (P == T || R[P][2] == T || R[P][1] == T || R[T][3] != 0);
    R[P][3] = T;
    R[T][3] = P;
    W = Fnr(20);
    B1 = Fnr(20);
    do
      B2 = Fnr(20);
    while (B2 == B1);
    P1 = Fnr(20);
    do
      P2 = Fnr(20);
    while (P2 == P1);
    do
      H = Fnr(20);
    while (H == W || H == P1 || H == P2 || H == B1 || H == B2);
  }
  void Getnow(void) {
    int H1;
    Wo = 0;
    Bo = 0;
    Po = 0;
    for (I = 1; I <= 3; I++) {
      H1 = R[H][I];
      if (H1 == P1 || H1 == P2) Po = 1;
      if (H1 == B1 || H1 == B2) Bo = 1;
      if (H1 == W) Wo = 1;
      for (J = 1; J <= 3; J++)
        if (R[H1][1] == W || R[H1][2] == W || R[H1][3] == W) Wo = 1;
    }
  }
  void Summarize(int I) {
    if (I > 0) goto Skip;
    Printstring(_imp_str_literal("You are in room"));
    Write(H, 0);
    Newline();
  Skip:
    Printstring(_imp_str_literal("There are passages to"));
    Write(R[H][1], 0);
    Printch(',');
    Write(R[H][2], 0);
    Printch(',');
    Write(R[H][3], 0);
    Newline();
    if (Wo == 1) {
      Printstring(_imp_str_literal("I smell a Wumpus"));
      Newline();
    }
    if (Po == 1) {
      Printstring(_imp_str_literal("I feel a draft"));
      Newline();
    }
    if (Bo == 1) {
      Printstring(_imp_str_literal("I hear squeaking"));
      Newline();
    }
  }
  int Fnr(int I) {
    float Rtemp;
    int Temp;
    Temp = ((3 * (N1 << 14) + N2) + (N2 << 14)) & ((1 << 28) - 1);
    N2 = Temp & 0x3FFF;
    N1 = (unsigned)(Temp - N2) >> 14;
    Rtemp = Temp / (1 << 28);
    return (1 + Intpt(I * Rtemp));
  }
  Printstring(_imp_str_literal("Would you like to see the rules?"));
  Newline();
  if (Getans() == 'Y') {
    Printstring(_imp_str_literal("Sorry, chum - but there aint none!!!"));
    Newline();
  }
  Prompt(_imp_str_literal(":"));
Begin:
  Randomise();
  Noofarrows = 5;
Moveloop:
  Getnow();
Errorinput:
  Summarize(0);
Getmove:
  Printstring(_imp_str_literal("Your move, or \"S\" to shoot."));
  Newline();
  Getrequest(Moveto);
  if (Moveto == 'S')
    goto Shoot;
  else
    goto Move;
Whaterr:;
  Printstring(_imp_str_literal("What, er.."));
  Printch(7);
  Newline();
  goto Errorinput;
Move:;
  if (R[H][1] == Moveto || R[H][2] == Moveto || R[H][3] == Moveto)
    H = Moveto;
  else
    goto Whaterr;
Check:
  if (H == W) goto Eathunter;
  if (H == P1 || H == P2) goto Pit;
  if (H == B1 || H == B2) goto Bat;
  if (Bog[H]) goto Toilet;
  goto Moveloop;
Bat:
Loop:;
  T = Fnr(20);
  if (T == H) goto Loop;
  H = T;
  Printstring(_imp_str_literal("You have been captured by a bat !!!"));
  Newline();
  Printstring(_imp_str_literal("You are now in room"));
  Write(H, 0);
  Newline();
  if (H == W || H == B1 || H == B2 || H == P1 || H == P2) goto Check;
  Getnow();
  Summarize(1);
  goto Getmove;
Eathunter:;
  Printstring(_imp_str_literal("You were eaten by the Wumpus!! You LOSE!!!"));
  goto Finish;
Pit:;
  Printstring(_imp_str_literal("You fell into a BOTTOMless pit!! "));
  if (Fnr(10) != 10 || (H != B1 && H != B2)) {
    Printstring(_imp_str_literal("You LOSE!!!"));
    goto Finish;
  }
  Printstring(_imp_str_literal("But .... "));
  Newline();
  goto Bat;
Shoot:
  if (!Noofarrows) goto Noarrows;
  Noofarrows--;
  A1 = H;
  for (I = 1; I <= 5; I++) {
  Getarrow:
    Printstring(_imp_str_literal("Where to?"));
    Newline();
    Getrequest(J);
    if (J == 'S') break;
    if (J != R[A1][1] && J != R[A1][2] && J != R[A1][3]) goto Bounce;
    if (Fnr(10) >= 10) goto Bounce;
    A1 = J;
    if (A1 == W) goto Kill;
    if (A1 == H) goto Suicide;
    Printstring(_imp_str_literal("Missed !!!"));
    Newline();
  }
Wakewumpus:
  if (Fnr(4) == 4) goto Moveloop;
  Bog[W] = 1;
  W = R[W][Fnr(3)];
  Bog[W] = 0;
  if (H != W) {
    Printstring(_imp_str_literal("You've woken the Wumpus!!!"));
    Newline();
    goto Moveloop;
  }
  Printstring(_imp_str_literal("The Wumpus moved into your room !!!"));
  Newline();
  goto Eathunter;
Suicide:
  Printstring(_imp_str_literal("Fool, you shot yourself !!!"));
  Newline();
  goto Finish;
Kill:
  Printstring(_imp_str_literal("CONGRATULATIONS, Great White Hunter !!!"));
  Newline();
  Printstring(_imp_str_literal("You slew the dreaded Wumpus !!!"));
  goto Finish;
Noarrows:
  Printstring(_imp_str_literal("No arrows left !!!"));
  Newline();
  goto Moveloop;
Toilet:
  Printstring(_imp_str_literal("Whoops! You've landed in Wump-Shit!!!"));
  Newline();
  goto Moveloop;
Bounce:;
  for (K = I; K <= 5; K++) {
    Printstring(_imp_str_literal("BouNCE!!!"));
    Newline();
    A1 = R[A1][Fnr(3)];
    if (A1 == H) goto Suicide;
    if (A1 == W) goto Kill;
  }
  goto Wakewumpus;
Finish:
  Newline();
  Printstring(_imp_str_literal("Another game?"));
  Newline();
  Ans = Getans();
  if (Ans == 'Y') {
    Ans = Fnr(10000);
    goto Begin;
  }
}
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  Wumpus(_imp_str_literal(""));
  exit(0);
  return (1);
}
