Bash random number.

Random numbers can be extremely important in games. One of the oldest games is sort of a black ball game that tries to emulate a fortune teller. Here will will use bash to create such a game. The code was originally created on the TRS_80 MODEL I using Basic.




oracle.sh
[code]
 ####################################
# tcode
#
#===============================
# Functions
#--------------------------------
# pc = position cursor
function pc () {
               tput cup $1 $2
        }

function header () {
        clear
        pc 2 10 ; echo "The Oracle"
        }

function footer() {
        pc 24 0
    }

# end functions
#=================================
# Assignments
# --------------------------------
datafile="odata"
pay=5
a=1
m="not done"
d=" "
# end assignments

#=================================
#
# Metadata input
#---------------------------------
while read line
do fdata[$a]=$line
    let a=a+1
done < $datafile

#===================================
# local variables
#--------------------------------
let nodf=$a
declare -i X=$nodf
# NUM=$[ ( $RANDOM % $X )  + 1 ]
#====================================
# Header
#-----------------------------------
header
#=====================================
# Begin logic
#--------------------------------------
while true; do
  let turns=turns+1
  clear
  pc 4 1
  echo "                T H E  O R A C L E !"
  pc 25 2
  echo "Computoman: Copyright 1980 - 2014 All rights reserved";
  pc 7 1
  echo "Please enter your question "
  pc 8 1
  echo "["
  pc 8 2
  read q
  pc 10 1
  echo "The Oracle will show you it's thoughts, then summon your answer."
  pc 12 1
  echo "So please be patient!"
  pc 15 1
  echo "***********************************************************************"
  pc 16 1
  echo "*                                                                     *"
  pc 17 1
  echo "***********************************************************************"
  for y in {1..100};
  do
    pc 16 1
    echo "*                                                                     *"
    pc 16 3
    NUM=$[ ( $RANDOM % $X )  + 1 ]
    echo ${fdata[$NUM]}
  done

  pc 18 1
  echo "Play again (Y/n)"
  read -s -n1 d
  echo
  case $d in
    [nN] ) break ;;
  esac

done
let owe=$pay*$turns
echo "Please pay the cashier $owe dollars!"
read
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# end of job:
  echo
  clear
  pc 4 1
  echo "                T H E  O R A C L E !"
  pc 23 1
  echo "Computoman: Copyright 1980 - 2015 All rights reserved"
  pc 6 1
  echo
  echo "If you use this program more than several times and would like"
  echo "to see more programs like the Oracle and the Cartomancer, please"
  echo "let the author know!"
  echo
# END
# end logic
#-----------------------------------
# footer
footer
#===================================
# End.
####################################
[/code]

odata:
Yes, if you are creative.
Yes, if you are receptive.
Anything is possible, but you will have a difficult start.
What a youthful folly to ask!
You must wait and ask again.
Only conflict will come of the result, please pray.
It will take many who are organized to accomplish your request.
Yes, if you keep it together.
Be meek and you will get your answer.
You are lucky to get this far!
You must have the fellowship of men.
In great measure will the possession result.
One must be modest to attain their goal.
You will do good to have enthusiasm for your quest.
Let someone else take the lead to your quest.
Atone for what has been spoiled, then reask your question.
You are too far away to get the answer.
Meditation will lead you to your answer.
Bite through to your goal.
If you handle life with grace!
There is to be a coming apart for fate to be realized.
All must return to what is.
Not knowing the true answer will be better.
You must tame the power of the great.
Watch the corners of the mouth.
The greatest preponderance will be fate.
It will be the abysmals, sorry!
You will be lucky to hold on to what you have.
Influence will be the steeping stone to your quest.
Just be patient for a while.
It is a time for getting away.
The power of the great is upon you.
Yes, there is a progression to be attained.
The crytal ball is losing light and no answer may be attained now.
Everyone close will be part of your answer.
No, there is too much opposition.
Not likely, there are obstructions in the way.
Yes, deliverance will come.
Not as much as you might as supposed.
Yes and more than was planned.
Yes, if there is a breakthrough.
Maybe if you come to meet.
Now is the time to gather together for the answer.
Yes, only if there is a push upward.
No, oppression will stop your quest.
Yes, no, and maybe.......
What the oracle says is opposite to your true answer.
The answer will take longer and you will pay for the wait.
Only through an arousing!
It is not time for a move, you must keep still.
Let fate develop as it will.
You must see the marrying maiden first.
More than you ever imagined.
You may wonder and wander, but it is time to move.
Only if you act gently.
Yes, with great joy!
No, so you must let go of it to spread out.
Only with limitations.
Look within yourself and you can find the answer.
Only with preponderance of the small.
It will come to be after completion.
Only before completion.
I love Elizabeth!
Only God knows...

---------------------------------------

Runs in freebasic

 REM **************************************************************************
REM * program:     oracle pc
REM * note   :     random choosing of answer for a question.
REM * programmer:  Computoman
REM * last update: 11/11/2014
REM *------------------------------------------------------------------------
RESTORE odata
WIDTH 80, 25
CLS
RANDOMIZE TIMER
DIM x$(64)
rem To.sound = 1
FOR x = 0 TO 63
  READ x$(x)
