Beispiel #1
0
        public byte[] GetOptimalStep(byte[,] playField, HashSet <byte[]> CellsToCheck, int depth)
        {
            Dictionary <byte[], int> iscores = new Dictionary <byte[], int>();

            foreach (byte[] cell in CellsToCheck)
            {
                byte[,] b           = (byte[, ])playField.Clone();
                b[cell[0], cell[1]] = 1;
                int s = algorithm.Evaluate(b, cell, 1);
                iscores[cell] = s;
            }
            var items            = from i in iscores orderby i.Value descending select new { coordinates = i.Key, estimation = i.Value };
            var cellsToCheckList = items.Take(10).ToList();

            if (cellsToCheckList[0].estimation > 430000)
            {
                return(cellsToCheckList[0].coordinates);
            }
            Dictionary <byte[], int> scores = new Dictionary <byte[], int>();

            Parallel.ForEach(cellsToCheckList, cell =>
            {
                int score = algorithm.EvaluateCell((byte[, ])playField.Clone(), cell.coordinates, 1, (byte)depth);
                lock (scores)
                {
                    scores.Add(cell.coordinates, score);
                }
            });
            var item = (from entry in scores orderby entry.Value descending select entry).FirstOrDefault();

            return(item.Key);
        }
Beispiel #2
0
        public int[] GetOptimalStep(int[,] playField, List <int[]> CellsToCheck)
        {
            List <KeyValuePair <int[], int> > cellsToCheckList = algorithmMiniMax.ReduceMoves(playField, CellsToCheck);

            if (cellsToCheckList.Count == 1)
            {
                return(cellsToCheckList[0].Key);
            }
            HybridDictionary dictionary = new HybridDictionary();

            Parallel.ForEach(cellsToCheckList, element => dictionary.Add(element, algorithmMiniMax.EvaluateCell(playField, element.Key)));

            int[] coordinateNextStep = new int[2];
            int   temp = 0;

            foreach (DictionaryEntry d in dictionary)
            {
                if (Convert.ToInt32(d.Value) > temp)
                {
                    temp = Convert.ToInt32(d.Value);
                    coordinateNextStep = (int[])d.Key;
                }
            }
            return(coordinateNextStep);
        }
Beispiel #3
0
        public int[] GetOptimalStep(int[,] playField, IEnumerable <int[]> CellsToCheck)
        {
            HashSet <Tuple <int, int> > NearCellsList = Utils.FindMoves(playField);

            foreach (int[] item in CellsToCheck)
            {
                NearCellsList.Add(new Tuple <int, int>(item[0], item[1]));
            }
            List <KeyValuePair <Tuple <int, int>, int> > cellsToCheckList = algorithmMiniMax.ReduceMoves(playField, NearCellsList);

            if (cellsToCheckList.Count == 1)
            {
                Tuple <int, int> res = cellsToCheckList[0].Key;
                return(new int[] { res.Item1, res.Item2 });
            }
            HybridDictionary dictionary = new HybridDictionary();

            Parallel.ForEach(cellsToCheckList, element => dictionary.Add(element.Key, algorithmMiniMax.EvaluateCell((int[, ])playField.Clone(), element.Key)));

            int[] coordinateNextStep = new int[2] {
                cellsToCheckList[0].Key.Item1, cellsToCheckList[0].Key.Item2
            };
            int temp = int.MinValue;

            foreach (DictionaryEntry d in dictionary)
            {
                if (Convert.ToInt32(d.Value) > temp)
                {
                    temp = Convert.ToInt32(d.Value);
                    Tuple <int, int> res = (Tuple <int, int>)d.Key;
                    coordinateNextStep = new int[] { res.Item1, res.Item2 };
                }
            }
            return(coordinateNextStep);
        }