Sponsored Content
Top Forums Shell Programming and Scripting Proper distribution of cards in terminal based crazy8's game in bash script Post 302985627 by Scrutinizer on Sunday 13th of November 2016 02:23:18 AM
Old 11-13-2016
The problem is in the two following lines:
Code:
computerdeal 8 | sed -r 's/[0123456789JQKAHSDC]+/ * /g'

and
Code:
echo "          The Card in Play is: "$(deal) | tee /home/cogiz/cardinplay.txt

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:
Code:
deal 8

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:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

text based football game?

Is there a textbased football game (American) that I can download through ubuntu server edition? (1 Reply)
Discussion started by: dadoprso
1 Replies

2. Shell Programming and Scripting

Reading output from terminal back into bash script

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)
Discussion started by: dp123
0 Replies

3. Shell Programming and Scripting

Bash Script for "simple" racing game.

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)
Discussion started by: jl487
0 Replies

4. Shell Programming and Scripting

Run bash script without terminal

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)
Discussion started by: locoroco
1 Replies

5. UNIX for Dummies Questions & Answers

Is there picture based game under linux terminal?

Is there picture based game under linux terminal? Just like Supermario under DOS. (18 Replies)
Discussion started by: vistastar
18 Replies

6. Shell Programming and Scripting

Making a Text based game. Need help.

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)
Discussion started by: lemonoid
1 Replies

7. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

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)
Discussion started by: LaurenRose
3 Replies

8. Shell Programming and Scripting

Bash tcsh Script runs in terminal but not folder

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)
Discussion started by: OntorEska
8 Replies

9. Shell Programming and Scripting

Tetris Game -- based on a shell script (new algorithm)

GitHub - deepgrace/tetris: Tetris implementation in all kinds of Programming Languages Usage: bash Tetris_Game ] ] ] ] Range: #!/bin/bash # Tetris Game // The Art Of Shell Programming box0=(4 30) box1=(4 30 4 32) box2=(4 30 5 32) box3=(4 28 4 30 4 32) box4=(4 28 4 30... (69 Replies)
Discussion started by: complex.invoke
69 Replies

10. Shell Programming and Scripting

Creating a text based game using shell script.

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
CANFIELD(6)							 BSD Games Manual						       CANFIELD(6)

NAME
canfield, cfscores -- the solitaire card game canfield SYNOPSIS
canfield cfscores [-a] [user] 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 available 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 BUGS
It is impossible to cheat. AUTHORS
Originally written: Steve Levine. Further random hacking by: Steve Feldman, Kirk McKusick, Mikey Olson, and Eric Allman. BSD
May 31, 1993 BSD
All times are GMT -4. The time now is 09:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy