|
Pieters bash scripts
Documentation for the bash scripts I have published
|
This script allows someone to play the game patience. More...
Go to the source code of this file.
Functions | |
| printErrorDescription ($arg1) | |
| Prints a descriptive error message based on the given error code. | |
| terminalBlackForeground () | |
| Sets the terminal text color to black. | |
| terminalRedForeground () | |
| Sets the terminal text color to red. | |
| terminalGreenForeground () | |
| Sets the terminal text color to green. | |
| terminalBrownForeground () | |
| Sets the terminal text color to brown. | |
| terminalBlueForeground () | |
| Sets the terminal text color to blue. | |
| terminalPurpleForeground () | |
| Sets the terminal text color to purple. | |
| terminalCyanForeground () | |
| Sets the terminal text color to cyan. | |
| terminalGreyForeground () | |
| Sets the terminal text color to gray. | |
| terminalBlackBackground () | |
| Sets the terminal background color to black. | |
| terminalRedBackground () | |
| Sets the terminal background color to red. | |
| terminalGreenBackground () | |
| Sets the terminal background color to green. | |
| terminalBrownBackground () | |
| Sets the terminal background color to brown. | |
| terminalBlueBackground () | |
| Sets the terminal background color to blue. | |
| terminalPurpleBackground () | |
| Sets the terminal background color to purple. | |
| terminalCyanBackground () | |
| Sets the terminal background color to cyan. | |
| terminalGreyBackground () | |
| Sets the terminal background color to gray. | |
| terminalBold () | |
| Sets the terminal to print bold text. | |
| terminalUnderline () | |
| Sets the terminal to print underlined text. | |
| terminalClearColors () | |
| Sets the terminal to reset the colors to the default. | |
| setBoardBackground () | |
| Sets the background of the board patience is played on. | |
| debugPrintDeck () | |
| Print the cards in the deck for debug purposes. | |
| removeFromDeckOpen ($arg1) | |
| removeFromDeckFront ($arg1, $arg2) | |
| Remove cards from the front of the deck. | |
| removeFromDeck ($arg1) | |
| reindexDeck () | |
| Reindex the deck, i.e. remove gaps in array. | |
| shuffleDeck () | |
| Move the cards in the deck to a random new position. | |
| populateDeck () | |
| Fill the deck with all the cards. | |
| rotateDeck ($arg1) | |
| printSuitsStack () | |
| Print the suit stacks as a string, if empty print the suit symbol. | |
| printDeck ($arg1) | |
| printBoard ($arg1, $arg2) | |
| printBoardContent () | |
| Helper function to print the board. It handles the coloring of the board. arguments same as args to printf. | |
| printScore () | |
| Helper function to print the board. It handles the coloring of the board. | |
| printHelp ($arg1) | |
| Print the help function and handles help navigation through the help. | |
| printCard ($arg1, $arg2) | |
| printCredits () | |
| Print the credits of the game and perform a short "animation". | |
| isGameWon () | |
| dealBlinds () | |
| Deal the blind cards on the board. | |
| fillOpen () | |
| turnBlind ($arg1) | |
| initSuitStack () | |
| Initialise the suitstacks. | |
| getBottomCard ($arg1) | |
| getTopCard ($arg1) | |
| moveDeckToSuitStack () | |
| removeFromOpenStacks ($arg1, $arg2) | |
| removeFromSuit ($arg1) | |
| initOpen () | |
| Initialise the open stacks on the board. | |
| findCard ($arg1) | |
| getCardValue ($arg1) | |
| getCardSuit ($arg1) | |
| getCardColor ($arg1) | |
| isValidBoardMove ($arg1, $arg2) | |
| isValidSuitMove ($arg1) | |
| moveCards ($arg1, $arg2) | |
| autoMoveToSuitstacks () | |
| Try to put all available cards on the suitstacks. | |
| nameToCard ($arg1) | |
| cardToName ($arg1) | |
| calculateLeftMargin ($arg1, $arg2) | |
| calculateTopMargin ($arg1, $arg2) | |
| init () | |
| Initialise the game. | |
| cleanup () | |
| Cleanup remnants of the old game before starting a new. | |
| confirmAction ($arg1) | |
| checkTerminalSize ($arg1, $arg2) | |
| main () | |
| Main function. | |
Variables | |
| const | $C_UNINIT = 2 |
| Bool is not initialised. | |
| const | $C_TRUE = 1 |
| True value. | |
| const | $C_FALSE = 0 |
| False value. | |
| const | $C_SUCCESS = 255 |
| const | $C_EMPTY_COLUMN = 254 |
| Indicates the selected column to take a card from is emtpy. | |
| const | $C_MOVE_INVALID = 253 |
| Indicates the given move is not a valid move. | |
| const | $C_CARD_NOT_FOUND = 252 |
| Indicates the card asked for is not available for a move. | |
| const | $C_COLUMN_NOT_EXISTS = 251 |
| Indicates the given column does not exist. | |
| const | $C_INVALID_ARGUMENT = 250 |
| Indicates the argument given does not exist. | |
| const | $C_NULL_CARD = 249 |
| Indicates the card given is empty. | |
| const | $C_NO_BLINDS = 248 |
| The request to turn a blind card cannot be fulfilled as there are no blind cards. | |
| const | $C_NOT_ENOUGH_CARDS = 247 |
| The card stack is too small to give the requested cards. | |
| const | $C_INCORRECT_CARD_NAME = 246 |
| The given name is not a valid card name. | |
| const | $C_TERMINAL_SIZE_ERROR = 245 |
| The size of the terminal is not large enough to show the patience board. | |
| const | $C_DEBUG_STOP = 70 |
| Returned prematurely for debug purposes. | |
| $useColoredTerminal = $C_TRUE | |
| Indicates if terminal colors should be used. | |
| $deck | |
| The deck of cards. | |
| $blindStacks | |
| The blind cards of each column. | |
| $openStacks | |
| The open cards of each column. | |
| $deckOpen | |
| The open cards on the unplayed deck. | |
| $deckFront | |
| The card on the front of the deck. | |
| $suitStack | |
| Stacks of cards having been sorted by suit. | |
| $user_msg1 = "Welcome" | |
| Text for the user message, first row. | |
| $user_msg2 = " press h for help" | |
| Text for the user message, second row. | |
| $marginLeft = "" | |
| How much margin to keep to the left of the terminal to center the board. | |
| $marginTop = "" | |
| How much margin to keep to the top of the terminal to center the board. | |
| $nDeckIterations = 0 | |
| How many times has the deck been rotated (viewed all cards and started over). | |
| $score = 0 | |
| Current score. | |
This script allows someone to play the game patience.
Author: Pieter van der Star (info@.nosp@m.piet.nosp@m.ervan.nosp@m.ders.nosp@m.tar.n.nosp@m.l) Modifications by: (unmodified)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Definition in file patience.sh.
| autoMoveToSuitstacks | ( | ) |
Try to put all available cards on the suitstacks.
Definition at line 1161 of file patience.sh.

