Program a Stick game in C

profileTranger
stick1.sh

#!/bin/sh echo Welcome to Stick Game while : do echo "How many sticks to play with (must be greater than or equal to 10)" read stickCount #below if statement is checking if the entered number is greater than or equal to 1 if [ $stickCount -ge 10 2>/dev/null ] ; then break fi done isValid=0 while : do echo "Press u for user and c for computer to start" read turn if [ $turn = "c" -o $turn = "u" ]; then while : do if [ $turn = "c" ] ; then echo "Computer's turn" #logic to get optimal number of sticks to be removed. remainder=`expr $stickCount % 4` if [ $remainder -eq 0 ]; then stickCount=`expr $stickCount - 1` remainder=1 else stickCount=`expr $stickCount - $remainder` fi echo "$remainder sticks removed" if [ $stickCount -lt 1 ] ; then echo "All sticks removed. Winner : Computer" exit 0 fi char='|' result=$( printf "%${stickCount}s" ' ' ) echo "${result// /$char} ($stickCount remaining)" echo turn="u" else echo "User's turn" while : do echo "Enter sticks to remove (1,2 or 3)" read removedSticks if [ $removedSticks -ge 0 2>/dev/null ] ; then #checking if number is 1, 2 or 3 if [ $removedSticks -eq 1 -o $removedSticks -eq 2 -o $removedSticks -eq 3 ] ; then echo "$removedSticks sticks removed" stickCount=`expr $stickCount - $removedSticks` if [ $stickCount -lt 1 ] ; then echo "All sticks removed. Winner : User" echo exit 0 else #Printing number of remaining sticks char='|' result=$( printf "%${stickCount}s" ' ' ) echo "${result// /$char} ($stickCount remaining)" echo isValid=0 turn="c" break fi #if user inputs an invalid number else if [ $isValid -eq 0 ]; then echo "Please try again as you still have one more chance" isValid=1 elif [ $isValid -eq 1 ]; then echo "User forfeited. Computer Wins!!!!" exit 0 fi fi #if user entered an invalid value else if [ $isValid -eq 0 ]; then echo "Please try again as you still have one more chance" isValid=1 elif [ $isValid -eq 1 ]; then echo "User forfeited. Computer Wins!!!!" echo exit 0 fi fi done fi done fi done