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
|
//CodeBreakerCPP
//Attempt to crack the code!
#include <iostream>
using namespace std;
//Global Constants
const char black = 'B';
const char white = 'W';
//Function Prototypes
void instructions();
void displayBoard(int[10][4],int[4]);
void calcResponse(int[4],int[4]);
//Main Function
int main(){
int move;
//instructions();
//TODO: SetCodeOrCrack? [Default: Crack]
int ans [4] = {1,2,3,4};
int codes [10][4];
for(int i=0;i<10;i++){
for(int j=0;j<4;j++){
codes[i][j]=i+j;
}
}
displayBoard(codes,ans);
return 0;
}
//Functions
void instructions()
{
cout << "Welcome to the ultimate man-machine showdown: Tic-Tac-Toe.\n";
cout << "--where human brain is pit against silicon processor\n\n";
cout << "Make your move known by entering a number, 0 - 8. The number\n";
cout << "corresponds to the desired board position, as illustrated:\n\n";
cout << " 0 | 1 | 2\n";
cout << " ---------\n";
cout << " 3 | 4 | 5\n";
cout << " ---------\n";
cout << " 6 | 7 | 8\n\n";
cout << "Prepare yourself, human. The battle is about to begin.\n\n";
}
void displayBoard(int codes[10][4],int ans[4])
{
for(int p=0;p<9;p++)
{
cout << "--------------------------\n";
cout << "|.0"<<p+1<<"| "<<codes[p][0]<<" | "<<codes[p][1]<<" | "<<codes[p][2]<<" | "<<codes[p][3]<<" |";
calcResponse(codes[p],ans);
cout<<"\n";
}
cout << "--------------------------\n";
cout << "|.10| "<<codes[9][0]<<" | "<<codes[9][1]<<" | "<<codes[9][2]<<" | "<<codes[9][3]<<" |\n";
cout << "--------------------------";
}
void calcResponse(int code[4],int ans[4]){
if(code[0]==0){
return;
}
int B=0,W=0;
for(int i=0;i<4;i++){
if(code[i]==ans[i]){
B++;
code[i]=0;
ans[i]=0;
}
}
for (int i=0;i<4;i++){
if(ans[i]==0){
continue;
}
for(int j=0;j<4;j++){
if(ans[i]==code[j]){
W++;
ans[i]=0;
code[j]=0;
break;
}
}
}
for(int i=0;i<B;i++){
cout<<black;
}
for(int i=0;i<W;i++){
cout<<white;
}
}
|