All pastes #545735 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-06 21:06 UTC
rendered paste body
#!/bin/bash

#elenxoume an dwthikan 2 parametroi

if [ $# -lt 2 ]
then
	echo "Error:you must supply two arguments (1-8)"
	exit 1
else
	Colors=$1
	Pegs=$2

	Color[0]="WH" #WHITE
	Color[1]="BL" #BLACK
	Color[2]="BU" #BLUE
	Color[3]="RD" #RED
	Color[4]="YL" #YELLOW
	Color[5]="GN" #GREEN
	Color[6]="PK" #PINK
	Color[7]="BR" #BROWN


	#o H/Y topothetei tuxaia ta xrwmata

	i=0	
	while [ $i -lt $2 ]
	do
		k=`expr $RANDOM % $Colors`
		Peg[$i]=$Color[k]
		i=`expr $i + 1`
	done

	found=1		#ginete 0 otan vrethei o swstos sindiasmos
	count=0 	#metraei to sinolo twn prospathiwn tou xristi


	#mexri na vrethei o swstos sindiasmos 
	#akolouthite i parakatw diadikasia

	while [ $found -eq 1 ]
	count=`expr $count + 1`
	do
		echo "User:"
		up=0
		#o xristis topothetei ta xrwmata

		while [ $up -lt $Pegs ]
		do
			echo "Peg $Pegs:"
			read usercolor
			userpeg[$up]=$usercolor
			echo -n "| $usercolor"
			up=`expr $up + 1`
		done
		echo -n "|"

		check=0
		echo " "
		echo "-----"
		echo "CPU:"

		#o H/Y elenxei ta xrwmata
	
		while [ $check -lt $Pegs ]
		do
			if [ ${userpeg[$check]} -eq ${Peg[$check]} ]
			then
				checkpeg[$check]="BL"	
						#swsto xrwma kai thesi
				echo -n "| B"
			else
				cp=0
				while [ $cp -lt $Pegs ]
				do
					if [ ${userpeg[$check]} -eq ${Peg[$cp]} ]
					then
						checkpeg[$check]="WH"		
							#swsto xrwma lathos thesi
						echo -n "| N"
							#tipota swsto
					fi
				done
				echo -n "|"
			fi
		done
	done

	fc=0
	while [ $fc -lt $Pegs ]
	do
		if [ checkpeg[$fc] = "BL" ]
		then
			$found=0
			fc=`expr $fc + 1`
		else
			$found=1
			break
		fi
	done

	echo "Congratulations!!!"
	echo "Your score is $count"
fi
exit 0