| calculateLeftMargin | ( | $arg1, | |
| $arg2 ) |
Calculate the margin so the board ends up in the middle of the terminal.
| $arg1 | terminal width. |
| $arg2 | width of the content (board is different to help) |
Definition at line 1270 of file patience.sh.
| calculateTopMargin | ( | $arg1, | |
| $arg2 ) |
Calculate the margin so the board ends up in the middle of the terminal.
| $arg1 | terminal height. |
| $arg2 | height of the content (board is different to help) |
Definition at line 1287 of file patience.sh.
| cardToName | ( | $arg1 | ) |
Convert cardnumber to a human readable card name.
| $arg1 | card number. |
Prints card name, for use in $(cardToName n)
Definition at line 1239 of file patience.sh.
| checkTerminalSize | ( | $arg1, | |
| $arg2 ) |
Check if the terminal has the correct size to display the board.
| $arg1 | Width of the terminal (in characters). |
| $arg2 | Width of the terminal (in characters). |
Definition at line 1370 of file patience.sh.
| cleanup | ( | ) |
Cleanup remnants of the old game before starting a new.
Definition at line 1341 of file patience.sh.
| confirmAction | ( | $arg1 | ) |
Ask user for confirmation.
| $arg1 | Description of the action to perform. |
Definition at line 1353 of file patience.sh.
| dealBlinds | ( | ) |
Deal the blind cards on the board.
Definition at line 745 of file patience.sh.

| debugPrintDeck | ( | ) |
Print the cards in the deck for debug purposes.
Definition at line 165 of file patience.sh.
| fillOpen | ( | ) |
Fill any open columns on the board.
Definition at line 764 of file patience.sh.


| findCard | ( | $arg1 | ) |
Search the deck, board and suitstacks for the given card.
| $arg1 | Cardnumber of the card to find. |
Definition at line 911 of file patience.sh.
| getBottomCard | ( | $arg1 | ) |
Get the card value at the bottom of the given column
| $arg1 | column |
Definition at line 808 of file patience.sh.

