コード例 #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);
        }
コード例 #2
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();
 }
コード例 #3
0
        static public List <IPartialSnapshotCompression> NewInstancesOfMultiUnitCountTreeCompression(Dictionary <ISensoryUnit, int> unitCountDictonary, ISensationSnapshot partialSnapshot, ISensationSnapshot snapShot, FieldOfVisionTypes fieldOfVision, DirectionTypes direction)
        {
            var result = new List <IPartialSnapshotCompression>();

            // Find 2-7 if 2-7 fields around are marked as Filled or Empty (two pattern with counted units) --> fieldOfVision.ThreeByThree
            foreach (KeyValuePair <ISensoryUnit, int> unitCountEntry in unitCountDictonary)
            {
                var patterns = partialSnapshot.SensoryPatterns.Where(p => p.SensoryUnits.Contains(unitCountEntry.Key)).ToList();
                foreach (ISensoryPattern pattern in patterns)
                {
                    ISensationSnapshot partialSnapshot2 = SensationSnapshot.ExtractSnapshot(snapShot, fieldOfVision, PuzzleReferee.Addition(direction, pattern.DirectionType));
                    var unitCountDictonary2             = SensationSnapshot.CountUnits(partialSnapshot2);
                    List <ISensoryUnit> sortedUnits     = new List <ISensoryUnit>();
                    sortedUnits.AddRange(unitCountDictonary2.Keys.ToList());
                    sortedUnits.Sort();
                    for (int i = 0; i < sortedUnits.Count - 1; i++)
                    {
                        var unitKey1   = sortedUnits[i];
                        int unitValue1 = unitCountDictonary2[unitKey1];
                        if (unitKey1.Equals(unitCountEntry.Key))
                        {
                            unitValue1--;
                            if (unitValue1 < 1)
                            {
                                // If the same unit found one time in the field of view, it must be the exact same one.
                                continue;
                            }
                        }
                        for (int j = i + 1; j < sortedUnits.Count; j++)
                        {
                            var unitKey2   = sortedUnits[j];
                            var unitValue2 = unitCountDictonary2[unitKey2];
                            if (unitKey2.Equals(unitCountEntry.Key))
                            {
                                unitValue2--;
                                if (unitValue2 < 1)
                                {
                                    // If the same unit found one time in the field of view, it must be the exact same one.
                                    continue;
                                }
                            }
                            var unitCompression = new PartialSnapshotCompression(CompressionTypes.MultiUnitCountTree, fieldOfVision, DirectionTypes.Undefined);
                            var node            = new PartialSnapshotCompressionNode(unitCountEntry.Key);

                            for (int q = 0; q < unitValue1; q++)
                            {
                                node.ChildNodes.Add(new PartialSnapshotCompressionNode(unitKey1));
                            }
                            for (int q = 0; q < unitValue2; q++)
                            {
                                node.ChildNodes.Add(new PartialSnapshotCompressionNode(unitKey2));
                            }

                            unitCompression.ChildNodes.Add(node);
                            if (!result.Contains(unitCompression))
                            {
                                result.Add(unitCompression);
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        static public List <IPartialSnapshotCompression> NewInstancesOfUnitCountTreeCompression(Dictionary <ISensoryUnit, int> unitCountDictonary, ISensationSnapshot partialSnapshot, ISensationSnapshot snapShot, FieldOfVisionTypes fieldOfVision, DirectionTypes direction)
        {
            var result = new List <IPartialSnapshotCompression>();

            // Find 2-7 if 2-7 fields around are marked as Filled or Empty (two pattern with counted units) --> fieldOfVision.ThreeByThree
            foreach (KeyValuePair <ISensoryUnit, int> unitCountEntry in unitCountDictonary)
            {
                var patterns = partialSnapshot.SensoryPatterns.Where(p => p.SensoryUnits.Contains(unitCountEntry.Key)).ToList();
                foreach (ISensoryPattern pattern in patterns)
                {
                    ISensationSnapshot partialSnapshot2 = SensationSnapshot.ExtractSnapshot(snapShot, fieldOfVision, PuzzleReferee.Addition(direction, pattern.DirectionType));
                    var unitCountDictonary2             = SensationSnapshot.CountUnits(partialSnapshot2);
                    foreach (KeyValuePair <ISensoryUnit, int> unitCountEntry2 in unitCountDictonary2)
                    {
                        if (unitCountEntry2.Key.Equals(unitCountEntry.Key) && unitCountEntry2.Value <= 1)
                        {
                            // If the same unit found one time in the field of view, it must be the exact same one.
                            continue;
                        }
                        var unitCompression = new PartialSnapshotCompression(CompressionTypes.UnitCountTree, fieldOfVision, DirectionTypes.Undefined);
                        var node            = new PartialSnapshotCompressionNode(unitCountEntry.Key);
                        for (int i = 0; i < unitCountEntry2.Value; i++)
                        {
                            node.ChildNodes.Add(new PartialSnapshotCompressionNode(unitCountEntry2.Key));
                        }
                        unitCompression.ChildNodes.Add(node);
                        if (!result.Contains(unitCompression))
                        {
                            result.Add(unitCompression);
                        }
                    }
                }
            }
            return(result);
        }