#!/bin/bash # nim.sh: Game of Nim # Author: Mendel Cooper # Reldate: 15 July 2008 # License: GPL3 ROWS=5 # Five rows of pegs (or matchsticks). WON=91 # Exit codes to keep track of wins/losses. LOST=92 # Possibly useful if running in batch mode. QUIT=99 peg_msg= # Peg/Pegs? Rows=( 0 5 4 3 2 1 ) # Array holding play info. # ${Rows[0]} holds total number of pegs, updated after each turn. # Other array elements hold number of pegs in corresponding row. instructions () { clear tput bold echo "Welcome to the game of Nim."; echo echo -n "Do you need instructions? (y/n) "; read ans if [ "$ans" = "y" -o "$ans" = "Y" ]; then clear echo -e '\E[33;41m' # Yellow fg., over red bg.; bold. cat <