Esempio n. 1
0
 public List<int> GetUnknownFieldIds(Field field)
 {
     var returnList = new List<int>();
     foreach (var id in field.Neighbours)
     {
         if (GameboardFields[id].FieldType == FieldType.Unknown)
         {
             returnList[returnList.Count()] = id;
         }
     }
     return returnList;
 }
Esempio n. 2
0
 public int GetOverLapsBetweenFields(Field current, Field neighbour)
 {
     int overlap = 0;
     foreach (var field in current.Neighbours)
     {
         foreach (var nField in neighbour.Neighbours)
         {
             if (field == nField)
             {
                 overlap++;
             }
         }
     }
     return overlap;
 }
Esempio n. 3
0
 public void NextMove(Field field)
 {
     if (GetMines(field) == field.Value) //if the field already has the correct number of mines
     {
         SetNumbered(field); //all remaining unNumbered fields are not mines
         //TODO: Set this field to inactive, and if new fields appear update these aswell
         return;
     }
     if (GetUnknown(field) + GetMines(field) == field.Value)
     {
         SetMine(field); //all remaining unNumbered fields are mines
         //TODO: set this field to inactive
         return;
     }
     //Consider only running this after none of the other options can solve anymore since its PRETTY HEAVY.
     if (2 < 1)
     {
         TwoPointLogic(field);
     }
 }
Esempio n. 4
0
 //How many of my neighbours do i know are Unknown
 public int GetUnknown(Field field)
 {
     return field.Neighbours.Count(id => GameboardFields[id].FieldType == FieldType.Unknown);
 }
Esempio n. 5
0
 //How many of my neighbours do i know are Numbered
 public int GetNumbered(Field field)
 {
     return field.Neighbours.Count(id => GameboardFields[id].FieldType == FieldType.Numbered);
 }
Esempio n. 6
0
 //How many of my neighbours do i know are mines
 public int GetMines(Field field)
 {
     return field.Neighbours.Count(id => GameboardFields[id].FieldType == FieldType.Mine);
 }
Esempio n. 7
0
        public void TwoPointLogic(Field field)
        {
            var missingMines = field.Value - GetMines(field);
            var unknownFields = GetUnknownFieldIds(field);
            List<List<int>> combinations = PermutationsOf(unknownFields, missingMines);
            var solutions = new List<List<int>>();
            foreach (var combination in combinations)
            {
                bool isSolution = true;
                foreach (var nField in field.Neighbours)
                {
                    //TODO: Kig på om kombinationen opfylder naboernes krav
                    //1. Naboerne må aldrig tildeles flere miner end deres værdi
                    //2. Naboerne skal have unknowns tilbage efter at en løsning er blevet valgt hvor deres værdi ikke fuldt er nået.
                    if (field.Value - GetMines(field) < FieldsIncluded(combination, nField) || FieldsIncluded(combination, nField) > 0)
                    {//not a valid solution
                        isSolution = false;
                        break;
                    }
                }
                if (isSolution)
                {
                    solutions.Add(combination);
                }
            }

            if (solutions.Count != 0)
            {
                var comparisonMap = new Dictionary<int, int>();
                foreach (var neighbour in field.Neighbours)
                {
                    comparisonMap[neighbour] = 0;
                }
                foreach (var candidate in solutions)
                {
                    foreach (var id in field.Neighbours)
                    {
                        if (candidate.Contains(field.Neighbours[id]))
                        {
                            comparisonMap[id] = comparisonMap[id] + 1;
                        }
                    }
                }
                foreach (var id in field.Neighbours)
                {
                    if (comparisonMap[id] == 0)
                    {
                        SetNumbered(GameboardFields[id]);
                    }
                    if (comparisonMap[id] == solutions.Count)
                    {
                        SetMine(GameboardFields[id]);
                    }
                }
            }
        }
Esempio n. 8
0
 //Sets all neighbours of 'field' to be Numbered
 public void SetNumbered(Field field)
 {
     foreach (var id in field.Neighbours.Where(id => GameboardFields[id].FieldType == FieldType.Unknown))
     {
         GameboardFields[id].FieldType = FieldType.Numbered;
         //update Value from screen
     }
     //GameboardFields[field.Id].IsActive = false;
 }
Esempio n. 9
0
 //Sets all neighbours of 'field' to be mines
 public void SetMine(Field field)
 {
     foreach (var id in field.Neighbours.Where(id => GameboardFields[id].FieldType == FieldType.Unknown))
     {
         GameboardFields[id].FieldType = FieldType.Mine;
     }
     //GameboardFields[field.Id].IsActive = false;
 }