The problem is in the two following lines:
and
In both cases the deal and computerdeal function are executed in a subshell, in the first case as the left hand side of a pipe, in the second case as part of a command substitution. The global variables that are set inside those functions are local to that subshell. When the subshell finishes, those variables and their values will be lost...
By contrast the first time the deal function is called:
it is done in the current shell itself and the value of global variable cards_remaining that gets set inside that function is the value that gets printed at the end..
So instead you could run those functions in the current shell and then use the global variables that are being set inside them...
Last edited by Scrutinizer; 11-13-2016 at 03:45 AM..
This User Gave Thanks to Scrutinizer For This Post:
How can I get a bash script to wait and read and count $i messages that a running program (drbl clonezilla) sends to the console (terminal) and only then move on to the next line in the script when the count is matched (the next line is the last line of the script and is a reboot)?
The script... (0 Replies)
Hello All,
I was wondering if it would be possible to create a "racing" game in script. The game play would be as follows. Script will read the following input:
Start
|b| | | | |
|r| | | | |
First player (b) will roll a die to see how many spaces to move. This is will continue until the... (0 Replies)
How can I make a bash script that keeps on running after I have closed the terminal?
Or a script that runs without having the terminal window open? (1 Reply)
Okay so Zork sparked my interest in this. I have been learning to program for the last year and a half. I've dabbled in everything from Java to Ruby to PHP & XHTML & SQL, and now I'm on bash. I really like bash scripting. Its easy and fun. I just started two days ago. Pretty much I've been writing... (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
So, I made a script beginning with #!/bin/bash on gedit.
And I double clicked it to run in terminal and I end up with "The child process exited normally with status 127" and "command not found".
If I run the same script from the terminal as "tcsh (script name)" it runs just fine.
If I... (8 Replies)
Hello guys I'm new to shell scripting and I need to make a game using shell script. I want to know if it is possible for me a total noob to shell scripting to make this game.
The game concept is simple:
First thing when you launch the script you get a menu in which you select if you want to... (3 Replies)
Discussion started by: Othmane
3 Replies
LEARN ABOUT NETBSD
canfield
CANFIELD(6) BSD Games Manual CANFIELD(6)NAME
canfield, cfscores -- the solitaire card game canfield
SYNOPSIS
canfield
cfscores [user]
cfscores -a
DESCRIPTION
If you have never played solitaire before, it is recommended that you consult a solitaire instruction book. In Canfield, tableau cards may
be built on each other downward in alternate colors. An entire pile must be moved as a unit in building. Top cards of the piles are avail-
able to be played on foundations, but never into empty spaces.
Spaces must be filled from the stock. The top card of the stock also is available to be played on foundations or built on tableau piles.
After the stock is exhausted, tableau spaces may be filled from the talon and the player may keep them open until he wishes to use them.
Cards are dealt from the hand to the talon by threes and this repeats until there are no more cards in the hand or the player quits. To have
cards dealt onto the talon the player types 'ht' for his move. Foundation base cards are also automatically moved to the foundation when
they become available.
The command 'c' causes canfield to maintain card counting statistics on the bottom of the screen. When properly used this can greatly
increase one's chances of winning.
The rules for betting are somewhat less strict than those used in the official version of the game. The initial deal costs $13. You may
quit at this point or inspect the game. Inspection costs $13 and allows you to make as many moves as possible without moving any cards from
your hand to the talon. (The initial deal places three cards on the talon; if all these cards are used, three more are made available.)
Finally, if the game seems interesting, you must pay the final installment of $26. At this point you are credited at the rate of $5 for each
card on the foundation; as the game progresses you are credited with $5 for each card that is moved to the foundation. Each run through the
hand after the first costs $5. The card counting feature costs $1 for each unknown card that is identified. If the information is toggled
on, you are only charged for cards that became visible since it was last turned on. Thus the maximum cost of information is $34. Playing
time is charged at a rate of $1 per minute.
With no arguments, the program cfscores prints out the current status of your canfield account. If a user name is specified, it prints out
the status of their canfield account. If the -a flag is specified, it prints out the canfield accounts for all users that have played the
game since the database was set up.
FILES
/usr/games/canfield the game itself
/usr/games/cfscores the database printer
/var/games/cfscores the database of scores
AUTHORS
Originally written: Steve Levine.
Further random hacking by: Steve Feldman, Kirk McKusick, Mikey Olson, and Eric Allman.
BUGS
It is impossible to cheat.
The score file database is not portable.
BSD January 1, 2010 BSD