Exemple #1
0
        public static int[,] NavigateCost(rootPlayer player, string[] map)
        {
            int[,] mapCost = new int[MapRows, MapColumns];
            int currentRow = 0;
            int currentCol = 0;

            foreach (var s in map)
            {
                foreach (var c in s.ToCharArray())
                {
                    mapCost[currentRow, currentCol] = GetTileCost(player, c.ToString());
                    currentCol++;
                }

                currentCol = 0;
                currentRow++;
            }

            return(mapCost);
        }
Exemple #2
0
        public static int[,] minCost(int[,] costPaths, int m, int n, rootPlayer player)
        {
            TravelPathsDictionary = new Dictionary <int, int>();
            int i, j;

            int[,] totalCost = new int[m, n];
            totalCost[0, 0]  = costPaths[0, 0];

            for (i = 1; i < m; i++)
            {
                totalCost[i, 0] = totalCost[i - 1, 0] + costPaths[i, 0];
            }

            for (j = 1; j < n; j++)
            {
                totalCost[0, j] = totalCost[0, j - 1] + costPaths[0, j];
            }

            for (i = 1; i < m; i++)
            {
                for (j = 1; j < n; j++)
                {
                    Console.WriteLine($"Evaluating 3 Positions 1:{totalCost[i - 1, j - 1]} , 2:{totalCost[i - 1, j]} , 3:{totalCost[i, j - 1]}");
                    var i1 = Math.Min(totalCost[i - 1, j], totalCost[i, j - 1]);
                    //MinofThree(
                    //    totalCost[i - 1, j - 1],
                    //    totalCost[i - 1, j],
                    //    totalCost[i, j - 1]);
                    var curPos    = costPaths[i, j];
                    var finalCost = i1 + curPos;
                    Console.WriteLine($"Going to {i1}, totalCost {finalCost}");
                    totalCost[i, j] = finalCost;

                    // Console.Write($"{i},{j} => {totalCost[i, j]}");
                }
            }

            var ret = totalCost[m - 1, n - 1];

            return(totalCost);
        }
Exemple #3
0
        public static int GetTileCost(rootPlayer player, string s)
        {
            if (s.Equals("*"))
            {
                return(0);
            }
            foreach (var rootPlayerTile in player.tile)
            {
                if (rootPlayerTile.terrain.Equals(s))
                {
                    if (Int32.TryParse(rootPlayerTile.cost, out var cost))
                    {
                        return(cost);
                    }
                }
            }

            return(1);

            throw new ArgumentException("Tile not found for player");
        }