Exemple #1
0
 private void PopulateFieldsWithFood(int amount)
 {
     for (int i = 0; i < amount; ++i)
     {
         Food food = Foods.GetRandomFood();
         GetRandomEmptyField().SetContent(Field.CONTENT.Food, food.Sprite, food.Value, food.Predicted);
     }
 }
Exemple #2
0
        public static BoardInput CreateBoard(Field[][] fields)
        {
            string dimensions = (Config.FIELD_ROWS_AMOUNT).ToString() + " " + (Config.FIELD_COLUMNS_AMOUNT).ToString();
            string walls      = Config.WALLS_AMOUNT.ToString();
            string foods      = Config.FIELDS_WITH_FOOD_AMOUNT.ToString();
            string coins      = Config.FIELDS_WITH_COINS_AMOUNT.ToString();

            File.WriteAllText(".\\config.txt", dimensions.Trim() + " " + walls.Trim() + " " + foods.Trim() + " " + coins.Trim());

            var proc = new Process();

            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.FileName  = "node";
            proc.StartInfo.Arguments = Config.PATH_BOARD_GENERATION + "\\index.js";

            proc.Start();
            string output = proc.StandardOutput.ReadToEnd().Trim();

            proc.WaitForExit();

            string[] outputLines = output.Split('\n');

            int[]             outputAgent      = outputLines[0].Split(' ').Select((input) => Int32.Parse(input)).ToArray();
            Agent.ORIENTATION agentOrientation = outputLines[1] == "polnoc"
                ? Agent.ORIENTATION.North
                : outputLines[1] == "poludnie"
                ? Agent.ORIENTATION.South
                : outputLines[1] == "wschod"
                ? Agent.ORIENTATION.East
                : Agent.ORIENTATION.West;
            Agent agent;
            int   agentX = outputAgent[0] % 2 == 0 ? outputAgent[0] / 2 : (outputAgent[0] - 1) / 2;
            int   agentY = outputAgent[1] % 2 == 0 ? outputAgent[1] / 2 : (outputAgent[1] - 1) / 2;

            agent = new Agent(fields[agentX][agentY], agentOrientation);

            int[] outputFoods = outputLines[3].Split(' ').Select((input) => Int32.Parse(input)).ToArray();
            for (int i = 0; i < outputFoods.Length; i += 2)
            {
                int  foodX = outputFoods[i] % 2 == 0 ? outputFoods[i] / 2 : (outputFoods[i] - 1) / 2;
                int  foodY = outputFoods[i + 1] % 2 == 0 ? outputFoods[i + 1] / 2 : (outputFoods[i + 1] - 1) / 2;
                Food food  = Foods.GetRandomFood();
                fields[foodX][foodY].SetContent(Field.CONTENT.Food, food.Sprite, food.Value, food.Predicted);
            }

            int[]  outputCoins = outputLines[4].Split(' ').Select((input) => Int32.Parse(input)).ToArray();
            Coin[] coinObjects = Coins.GetRandomCoins(outputCoins.Length / 2);
            for (int i = 0; i < outputCoins.Length; i += 2)
            {
                int  coinX = outputCoins[i] % 2 == 0 ? outputCoins[i] / 2 : (outputCoins[i] - 1) / 2;
                int  coinY = outputCoins[i + 1] % 2 == 0 ? outputCoins[i + 1] / 2 : (outputCoins[i + 1] - 1) / 2;
                Coin coin  = coinObjects[i / 2];
                fields[coinX][coinY].SetContent(Field.CONTENT.Coins, coin.Sprite, coin.Value, coin.Predicted);
            }

            List <Wall> wallsResult = new List <Wall>();

            int[] outputObstacles = outputLines[2].Split(' ').Select((input) => Int32.Parse(input)).ToArray();
            for (int i = 0; i < outputObstacles.Length; i += 2)
            {
                if (!(outputObstacles[i] % 2 == 1 && outputObstacles[i + 1] % 2 == 1))
                {
                    if (outputObstacles[i] % 2 == 0)
                    {
                        int x = outputObstacles[i] / 2;
                        int y = (outputObstacles[i + 1] - 1) / 2;
                        wallsResult.Add(new Wall(fields[x][y], fields[x][y + 1]));
                    }
                    else
                    {
                        int x = (outputObstacles[i] - 1) / 2;
                        int y = outputObstacles[i + 1] / 2;
                        wallsResult.Add(new Wall(fields[x][y], fields[x + 1][y]));
                    }
                }
            }

            return(new BoardInput(wallsResult, agent));
        }