REXX game

Share a quote, a general thought, jokes or one liners here.
Post Reply
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

REXX game

Post by zprogrammer »

I created this intellectual game ;) :mrgreen:

Others can use it and have fun with it

Code: Select all

/*REXX*/
/* RANDOMLY GENERATE A FOUR DIGIT NUMBER WITHOUT REPEAT */
/* GUESS A NUMBER OF FOUR DIGITS WITHOUT REPEATS IF YOUR THE GUESSED
   NUMBER SHOULD NOT CONTAIN REPEATS,SHOULD NOT CONTAIN ALPHABETS AND
   SHOULD NOT BE MORE THAN FOUR DIGITS

   IF YOUR NUMBER CONTAINS 1 DIGIT SAME AS THE RANDOMLY PICKED NUMBER
   AND THE SAME PLACE THEY THE GAME WOULD RETURN 1 BULLS WHICH MEANS
   A DIGIT OUT OF 4 DIGIT NUMBER HAS A NUMBER IN SAME POSITION AS THE
   GUESSED NUMBER

   IF YOUR NUMBER CONTAINS 1 DIGIT SAME AS THE RANDOMLY PICKED NUMBER
   AND AT DIFFERENT PLACE THE GAME WOULD RETURN 1 COW WHICH MEANS A
   DIGIT OUT OF 4 DIGIT NUMBER HAS A NUMBER IS PRESENT IN THE GUESSED
   NUMBER BUT IN DIFFERENT POSITION
*/
CALL START
CALL USERGUESS
CALL MAINPROCESS
CALL GRESULT

START:
  CALL RNUMCREATOR
  CALL RNUMVALIDAT

RNUMCREATOR:
  RNUM = RIGHT(RANDOM(0,9999),4,0)

RNUMVALIDAT:
  RNUM1 = SUBSTR(RNUM,1,1)
  RNUM2 = SUBSTR(RNUM,2,1)
  RNUM3 = SUBSTR(RNUM,3,1)
  RNUM4 = SUBSTR(RNUM,4,1)

  IF RNUM1 = RNUM2 THEN
     DO
        CALL START
     END

  IF RNUM1 = RNUM3 THEN
     DO
        CALL START
     END

  IF RNUM1 = RNUM4 THEN
     DO
        CALL START
     END

  IF RNUM2 = RNUM3 THEN
     DO
        CALL START
     END

  IF RNUM2 = RNUM4 THEN
     DO
        CALL START
     END

  IF RNUM3 = RNUM4 THEN
     DO
        CALL START
     END


/* PICKS THE NUMBER FROM USER FOR GUESSING  */

USERGUESS:

   SAY ' GUESS A VALID FOUR DIGIT NUMBER WITH NO REPEATS : '
   PULL UNUM
   UNUM = STRIP(UNUM)
   CALL UNUMVALID
   CALL UNUMVALID2
   CALL UNUMVALID3

UNUMVALID:
   UNUM1 = SUBSTR(UNUM,1,1)
   UNUM2 = SUBSTR(UNUM,2,1)
   UNUM3 = SUBSTR(UNUM,3,1)
   UNUM4 = SUBSTR(UNUM,4,1)

   IF UNUM1 = UNUM2 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

   IF UNUM1 = UNUM3 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

   IF UNUM1 = UNUM4 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

   IF UNUM2 = UNUM3 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

   IF UNUM2 = UNUM4 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

   IF UNUM3 = UNUM4 THEN
   DO
      SAY
      SAY ' THE NUMBER CANNOT CONTAIN REPEATS '
      CALL USERGUESS
   END

UNUMVALID2:

   IF DATATYPE(UNUM) ¬= NUM THEN
   DO
      SAY ' THE GUESSED NUMBER CAN CONTAIN ONLY NUMBERS '
      CALL USERGUESS
   END
UNUMVALID3:

   IF LENGTH(UNUM) < 4 & LENGTH(UNUM) > 1 THEN
   DO
      SAY ' THE NUMBER SHOULD CONTAIN 4 DIGITS '
      CALL USERGUESS
   END

MAINPROCESS:

   BULLS = 0
   COWS  = 0

   IF UNUM1 = RNUM1 THEN
   DO
      BULLS = BULLS + 1
   END

   IF UNUM1 = RNUM2 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM1 = RNUM3 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM1 = RNUM4 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM2 = RNUM2 THEN
   DO
      BULLS = BULLS + 1
   END

   IF UNUM2 = RNUM1 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM2 = RNUM3 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM2 = RNUM4 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM3 = RNUM3 THEN
   DO
      BULLS = BULLS + 1
   END

   IF UNUM3 = RNUM1 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM3 = RNUM2 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM3 = RNUM4 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM4 = RNUM4 THEN
   DO
      BULLS = BULLS + 1
   END

   IF UNUM4 = RNUM1 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM4 = RNUM2 THEN
   DO
      COWS = COWS + 1
   END

   IF UNUM4 = RNUM3 THEN
   DO
      COWS = COWS + 1
   END

   IF BULLS = 4 THEN
   DO
      CALL GRESULT
   END
   ELSE
   DO
      SAY ' BULLS ' BULLS ' & COWS ' COWS
      CALL USERGUESS
   END

GRESULT:
   USER = USERID()
   SAY ' CONGRATS!!!!!!' USER ' YOU HAVE CRACKED THE PUZZLE '
zprogrammer
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: REXX game

Post by zprogrammer »

The above code would be more fun to work on if there is a table storing meaningfull 4 byte word without repeatitive chars and select them at random :)

Probably someone could try it
zprogrammer
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: REXX game

Post by zprogrammer »

Ha that's much better code Enrico :)

Will use to upgrade my game to 2.0 :mrgreen:
zprogrammer
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: REXX game

Post by zprogrammer »

works great :)
zprogrammer
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Thought of the Day, General Talk & Jokes.”