Ejemplo n.º 1
0
        public void Experience(FieldOfVisionTypes fieldOfVisionType, PuzzleBoard partialBoard)
        {
            Point centerPos = new Point();

            switch (fieldOfVisionType)
            {
            case FieldOfVisionTypes.Single:
                centerPos = new Point(0, 0);
                break;

            case FieldOfVisionTypes.ThreeByThree:
                centerPos = new Point(1, 1);
                break;

            case FieldOfVisionTypes.FiveByFive:
                centerPos = new Point(2, 2);
                break;
            }

            List <ISensoryPattern> sensoryPatterns = new List <ISensoryPattern>();

            for (int y = 0; y < partialBoard.Rows; y++)
            {
                for (int x = 0; x < partialBoard.Columns; x++)
                {
                    Point                pos           = new Point(x, y);
                    DirectionTypes       directionType = PuzzleReferee.ConvertToDirectionType(new Point(pos.X - centerPos.X, pos.Y - centerPos.Y));
                    PuzzleCellStateTypes state         = partialBoard.GetState(pos);
                    int    value       = partialBoard.GetValue(pos);
                    string valueString = value >= 0 ? value.ToString() : " ";

                    if (state != PuzzleCellStateTypes.Undefined)
                    {
                        ISensoryUnit sensoryUnitState = GetOrCreateSensoryUnit(SensoryTypes.FieldState, state.ToString());
                        ISensoryUnit sensoryUnitValue = GetOrCreateSensoryUnit(SensoryTypes.FieldValue, valueString);

                        List <ISensoryUnit> sensoryUnits = new List <ISensoryUnit>();
                        sensoryUnits.Add(sensoryUnitState);
                        sensoryUnits.Add(sensoryUnitValue);

                        ISensoryPattern sensoryPattern = new SensoryPattern(directionType, sensoryUnits);

                        if (_kownSensoryPatterns.Contains(sensoryPattern))
                        {
                            sensoryPattern = _kownSensoryPatterns[_kownSensoryPatterns.IndexOf(sensoryPattern)];
                        }
                        else
                        {
                            _kownSensoryPatterns.Add(sensoryPattern);
                            _kownSensoryPatterns.Sort();
                        }

                        sensoryPatterns.Add(sensoryPattern);
                    }
                }
            }
            _lastSensationSnapshot = new SensationSnapshot(DirectionTypes.Center, fieldOfVisionType, sensoryPatterns, IS_SAVEABLE_SNAPSHOT);
        }
Ejemplo n.º 2
0
        private List <ISensoryPattern> SplitPattern(ISensationSnapshot snapShot, int unitSize)
        {
            var result = new List <ISensoryPattern>();

            foreach (var pattern in snapShot.SensoryPatterns)
            {
                foreach (var splittedPattern in SensoryPattern.Split(pattern))
                {
                    if (splittedPattern.SensoryUnits.Count == unitSize && !result.Contains(splittedPattern))
                    {
                        result.Add(splittedPattern);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
 static public ISensationSnapshot ExtractSnapshot(ISensationSnapshot sensationSnapshot, FieldOfVisionTypes fieldOfVision, DirectionTypes direction)
 {
     if (fieldOfVision == FieldOfVisionTypes.Single)
     {
         Point centerPos      = PuzzleReferee.ConvertToPoint(direction);
         var   resultPatterns = new List <ISensoryPattern>();
         foreach (ISensoryPattern pattern in sensationSnapshot.SensoryPatterns)
         {
             if (direction.Equals(pattern.DirectionType))
             {
                 var   newPattern    = new SensoryPattern(pattern);
                 Point oldPatternPos = PuzzleReferee.ConvertToPoint(newPattern.DirectionType);
                 var   newPatternPos = new Point(oldPatternPos.X - centerPos.X, oldPatternPos.Y - centerPos.Y);
                 newPattern.DirectionType = PuzzleReferee.ConvertToDirectionType(newPatternPos);
                 resultPatterns.Add(newPattern);
             }
         }
         return(new SensationSnapshot(PuzzleReferee.ConvertToDirectionType(centerPos), FieldOfVisionTypes.Single, resultPatterns, false));
     }
     else if (fieldOfVision == FieldOfVisionTypes.ThreeByThree)
     {
         Point centerPos = PuzzleReferee.ConvertToPoint(direction);
         List <DirectionTypes> fieldOfVisionDirections = new List <DirectionTypes>();
         for (int sy = -1; sy < 2; sy++)
         {
             for (int sx = -1; sx < 2; sx++)
             {
                 fieldOfVisionDirections.Add(PuzzleReferee.ConvertToDirectionType(new Point(sx + centerPos.X, sy + centerPos.Y)));
             }
         }
         var resultPatterns = new List <ISensoryPattern>();
         foreach (ISensoryPattern pattern in sensationSnapshot.SensoryPatterns)
         {
             if (fieldOfVisionDirections.Contains(pattern.DirectionType))
             {
                 var   newPattern    = new SensoryPattern(pattern);
                 Point oldPatternPos = PuzzleReferee.ConvertToPoint(newPattern.DirectionType);
                 var   newPatternPos = new Point(oldPatternPos.X - centerPos.X, oldPatternPos.Y - centerPos.Y);
                 newPattern.DirectionType = PuzzleReferee.ConvertToDirectionType(newPatternPos);
                 resultPatterns.Add(newPattern);
             }
         }
         return(new SensationSnapshot(PuzzleReferee.ConvertToDirectionType(centerPos), FieldOfVisionTypes.ThreeByThree, resultPatterns, false));
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
        public bool EqualsSensoryUnits(SensoryPattern sensoryPattern)
        {
            if (sensoryPattern == null)
            {
                return(false);
            }
            if (SensoryUnits.Count != sensoryPattern.SensoryUnits.Count)
            {
                return(false);
            }

            foreach (var sensoryUnit in SensoryUnits)
            {
                if (!sensoryPattern.SensoryUnits.Contains(sensoryUnit))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        static private List <ISensoryPattern> Split(DirectionTypes directionType, int level, List <ISensoryUnit> sensoryUnits)
        {
            List <ISensoryPattern> result = new List <ISensoryPattern>();

            if (level == 1)
            {
                foreach (ISensoryUnit leftUnit in sensoryUnits)
                {
                    var splittedSensoryUnits = new List <ISensoryUnit>();
                    splittedSensoryUnits.Add(leftUnit);
                    ISensoryPattern newEntry = new SensoryPattern(directionType, splittedSensoryUnits);
                    result.Add(newEntry);
                }
            }
            else if (level >= 2)
            {
                var reducedSensoryUnits = new List <ISensoryUnit>();
                reducedSensoryUnits.AddRange(sensoryUnits);

                foreach (ISensoryUnit leftUnit in sensoryUnits)
                {
                    if (reducedSensoryUnits.Count < level)
                    {
                        break;
                    }
                    reducedSensoryUnits.RemoveAt(0);
                    var testPattern = Split(directionType, level - 1, reducedSensoryUnits);
                    foreach (var rightPattern in testPattern)
                    {
                        var splittedSensoryUnits = new List <ISensoryUnit>();
                        splittedSensoryUnits.Add(leftUnit);
                        splittedSensoryUnits.AddRange(rightPattern.SensoryUnits);
                        ISensoryPattern newEntry = new SensoryPattern(directionType, splittedSensoryUnits);
                        result.Add(newEntry);
                    }
                }
            }

            return(result);
        }