Hey, guys i've been working on for a while. And i completly got stuck in this moment, and the deadline is coming for me.
Code:
#include <stdio.h>
#include <time.h>
#include <cstdlib>
#include <string.h>
using namespace std;
char allseq[1296][4];
int z;
void hit_counter(char *seq_1, char *seq_2, int *result_1, int *result_2);
void sequence_deleter(char *seq);
int main() {
srand((unsigned)time(NULL));
int round/* z */, x, y, c, p;
char code[5];
char str[5];
//char allseq [1926][4];
int sl, sk, skl; //sl-słowo łamacz
z = 1296;
//sk-słowo koder
//skl-słowo klucz
for (x = 0; x<1296; x++)
{
allseq[x][0] = (x % 6) + 1;
allseq[x][1] = ((x / 6) % 6) + 1;
allseq[x][2] = ((x / 36) % 6) + 1;
allseq[x][3] = ((x / 216) % 6) + 1;
};
x = rand() % z;
sl = allseq[x][3] * 1000 + allseq[x][2] * 100 + allseq[x][1] * 10 + allseq[x][0];
printf("First guess: ");
printf("%d", sl);
printf("\nAnswer: ");
scanf("%4s", code);
sprintf(str,"%d",sl);
int k=0;
int number_x = 0;
int number_o = 0;
while (code[k])
{
if (code[k] == 'x')
{
number_x++;
k++;
continue;
}
else if (code[k] == 'o')
{
number_o++;
k++;
continue;
}
k++;
}
int res1, res2;
for (int i = 0; i < 1296;i++)
{
hit_counter(allseq[i], str, &res1, &res2);
if (res1 != number_x || res2 != number_o)
{ sequence_deleter(allseq[i]); }
}
system("pause");
return 0;
}
void hit_counter(char *seq_1, char *seq_2, int *result_1, int *result_2) {
char k1[5]; /* for sequence copy not to destroy the original one */
*result_1 = 0; /* for good placed pin's black one's) */
*result_2 = 0; /* for white pin's */
strcpy(k1, seq_1);
for (int i = 0; i < 4; i++)
{
if (k1[i] == seq_2[i])
{
*result_1++;
k1[i] = 'S';
}
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
if (k1[i] == seq_2[j])
{
*result_2++;
k1[i] = 'S';
}
}
}
}
void sequence_deleter(char *seq)
{
int i=0;
while (seq[i])
{
seq[i] = 'S';
}
}
Here is my code, generally i have no idea how to move on. I dont know how it should cope my strings and delete them from the all_seq two dimensional array. Generally i don't know how to send all these sequence combination to these functions. Any idea how i can finish this or something useful? Looking forward for your quick answers, thanks for all help to this time!