Exemplo n.º 1
0
        public static int multiplyOutputs()
        {
            List <outputObject> botsOutput = new List <outputObject>();

            foreach (BotObject bot in bots)
            {
                if (bot.outputLow || bot.outputHigh)
                {
                    outputObject tmpBotsOutput = new outputObject();

                    if (bot.outputLow)
                    {
                        tmpBotsOutput.id    = bot.lowValueToId;
                        tmpBotsOutput.value = bot.valueCollection.Min();
                    }
                    else if (bot.outputHigh)
                    {
                        tmpBotsOutput.id    = bot.highValueToId;
                        tmpBotsOutput.value = bot.valueCollection.Max();
                    }

                    botsOutput.Add(tmpBotsOutput);
                }
            }

            int multipliedAnswer = 1;

            foreach (outputObject output in botsOutput)
            {
                if (output.id == 0 || output.id == 1 || output.id == 2)
                {
                    multipliedAnswer *= output.value;
                }
            }

            return(multipliedAnswer);
        }
Exemplo n.º 2
0
        public void Convert(Stream input, ReadOnlyCollection<RecognizedSegment> results)
        {
            outputObject resultsRenderer = new outputObject();
            List<RecognizedSegment> sortedOutput = orderAllResults(results);

            const int overlapThreshold = 1;
            const int spaceWidth = 7; //The amount of pixels in a space

            lastSegmentRendered lastSeg = new lastSegmentRendered();
            lastSeg.endingXValue = columnStart;
            lastSeg.startingXValue = columnStart;

            writerPosition position = writerPosition.firstSeg;

            for (int i = 0; i < sortedOutput.Count; i++) {
                //Test for new line
                if (lastSeg.TestForNewLine(sortedOutput[i], position)) {
                    //New line determined
                    resultsRenderer.AddOutput(Environment.NewLine);
                    lastSeg.AdjustLastSegValues(sortedOutput[i]);
                    position = writerPosition.newLine;
                }
                else {
                    //Not a new line
                    if (position == writerPosition.sameLine &&
                        //check that the segment isn't wholly subsumed in the last
                        !(sortedOutput[i].Bounds.X >= lastSeg.startingXValue
                                && sortedOutput[i].Bounds.Right <= lastSeg.endingXValue)
                        ) {
                        //Add spaces
                        int numberOfSpaces = (sortedOutput[i].Bounds.X - lastSeg.endingXValue) / spaceWidth;
                        for (int j = 0; j < numberOfSpaces; j++) {
                            resultsRenderer.AddOutput(" ");
                        }
                        string segToResolve = sortedOutput[i].Text;
                        string segToRender = string.Empty;
                        //Remove segments from the previous renderings list
                        lastSeg.RemoveOldRenderedString(sortedOutput[i]);
                        //Check for some degree of overlap
                        if (lastSeg.endingXValue - sortedOutput[i].Bounds.X > overlapThreshold) {
                            //Check if some characters can be removed from segToResolve
                            string storedPrevRenderings = string.Empty;
                            foreach (string s in lastSeg.renderingsAndEndIdx.Select(k => k.Item1)) {
                                storedPrevRenderings += s;
                            }
                            for (int j = 0; j < segToResolve.ToCharArray().Count(); j++) {
                                if (!storedPrevRenderings.Contains(segToResolve[j])) {
                                    segToRender += segToResolve[j];
                                } else {
                                    int idx = storedPrevRenderings.IndexOf(segToResolve[j]);
                                    storedPrevRenderings = storedPrevRenderings.Remove(idx, 1);
                                }
                            }
                            lastSeg.renderingsAndEndIdx.Add(new Tuple<string, int>(segToRender, sortedOutput[i].Bounds.Right));
                            resultsRenderer.AddOutput(segToRender);
                            lastSeg.AdjustLastSegValues(sortedOutput[i]);
                        } else {
                            //No overlap. Clear list of previous rendrings
                            lastSeg.ResetListOfPreviousRenderings();
                            lastSeg.renderingsAndEndIdx.Add(new Tuple<string, int>(sortedOutput[i].Text, sortedOutput[i].Bounds.Right));
                            resultsRenderer.AddOutput(sortedOutput[i].Text);
                            lastSeg.AdjustLastSegValues(sortedOutput[i]);
                        }
                    }
                    if (position == writerPosition.firstSeg || position == writerPosition.newLine) {
                        //New line. Render without checking for spaces
                        lastSeg.ResetListOfPreviousRenderings();
                        lastSeg.renderingsAndEndIdx.Add(new Tuple<string, int>(sortedOutput[i].Text, sortedOutput[i].Bounds.Right));
                        resultsRenderer.AddOutput(sortedOutput[i].Text);
                        lastSeg.AdjustLastSegValues(sortedOutput[i]);
                        position = writerPosition.sameLine;
                    }
                }
            }
            resultsRenderer.PrintStoredOutput();
        }