Finite State AI help [SOLVED]

So I’ve been trying to do the finite state AI puzzle and I’m missing something obvious or it is poorly worded. So I deduced that the initial while loops are there to gather information for the bots to use. Now using this bit of code which I will link at the bottom. I access the sample data 1. And then based on the costA etc I collect the molecules and then drop them off at the laboratory. But It says that the data is still in the cloud? Any help?

Code:

requiredMolecules[] req = new requiredMolecules[5];
            Console.WriteLine("GOTO DIAGNOSIS");
            Console.WriteLine("CONNECT 1");
            Console.WriteLine("GOTO MOLECULES");
            for(int i = 0; i < 4; i++){
                switch (i){
                    case 0:
                    req[i].letter = 'A';
                    req[i].number = A;
                    break;
                    case 1:
                    req[i].letter = 'B';
                    req[i].number = B;
                    break;
                    case 2:
                    req[i].letter = 'C';
                    req[i].number = C;
                    break;
                    case 3:
                    req[i].letter = 'D';
                    req[i].number = D;
                    break;
                    case 4:
                    req[i].letter = 'E';
                    req[i].number = E;
                    break;
                    }
            }
            for(int i = 0; i < 4;i++){
                if (req[i].number > 0){
                    for (int k = 0; k < req[i].number;k++){
                    Console.WriteLine("CONNECT " + req[i].letter);
                    }
                    }
                }
            Console.WriteLine("GOTO LABORATORY");
            Console.WriteLine("CONNECT 1");

requiredMolecules is my own custom type which contains a letter char and number of required molecules of the related char.

In 1 turn you

  • read the console input
  • plan your turn
  • print one action

When you have multiple WriteLines, your program will get out of sync with the actual game.

Your program should be something like this:

if (location == "DIAGNOSIS") action = "CONNECT " + id; // or GOTO MOLECULES
else if (location == "MOLECULES") action = ...

Console.WriteLine(action);
3 Likes

Ah so I think what your saying is I’m doing everything in the equivalence of 1 turn. And that’s resulting in everything going out of sync? So I have to do one action. Then let the game update, then do another action?

Correct, only print 1 line in each iteration of the while (true) loop.

1 Like

I did the same mistake at first and spent a lot of time trying to understand what was wrong (I had written two commands in the same turn). Now I’m more careful about what I wirte :slight_smile: .

Ok now I’ve got the problem of the sample molecules not working still. This code should write one line at a time (It’s called once every while loop). Also after taking the sample, I gather the current costA etc into static ints (this is updated only once). Then the if statements filter through slowly collecting the molecules. When all equal 0, it moves to the lab and submits the sample data and molecules. But it says they are incorrect? :S!

Code:

static string action(){
         string actionCommand = null;
         if (location == null || location == "LABORATORY" && startLaboratory == false){
             location = "DIAGNOSIS";
             return actionCommand = "GOTO DIAGNOSIS";
             } else if (location == "DIAGNOSIS" && pickedSample == false){
                 pickedSample = true;
                 return actionCommand = "CONNECT 1";
             } else if(location == "DIAGNOSIS" && pickedSample == true){
                 pickedSample = false;
                 location = "MOLECULES";
                 return actionCommand = "GOTO MOLECULES";
             } else if (location == "MOLECULES" && startMolecules == false){
                startMolecules = true;
                Agather = A;
                Bgather = B;
                Cgather = C;
                Dgather = D;
                Egather = E;
                if(Agather > 0){
                     Agather = Agather - 1;
                     return actionCommand = "CONNECT A";
                 } else if (Bgather > 0){
                     Bgather = Bgather - 1;
                     return actionCommand = "CONNECT B";
                 } else if (Cgather > 0){
                     Cgather = Cgather - 1;
                     return actionCommand = "CONNECT C";
                 } else if (Dgather > 0){
                     Dgather = Dgather - 1;
                     return actionCommand = "CONNECT D";
                 } else if (Egather > 0){
                     Egather = Egather - 1;
                     return actionCommand = "CONNECT E";
                 }
             } else if (location == "MOLECULES" && startMolecules == true){
                 if(Agather > 0){
                     Agather = Agather - 1;
                     return actionCommand = "CONNECT A";
                 } else if (Bgather > 0){
                     Bgather = Bgather - 1;
                     return actionCommand = "CONNECT B";
                 } else if (Cgather > 0){
                     Cgather = Cgather - 1;
                     return actionCommand = "CONNECT C";
                 } else if (Dgather > 0){
                     Dgather = Dgather - 1;
                     return actionCommand = "CONNECT D";
                 } else if (Egather > 0){
                     Egather = Egather - 1;
                     return actionCommand = "CONNECT E";
                 } else {
                     startMolecules = false;
                     startLaboratory = true;
                     location = "LABORATORY";
                     return actionCommand = "GOTO LABORATORY";
                 }
             } else if (location == "LABORATORY" && startLaboratory == true){
                 startLaboratory = false;
                 return actionCommand = "CONNECT 1";
                 }
        return null;
    }

Solved, have to store the incoming data.