-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.cpp
More file actions
97 lines (95 loc) · 3 KB
/
Copy path15.cpp
File metadata and controls
97 lines (95 loc) · 3 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
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
#include <time.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
srand(time(NULL));
int var[1000],n,player=0,penny0=0,penny1=0,cmain=0,control=0,c=0,input,pointer=0,m,temp;
for(int c=0;c<1000;c++){
var[c]=-1;
}
cout << "Pennies in the Boxes" << endl;
n=rand();
n=n%30+1;
m=n;
for(int c=0;c<n;c++){
temp=rand();
temp=temp%30+1;
var[c]=temp;
}
cout << endl << "Game start" << endl;
cout << "0:left 1:right" << endl;
cout << "Board:";
while(cmain<m){
if(control==0){
if (c<n){
cout << var[c] << " ";
c++;
}else{
cout << endl;
control=1;
}
}else{
if(player==0){
cout << "Player1 Moves:";
cin >> input;
if(input!=0&&input!=1){
cout << "Please input 1,0."<<endl;
}else if(input==1){
penny0+=var[n-1];
var[n-1]=-1;
n--;
control=0;
player=1;
cmain++;
c=pointer;
cout << "Score: Player1:" << penny0 << " Computer:" << penny1<< endl;
cout<<"Board:";
}else if(input==0){
penny0+=var[pointer];
var[pointer]=-1;
pointer++;
control=0;
player=1;
cmain++;
c=pointer;
cout << "Score: Player1:" << penny0 << " Computer:" << penny1<< endl;
cout<<"Board:";
}
}else{
cout << "Computer Moves:";
if(var[n-1]>=var[pointer]){
cout << "1" << endl;
penny1+=var[n-1];
var[n-1]=-1;
n--;
control=0;
player=0;
cmain++;
c=pointer;
cout << "Score: Player1:" << penny0 << " Computer:" << penny1<<endl;
cout<<"Board:";
}else{
cout << "0" << endl;
penny1+=var[pointer];
var[pointer]=-1;
pointer++;
control=0;
player=0;
cmain++;
c=pointer;
cout << "Score: Player1:" << penny0 << " Computer:" << penny1<< endl;
cout<<"Board:";
}
}
}
}
cout<<endl;
if(penny0>penny1){
cout << "Player1 wins!" << endl;
}else if(penny1>penny0){
cout << "Computer wins!"<< endl;
}else{
cout << "It`s a tie!" << endl;
}
}