forked from ashtonbieri/Biocomp-Exercise08
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise8_Script.R
More file actions
55 lines (54 loc) · 1.81 KB
/
Copy pathExercise8_Script.R
File metadata and controls
55 lines (54 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Biocomputing Exercise 8
#Loan Duong
#1. Plot the running scores for UW vs MSU basketball
#Load the table
GameData <- read.table("UWvMSU_1-22-13.txt", header=TRUE)
#Define variables for two teams
unique(GameData$team)
scoreUW<-0
UWVector<-c(0)
scoreMSU<-0
MSUVector<-c(0)
time<-c(0,GameData$time)
#loop through rows to tally score, generate score vectors
for(i in 1:nrow(GameData)){
if(GameData$team[i]=="UW"){
scoreUW<-scoreUW+GameData$score[i]
UWVector<-append(UWVector, scoreUW, after=length(UWVector))
MSUVector<-append(MSUVector, scoreMSU, after=length(MSUVector))
}else{
scoreMSU<-scoreMSU+GameData$score[i]
UWVector<-append(UWVector, scoreUW, after=length(UWVector))
MSUVector<-append(MSUVector, scoreMSU, after=length(MSUVector))
}
}
#plot
plot(time,UWVector,type="l",col="red",xlab = "Time(Min)",ylab = "Score", main = "UW vs MSU")
lines(time,MSUVector,type="l", col="dark green")
#2. Guess my number game.
# Computer generates a random number between 1 and 100.
RandomNumber<-sample(1:100,1)
#Guessing game
#Run with GuessingGame()
GuessingGame<-function(){
PlayerGuess<-readline(prompt="I'm thinking of a number between 1 and 100. Take a guess? " )
RemainingGuesses <- 9
while(RemainingGuesses>0){
if(PlayerGuess<RandomNumber){
cat(paste("Sorry, that's incorrect. Guesses left: ", RemainingGuesses))
PlayerGuess<-readline(prompt="Try a higher number! ")
RemainingGuesses<-RemainingGuesses-1
}else{
if(PlayerGuess>RandomNumber){
cat(paste("Sorry, that's incorrect. Guesses left: ", RemainingGuesses))
PlayerGuess<-readline(prompt="Try a lower number! ")
RemainingGuesses<-RemainingGuesses-1
}else{
cat("Congratulations, you've guessed correctly!")
if(PlayerGuess==RandomNumber){
break
}
}
}
}
}