NEXT x
m$ = "Not done"
pay = 0

WHILE m$ = "Not done"
  pay = pay + 1
  CLS
  LOCATE 4, 1
  PRINT "                T H E  O R A C L E !"
  LOCATE 5, 1
  PRINT "                Computothought 2009"
  FOR x = 1 TO 1500
  NEXT x
  LOCATE 7, 1
  LINE INPUT "Please enter your question: ", q$
  SELECT CASE LEFT$(q$, 1)
    CASE CHR$(248)
    rem     To.sound = 1
    CASE CHR$(255)
    rem     To.sound = 0
  END SELECT
  LOCATE 10, 1
  PRINT "The Oracle will show you it's thoughts, then summon your answer."
  LOCATE 12, 1
  PRINT "So please be patient!"
  LOCATE 15, 1
  PRINT "<" + STRING$(76, "=") + ">"
  LOCATE 16, 1
  PRINT "<"; TAB(78); ">"
  LOCATE 17, 1
  PRINT "<" + STRING$(76, "=") + ">"
  FOR Z = 1 TO 1000
    LOCATE 16, 3
    PRINT STRING$(75, " ");
    LOCATE 16, 3
    PRINT x$(RND(1) * 63);
    rem IF To.sound = 1 THEN
        rem PLAY "l16" + CHR$(INT(RND(1) * 7) + 65)
    rem END IF
  NEXT Z
  FOR x = 1 TO 5
    PRINT
  NEXT x
  INPUT "Are you done (Y/n)"; d$
  IF UCASE$(d$) <> "N" THEN
    m$ = "Done"
  END IF
WEND

PRINT
PRINT "Please pay the cashier "; pay * 5; " dollars!"
zz$ = ""
zz$ = INPUT$(1)

' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
endvofvjob:
  VIEW PRINT
  LOCATE 25, 1
  PRINT STRING$(79, " ");
  LOCATE 24, 1
  rem EXIT SUB
END


Odata:
DATA "Yes, if you are creative."
DATA "Yes, if you are receptive."
DATA "Anything is possible, but you will have a difficult start."
DATA "What a youthful folly to ask!"
DATA "You must wait and ask again."
DATA "Only conflict will come of the result, please pray."
DATA "It will take many who are organized to accomplish your request."
DATA "Yes, if you keep it together."
DATA "Be meek and you will get your answer."
DATA "You are lucky to get this far!"
DATA "You must have the fellowship of men."
DATA "In great measure will the possession result."
DATA "One must be modest to attain their goal."
DATA "You will do good to have enthusiasm for your quest."
DATA "Let someone else take the lead to your quest."
DATA "Atone for what has been spoiled, then reask your question."
DATA "You are too far away to get the answer."
DATA "Meditation will lead you to your answer."
DATA "Bite through to your goal."
DATA "If you handle life with grace!"
DATA "There is to be a coming apart for fate to be realized."
DATA "All must return to what is."
DATA "Not knowing the true answer will be better."
DATA "You must tame the power of the great."
DATA "Watch the corners of the mouth."
DATA "The greatest preponderance will be fate."
DATA "It will be the abysmals, sorry!"
DATA "You will be lucky to hold on to what you have."
DATA "Influence will be the steeping stone to your quest."
DATA "Just be patient for a while."
DATA "It is a time for getting away."
DATA "The power of the great is upon you."
DATA "Yes, there is a progression to be attained."
DATA "The crytal ball is losing light and no answer may be attained now."
DATA "Everyone close will be part of your answer."
DATA "No, there is too much opposition."
DATA "Not likely, there are obstructions in the way."
DATA "Yes, deliverance will come."
DATA "Not as much as you might as supposed."
DATA "Yes and more than was planned."
DATA "Yes, if there is a breakthrough."
DATA "Maybe if you come to meet."
DATA "Now is the time to gather together for the answer."
DATA "Yes, only if there is a push upward."
DATA "No, oppression will stop your quest."
DATA "Yes, no, and maybe......."
DATA "What the oracle says is opposite to your true answer."
DATA "The answer will take longer and you will pay for the wait."
DATA "Only through an arousing!"
DATA "It is not time for a move, you must keep still."
DATA "Let fate develop as it will."
DATA "You must see the marrying maiden first."
DATA "More than you ever imagined."
DATA "You may wonder and wander, but it is time to move."
DATA "Only if you act gently."
DATA "Yes, with great joy!"
DATA "No, so you must let go of it to spread out."
DATA "Only with limitations."
DATA "Look within yourself and you can find the answer."
DATA "Only with preponderance of the small."
DATA "It will come to be after completion."
DATA "Only before completion."
DATA "I love Elizabeth!"
DATA "Only God knows..."

Comments

Popular posts from this blog

Guiless?

Web.com and Network Solutions, the Walmart of the internet.

MSOffice vs Libreoffice