Rock Paper Scissors


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Rock Paper Scissors
# 1  
Old 04-02-2009
Rock Paper Scissors

I'm trying to create this game in Unix.

This is what I have so far:

Code:
echo "Player one: Choose (R)ock, (P)aper (S)cissors"
stty -echo
read Pone
case $Pone
in
R) echo "Good Choice! Let's see what Player two chooses.";;
P) echo "Good Choice! Let's see what Player two chooses.";;
S) echo "Good Choice! Let's see what Player two chooses.";;
*) echo "Please choose only R,P or S.";;
esac
 
echo "Player two: Choose (R)ock, (P)aper (S)cissors"
stty -echo
read Ptwo
case $Ptwo
in
R) echo "Good Choice! ";;
P) echo "Good Choice! ";;
S) echo "Good Choice! ";;
*) echo "Please choose only R,P or S.";;
esac

I need to be able to take both inputs and give it a value 1,2,3,or4 so I can use those values for the possible combination of the outcome. Any suggestions would be appreciated.

Ro

P.S. Does anyone know how to cut and paste between virtual machine and your actual machine?

Last edited by Yogesh Sawant; 04-03-2009 at 02:56 PM.. Reason: added code tags
# 2  
Old 04-02-2009
Quote:
P.S. Does anyone know how to cut and paste between virtual machine and your actual machine?
Edit/Delete Message
No... but they can have disk space in common (NFS)...
IMHO its the second that should do the processing then send output to both StdOut
# 3  
Old 04-02-2009
Thanks VBE. Any suggestions on the game I'm trying to make?
# 4  
Old 04-02-2009
Start by doing a decision tree/table
You will see more clear...
# 5  
Old 04-02-2009
Tree was the answer

Thanks VBE,

I made a tree and was able to see it much clearer. I made 4 seperate scripts using case statements. Now my assignment is complete.

Now i got addicted to this stuff and want to add a scoring system where i can append a score. Any ideas?

gpro
# 6  
Old 04-02-2009
PHP

Hi,

here's my version of RPS. I tried to get basic functionality for keeping track of the score. Of course, there's still much to improve, but that's your job Smilie

Code:
#!/bin/bash

# Load score from files player1.score and player2.score, if they exist.
# Otherwise leave them 0.

p1_number_of_victories=0
p2_number_of_victories=0

if [ -e player1.score -a -e player2.score ]; then
        p1_number_of_victories=`cat player1.score`
        p2_number_of_victories=`cat player2.score`
fi

function p1_wins() {
        p1_number_of_victories=`expr $p1_number_of_victories + 1`
}

function p2_wins() {
        p2_number_of_victories=`expr $p2_number_of_victories + 1`
}

abort_game=n

until [ $abort_game = y ]; do
        PS3='Choose your action, player 1: '
        select action1 in "Rock" "Paper" "Scissors"; do break; done
        PS3='Choose your action, player 2: '
        select action2 in "Rock" "Paper" "Scissors"; do break; done

        case $action1 in
        "Rock")
                case $action2 in
                        "Rock") echo "Draw";;
                        "Paper") echo "Player 2 wins"; p2_wins;;
                        "Scissors") echo "Player 1 wins"; p1_wins;;
                esac
                ;;
        "Paper")
                case $action2 in
                        "Rock") echo "Player 1 wins"; p1_wins;;
                        "Paper") echo "Draw";;
                        "Scissors") echo "Player 2 wins"; p2_wins;;
                esac
                ;;
        "Scissors")
                case $action2 in
                        "Rock") echo "Player 2 wins"; p2_wins;;
                        "Paper") echo "Player 1 wins"; p1_wins;;
                        "Scissors") echo "Draw";;
                esac
                ;;
        esac

echo "Do you want to quit the game? [y/N]"
read abort_game
if [ -z "$abort_game" ]; then abort_game=n; fi # -z: input is empty -> ENTER was pressed

done
# end of loop

# Write new score to .score files
echo $p1_number_of_victories > player1.score
echo $p2_number_of_victories > player2.score

# exit gently
exit 0

 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Red Hat

i want to enjoy and rock my career as linux admin

hello i want to build my career as linux admin.I have completed my Engineering and had one month training on LINUX ADMIN course.I am doing well now in basics.Kindly provide suggetions or advice or books etc etc so that it will enhance my knowledge in linux Redhat. (1 Reply)
Discussion started by: dillipkmrpadhy
1 Replies

2. UNIX and Linux Applications

Problems of sharing of disk space in Rock Clusters

Hi Server configuration is Processor : xeon 64 bit Os: centos 5 We are in the process of setting up the Rock Cluster with 5 node.Currently the node are communication with each other however the disk space is not being shared in the cluster We would like to know how to used one disk space... (1 Reply)
Discussion started by: airquality
1 Replies

3. High Performance Computing

problem in the of installation rock cluster

Hai, I am trying to install rock4.3 in my Intel core2 quad process, but when i insert kernel cd which is the first step in the installation procedure, it asks for driver disk not found.. insert CD/DVD ROM even after i inserted my CD in my driver.. could anyone help me in solving this problem...... (1 Reply)
Discussion started by: sasirekha
1 Replies

4. UNIX for Dummies Questions & Answers

MPI in Rock cluster

hi, may i know how to run mpi after i had install the rock cluster? is there any guidelines or examples? (0 Replies)
Discussion started by: joannetan9984
0 Replies

5. UNIX for Dummies Questions & Answers

Rock Cluster

Hello, I had install the rock cluster 4.3 version on my pcs..but i can't access into the desktop...may i know what is the problem? (1 Reply)
Discussion started by: joannetan9984
1 Replies

6. OS X (Apple)

Mac OS X: Based on UNIX - Solid As a Rock

See this threads: Page Not Found - Apple Open Source - Apple (0 Replies)
Discussion started by: Neo
0 Replies

7. UNIX for Dummies Questions & Answers

Research paper

I am doing a "research" paper for school and i'm having a hard time finding accurate information. I am supposed to choose three differant versions of unix, give a brief explination of each, tell why there each differant from each other. I have found a ton of web sites but the information is so vast... (1 Reply)
Discussion started by: pantsusan
1 Replies
Login or Register to Ask a Question