-
Notifications
You must be signed in to change notification settings - Fork 1
/
PigGameRay.java
222 lines (209 loc) · 6.7 KB
/
PigGameRay.java
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
* Auto Generated Java Class.
*/
import java.lang.Math;
import java.util.Scanner;
public class PigGameRay {
//Ms. Visa---- How my random works
//First My random limits the maximum time the computer can roll, which is 10
//Everytime it goes through the loop, the computer will minus 1
//It will roll a dice, first time through with 1/10 chance of stopping, second time 1/9, third time 1/8, and so on
//eventually, after 10 rounds, it will be a 1/1 chance of stopping.
//I played with computer with the random stopping, i usually win
//but with unrandom, the computer has a high chance of winning
//finally, I improved pig to how i usually play it, with two dice.
//if I get only one die with 1, that turn's points are gone
//if both dice show 1, your whole score is gone, returning your score to zero
//the goal is the same, to get to 100 points
//the two die game has the AI system shown above built in
//please definitely play by running pigtwo();
//have fun!
public static void main(String[] args){
//run pig completelyrandom
pigtwo();
//run pig not random (AI Mode)
//Uncomment this: pigunrand();
//run pig 2 dice
//Uncomment this: pigtwo();
}
public static void pig(){
int comp= 0;
int person=0;
int tempcomp=0;
int tempperson=0;
int stop= 0;
int stopperson=0;
int randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
Scanner scan = new Scanner(System.in);
while (comp<100&&person<100){
while (stop!=1){
randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Computer 2 Roll:" +randomNumber);
if (randomNumber==1){
tempcomp=0;
stop=1;
}else{
stop= (int) (Math.random() * (2 - 1 +1)+1);
tempcomp=tempcomp+randomNumber;
}
}
stop=0;
comp=comp+tempcomp;
tempcomp=0;
if(comp>100){
break;
}
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
while (stopperson!=1){
randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Person Roll:" +randomNumber);
if (randomNumber==1){
tempperson=0;
stopperson=1;
}else{
tempperson=tempperson+randomNumber;
System.out.print("Enter a Number(2 to roll, 1 to quit):");
stopperson = scan.nextInt();
}
}
stopperson=0;
person=person+tempperson;
tempperson=0;
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
}
if (person>100&&comp>100){
System.out.println("Tie Game!");
}else if(comp>100){
System.out.println("Computer Won! Computer got "+comp);
}else if(person>100){
System.out.println("Player Won! Player got "+person);
}
}
public static void pigunrand(){
int comp= 0;
int person=0;
int tempcomp=0;
int tempperson=0;
int stop= 0;
int stopperson=0;
int randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
int compcounter=10;
Scanner scan = new Scanner(System.in);
while (comp<100&&person<100){
while (stop!=1){
randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Computer 2 Roll:" +randomNumber);
if (randomNumber==1){
tempcomp=0;
stop=1;
}else{
stop= (int) (Math.random() * (compcounter - 1 +1)+1);
tempcomp=tempcomp+randomNumber;
}
}
stop=0;
comp=comp+tempcomp;
tempcomp=0;
compcounter=10;
if(comp>100){
break;
}
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
while (stopperson!=1){
randomNumber= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Person Roll:" +randomNumber);
if (randomNumber==1){
tempperson=0;
stopperson=1;
}else{
tempperson=tempperson+randomNumber;
System.out.print("Enter a Number(2 to roll, 1 to quit):");
stopperson = scan.nextInt();
}
}
stopperson=0;
person=person+tempperson;
tempperson=0;
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
}
if (person>100&&comp>100){
System.out.println("Tie Game!");
}else if(comp>100){
System.out.println("Computer Won! Computer got "+comp);
}else if(person>100){
System.out.println("Player Won! Player got "+person);
}
}
public static void pigtwo(){
int comp= 0;
int person=0;
int tempcomp=0;
int tempperson=0;
int stop= 0;
int stopperson=0;
int dice1= (int) (Math.random() * (6 - 1 +1)+1);
int dice2= (int) (Math.random() * (6 - 1 +1)+1);
int compcounter=10;
Scanner scan = new Scanner(System.in);
while (comp<100&&person<100){
while (stop!=1){
dice1= (int) (Math.random() * (6 - 1 +1)+1);
dice2= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Computer 2 Roll:" +dice1+" "+dice2);
if(dice1==1&&dice2==1){
comp=0;
tempcomp=0;
stop=1;
}else if (dice1==1||dice2==1){
tempcomp=0;
stop=1;
}else{
stop= (int) (Math.random() * (compcounter - 1 +1)+1);
tempcomp=tempcomp+dice1+dice2;
compcounter--;
}
}
stop=0;
comp=comp+tempcomp;
tempcomp=0;
compcounter=10;
if(comp>100){
break;
}
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
while (stopperson!=1){
dice1= (int) (Math.random() * (6 - 1 +1)+1);
System.out.println("Person Roll:" +dice1+" "+dice2);
if(dice1==1&&dice2==1){
person=0;
tempperson=0;
stop=1;
}else if (dice1==1||dice2==1){
tempperson=0;
stopperson=1;
}else{
tempperson=tempperson+dice1+dice2;
System.out.print("Enter a Number(2 to roll, 1 to quit):");
stopperson = scan.nextInt();
}
}
stopperson=0;
person=person+tempperson;
tempperson=0;
System.out.println("Current Computer Score: "+comp);
System.out.println("Current Person Score: "+person);
}
if (person>=100&&comp>=100){
System.out.println("Tie Game!");
}else if(comp>=100){
System.out.println("Computer Won! Computer got "+comp);
}else if(person>=100){
System.out.println("Player Won! Player got "+person);
}
}
}