| getCardColor | ( | $arg1 | ) |
Get the color of the card based on the cardnumber.
| $arg1 | Cardnumber. |
Definition at line 966 of file patience.sh.
| getCardSuit | ( | $arg1 | ) |
Get the suit of the card based on the cardnumber.
| $arg1 | Cardnumber. |
Definition at line 958 of file patience.sh.
| getCardValue | ( | $arg1 | ) |
Get the value of the card based on the cardnumber.
| $arg1 | Cardnumber. |
Definition at line 950 of file patience.sh.
| getTopCard | ( | $arg1 | ) |
Get the card value at the top of the given column.
| $arg1 | column. |
Definition at line 824 of file patience.sh.
| init | ( | ) |
Initialise the game.
Definition at line 1325 of file patience.sh.

| initOpen | ( | ) |
Initialise the open stacks on the board.
Definition at line 896 of file patience.sh.
| initSuitStack | ( | ) |
Initialise the suitstacks.
Definition at line 798 of file patience.sh.
| isGameWon | ( | ) |
Check if the game is won.
Definition at line 733 of file patience.sh.
| isValidBoardMove | ( | $arg1, | |
| $arg2 ) |
Check if the move is a valid move on the board.
| $arg1 | Cardnumber of card to move. |
| $arg2 | cardnumber of card to move the arg1 card on top of. |
Definition at line 975 of file patience.sh.
| isValidSuitMove | ( | $arg1 | ) |
Check if the move is a valid move to the suitstacks.
| $arg1 | cardnumber of card to move. |
Definition at line 1009 of file patience.sh.
| main | ( | ) |
Main function.
Definition at line 1382 of file patience.sh.
| moveCards | ( | $arg1, | |
| $arg2 ) |
Move card from A to B.
| $arg1 | card to move. |
| $arg2 | location to move to. |
Definition at line 1025 of file patience.sh.

| moveDeckToSuitStack | ( | ) |
Move a card from the deck to the corresponding suitstack.
Definition at line 839 of file patience.sh.
| nameToCard | ( | $arg1 | ) |
Convert a human card name to a cardnumber.
| $arg1 | abbrieviated human name for the card. |
Definition at line 1210 of file patience.sh.
| populateDeck | ( | ) |
Fill the deck with all the cards.
Definition at line 306 of file patience.sh.

| printBoard | ( | $arg1, | |
| $arg2 ) |
Print the board.
| $arg1 | (optional) has player won the game. |
| $arg2 | (optional) end of deck iterations. |
Definition at line 414 of file patience.sh.

| printBoardContent | ( | ) |
Helper function to print the board. It handles the coloring of the board. arguments same as args to printf.
Definition at line 496 of file patience.sh.
| printCard | ( | $arg1, | |
| $arg2 ) |
Output a card character.
| $arg1 | cardnumber of card to print. |
| $arg2 | (optional) print the card closed. |
Definition at line 667 of file patience.sh.

| printCredits | ( | ) |
Print the credits of the game and perform a short "animation".
Definition at line 706 of file patience.sh.

| printDeck | ( | $arg1 | ) |
Print the deck, in two parts, first the closed, then the front.
| $arg1 | end of deck iterations. |
Definition at line 379 of file patience.sh.
| printHelp | ( | $arg1 | ) |
Print the help function and handles help navigation through the help.
| $arg1 | (optional) pagenumber to show. |
Definition at line 512 of file patience.sh.

| printScore | ( | ) |
Helper function to print the board. It handles the coloring of the board.
Definition at line 501 of file patience.sh.
| printSuitsStack | ( | ) |
Print the suit stacks as a string, if empty print the suit symbol.
Definition at line 356 of file patience.sh.

| reindexDeck | ( | ) |
Reindex the deck, i.e. remove gaps in array.
Definition at line 268 of file patience.sh.

| removeFromDeck | ( | $arg1 | ) |
Remove cards from the closed part of the deck at given index and fill the gap.
| $arg1 | index of the card to be removed. |
Definition at line 250 of file patience.sh.

| removeFromDeckFront | ( | $arg1, | |
| $arg2 ) |
Remove cards from the front of the deck.
| $arg1 | Index of the card to be removed. |
| $arg2 | should it backfill from deckOpen. |
Remove cards from the open part of the deck at given index and fill the gap. If backfill is set take one card from the open hand of the deck and move it to the front.
Definition at line 218 of file patience.sh.
| removeFromDeckOpen | ( | $arg1 | ) |
Remove cards from the open part of the deck at given index and fill the gap.
| $arg1 | Index of the card to be removed. |
Definition at line 193 of file patience.sh.
| removeFromOpenStacks | ( | $arg1, | |
| $arg2 ) |
Remove a card from one of the open stacks on the board.
| $arg1 | column index. |
| $arg2 | number of cards. |
Definition at line 866 of file patience.sh.
| removeFromSuit | ( | $arg1 | ) |
Remove a card from the suitstack.
| $arg1 | the suit to remove the card from. |
Definition at line 886 of file patience.sh.
| rotateDeck | ( | $arg1 | ) |
Move cards from the front to the open deck and then nFront from the closed to the front.
| $arg1 | how many cards should be in a hand. |
Definition at line 317 of file patience.sh.
| setBoardBackground | ( | ) |
Sets the background of the board patience is played on.
Definition at line 161 of file patience.sh.

