-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18.cpp
More file actions
82 lines (81 loc) · 2.5 KB
/
Copy path18.cpp
File metadata and controls
82 lines (81 loc) · 2.5 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
#include <iostream>
using namespace std;
int main(){
int board,choice,storage[22],stop[22],control=0,cgame=1;
cout << "Please input board size:";
for(int c=0;c<22;c++){
storage[c]=-1;
}
cin >> board;
for(int c=1;c<=board;c++){
if (c<=board/2){
storage[c]=2;
stop[c]=1;
}else if(c==board/2+1){
storage[c]=0;
stop[c]=0;
}else{
storage[c]=1;
stop[c]=2;
}
}
while(control!=3){
if(control==0){
for(int c=1;c<=board;c++){
if(storage[c]==1){
cout << " F ";
}else if(storage[c]==2){
cout << " T ";
}else{
cout << " - ";
}
}
cout << endl;
control=1;
}else if(control==1){
cin >> choice;
if(choice<=0||choice>board||storage[choice]==0){
cout << "Bad input" << endl;
control=1;
}else{
if(storage[choice]==2){
if(storage[choice+1]==0){
storage[choice]=0;
storage[choice+1]=2;
control=2;
}else if(storage[choice+2]==0&&storage[choice+1]==1){
storage[choice+2]=2;
storage[choice]=0;
control=2;
}else{
cout << "Bad input" << endl;
control=1;
}
}else if(storage[choice]==1){
if(storage[choice-1]==0){
storage[choice]=0;
storage[choice-1]=1;
control=2;
}else if(storage[choice-2]==0&&storage[choice-1]==2){
storage[choice-2]=1;
storage[choice]=0;
control=2;
}else{
cout << "Bad input" << endl;
control=1;
}
}
}
}else{
if(storage[cgame]!=stop[cgame]){
control=0;
}else{
cgame++;
if(cgame==board){
control=3;
}
}
}
}
cout << "You win!" << endl;
}