-
Notifications
You must be signed in to change notification settings - Fork 0
/
trial3.go
141 lines (116 loc) · 2.57 KB
/
trial3.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import "fmt"
import "math/rand"
func main() {
var repeat string = "yes"
var newMatch = "yes"
var playerMove, comMove string
var outcome, playerPoints, comPoints float64
var match int
/*
var output float64
output = checkWin("scissors", "paper")
fmt.Println(output)
*/
fmt.Println(" ")
fmt.Println("==============================================================================")
fmt.Println("Welcome to Rock, Paper, Scissors by Shane Treadway.")
fmt.Println("--")
fmt.Println(" ")
fmt.Println("You will play the computer for the best out of three games.")
fmt.Println(" ")
for repeat == "yes" {
playerPoints = 0
comPoints = 0
match = 0
newMatch = "yes"
for newMatch == "yes" {
match = match + 1
fmt.Println("Match", match)
fmt.Println("Type your choosen move (rock, paper, or scissors): ")
fmt.Scanf("%s", &playerMove)
comMove = RockPaperScissorsGenerator()
fmt.Print("The computer played ", comMove, ".")
fmt.Println(" ")
outcome = checkWin(playerMove, comMove)
if outcome == 1 {
fmt.Println("Win")
playerPoints = playerPoints + 1
}
if outcome == 0 {
fmt.Println("Loss")
comPoints = comPoints + 1
}
if outcome == 0.5 {
fmt.Println("Tie")
}
fmt.Println(" ")
fmt.Println("Your Wins: ", playerPoints)
fmt.Println("Computer Wins: ", comPoints)
fmt.Println(" ")
if playerPoints == 2 {
fmt.Println("Congradulations! You won in ", match, " matches.")
newMatch = "no"
}
if comPoints == 2 {
fmt.Println("Sorry, you lost in ", match, " matches.")
newMatch = "no"
}
}
fmt.Println("Would you like to play again? (yes/no)")
fmt.Scanf("%s", &repeat)
fmt.Println("==============================================================================")
fmt.Println(" ")
}
}
func RockPaperScissorsGenerator() string {
var randomNumber int = rand.Intn(3)
var move string
if randomNumber == 0 {
move = "rock"
}
if randomNumber == 1 {
move = "paper"
}
if randomNumber == 2 {
move = "scissors"
}
return move
}
func checkWin(move1 string, move2 string) float64 {
var result float64
if move1 == "rock" {
if move2 == "rock" {
result = 0.5
}
if move2 == "paper" {
result = 0
}
if move2 == "scissors" {
result = 1
}
}
if move1 == "paper" {
if move2 == "rock" {
result = 1
}
if move2 == "paper" {
result = 0.5
}
if move2 == "scissors" {
result = 0
}
}
if move1 == "scissors" {
if move2 == "rock" {
result = 0
}
if move2 == "paper" {
result = 1
}
if move2 == "scissors" {
result = 0.5
}
}
return result
}