| shuffleDeck | ( | ) |
Move the cards in the deck to a random new position.
Definition at line 288 of file patience.sh.

| terminalBlackBackground | ( | ) |
Sets the terminal background color to black.
Definition at line 138 of file patience.sh.
| terminalBlackForeground | ( | ) |
Sets the terminal text color to black.
Definition at line 121 of file patience.sh.

| terminalBlueBackground | ( | ) |
Sets the terminal background color to blue.
Definition at line 146 of file patience.sh.

| terminalBlueForeground | ( | ) |
Sets the terminal text color to blue.
Definition at line 129 of file patience.sh.
| terminalBold | ( | ) |
Sets the terminal to print bold text.
Definition at line 155 of file patience.sh.
| terminalBrownBackground | ( | ) |
Sets the terminal background color to brown.
Definition at line 144 of file patience.sh.
| terminalBrownForeground | ( | ) |
Sets the terminal text color to brown.
Definition at line 127 of file patience.sh.

| terminalClearColors | ( | ) |
Sets the terminal to reset the colors to the default.
Definition at line 159 of file patience.sh.
| terminalCyanBackground | ( | ) |
Sets the terminal background color to cyan.
Definition at line 150 of file patience.sh.
| terminalCyanForeground | ( | ) |
Sets the terminal text color to cyan.
Definition at line 133 of file patience.sh.
| terminalGreenBackground | ( | ) |
Sets the terminal background color to green.
Definition at line 142 of file patience.sh.

| terminalGreenForeground | ( | ) |
Sets the terminal text color to green.
Definition at line 125 of file patience.sh.

| terminalGreyBackground | ( | ) |
Sets the terminal background color to gray.
Definition at line 152 of file patience.sh.
| terminalGreyForeground | ( | ) |
Sets the terminal text color to gray.
Definition at line 135 of file patience.sh.

| terminalPurpleBackground | ( | ) |
Sets the terminal background color to purple.
Definition at line 148 of file patience.sh.
| terminalPurpleForeground | ( | ) |
Sets the terminal text color to purple.
Definition at line 131 of file patience.sh.
| terminalRedBackground | ( | ) |
Sets the terminal background color to red.
Definition at line 140 of file patience.sh.
| terminalRedForeground | ( | ) |
Sets the terminal text color to red.
Definition at line 123 of file patience.sh.

| terminalUnderline | ( | ) |
Sets the terminal to print underlined text.
Definition at line 157 of file patience.sh.
| turnBlind | ( | $arg1 | ) |
Turn a blind card from a given column.
| $arg1 | column to turn the frontmost blind card. |
Definition at line 784 of file patience.sh.

| $blindStacks |
The blind cards of each column.
Definition at line 1306 of file patience.sh.
| const $C_FALSE = 0 |
False value.
Definition at line 60 of file patience.sh.
| const $C_TRUE = 1 |
True value.
Definition at line 58 of file patience.sh.
| const $C_UNINIT = 2 |
Bool is not initialised.
Definition at line 56 of file patience.sh.
| $deck |
The deck of cards.
Definition at line 1305 of file patience.sh.
| $deckFront |
The card on the front of the deck.
Definition at line 1309 of file patience.sh.
| $deckOpen |
The open cards on the unplayed deck.
Definition at line 1308 of file patience.sh.
| $marginLeft = "" |
How much margin to keep to the left of the terminal to center the board.
Definition at line 1315 of file patience.sh.
| $marginTop = "" |
How much margin to keep to the top of the terminal to center the board.
Definition at line 1317 of file patience.sh.
| $nDeckIterations = 0 |
How many times has the deck been rotated (viewed all cards and started over).
Definition at line 1320 of file patience.sh.
| $openStacks |
The open cards of each column.
Definition at line 1307 of file patience.sh.
| $score = 0 |
Current score.
Definition at line 1322 of file patience.sh.
| $suitStack |
Stacks of cards having been sorted by suit.
Definition at line 1310 of file patience.sh.
| $useColoredTerminal = $C_TRUE |
Indicates if terminal colors should be used.
Definition at line 119 of file patience.sh.
| $user_msg1 = "Welcome" |
Text for the user message, first row.
Definition at line 1311 of file patience.sh.
| $user_msg2 = " press h for help" |
Text for the user message, second row.
Definition at line 1313 of file patience.sh.