private static Int64 RunPhase(ACS[] amps, int[] phaseSettings, bool feedBackLoop)
        {
            //Each amplifier should run its own code


            int[] samePositions = new int[10];

            for (int x = 0; x < phaseSettings.Length; ++x)
            {
                samePositions[phaseSettings[x]] += 1;
            }

            if (samePositions.Where(x => x > 1).Count() != 0)
            {
                return(0);
            }


            ICC.ICCOutput output = new ICC.ICCOutput
            {
                //input signal
                outputFromPhase = 0
            };

            for (int idx = 0; idx < phaseSettings.Length; ++idx)
            {
                amps[idx].Reset();
                amps[idx].icc.ResetMemory();


                //amps[idx].input.Enqueue(amps[idx-1].output)
            }
            amps[0].input.Enqueue(0);
            for (int idx = 0; idx < phaseSettings.Length; ++idx)
            {
                amps[idx].input.Enqueue(phaseSettings[idx]);
            }


            bool anyHalt = false;

            while (!anyHalt)
            {
                foreach (var amp in amps)
                {
                    output = amp.RunAmplifier();
                    Console.WriteLine($"Phase Output {output.outputFromPhase} OpCode {output.opCodeDetected}");
                    if (output.opCodeDetected == ICC.OpCodes.halt)
                    {
                        //break;
                    }
                }
                if (!feedBackLoop)
                {
                    break;
                }
            }

            //Console.WriteLine($"{a},{b},{c},{d},{e} output of phase { output.outputFromPhase}");
            return(amps.Last().output.Single());
        }
Esempio n. 2
0
        private static Int64 RunPhase(ACS[] amps, int[] phaseSettings, bool feedBackLoop)
        {
            //Each amplifier should run its own code


            int[] samePositions = new int[10];

            for (int x = 0; x < phaseSettings.Length; ++x)
            {
                samePositions[phaseSettings[x]] += 1;
            }

            if (samePositions.Where(x => x > 1).Count() != 0)
            {
                return(0);
            }


            ICC.ICCOutput output = new ICC.ICCOutput
            {
                //input signal
                outputFromPhase = 0
            };

            for (int idx = 0; idx < phaseSettings.Length; ++idx)
            {
                amps[idx].Reset();
                amps[idx].icc.ResetMemory();


                //amps[idx].input.Enqueue(amps[idx-1].output)
            }

            for (int idx = 0; idx < phaseSettings.Length; ++idx)
            {
                amps[idx].input.Enqueue(phaseSettings[idx]);
            }


            bool anyHalt = true;
            int  counter = 0;

            while (anyHalt)
            {
                foreach (var amp in amps)
                {
                    if (counter == 0)
                    {
                        amp.input.Enqueue(0);
                    }
                    amp.input.Enqueue((int)output.outputFromPhase);
                    output = amp.RunAmplifier();
                    ++counter;
                    if (!feedBackLoop)
                    {
                        anyHalt = false;
                        break;
                    }
                    counter++;
                }
            }

            //for (int idx = 0; idx < phaseSettings.Length; ++idx)
            //{
            //    amp.input.Enqueue(phaseSettings[idx]);
            //    if (idx == 0)
            //    {
            //        amp.input.Enqueue(0);
            //    }
            //    else
            //    {
            //        amp.input.Enqueue((int)output.outputFromPhase);
            //    }
            //    output = amp.RunAmplifier();
            //    if (feedBackLoop)
            //    {
            //        if (output.opCodeDetected == ICC.OpCodes.halt)
            //        {
            //            anyHalt = false;
            //            break;
            //        }
            //    }
            //}



            //Console.WriteLine($"{a},{b},{c},{d},{e} output of phase { output.outputFromPhase}");
            return(output.outputFromPhase);
        }