Пример #1
0
        public void CopyFromTest()
        {
            using (var reader = File.OpenText("../../../maze.txt"))
            {
                var maze  = PlayfieldFactory.Create(reader);
                var maze1 = new Playfield(maze.Dimentions.X, maze.Dimentions.Y);
                maze1.CopyCellTypesFrom(maze);

                Assert.Equal(maze[0, 0].CellType, maze1[0, 0].CellType);
                Assert.Equal(maze[10, 10].CellType, maze1[10, 10].CellType);
            }
        }
Пример #2
0
        public void FindPath()
        {
            using (var reader = File.OpenText("../../../maze1.txt"))
            {
                var maze   = PlayfieldFactory.Create(reader);
                var result = new PathFinder(maze)
                             .From(new Vector2D(1, 1))
                             .To(new Vector2D(3, 1))
                             .FindPath();

                Assert.Equal(5, result.Path.Length);
            }
        }
Пример #3
0
        public void PlayfieldFactoryCreate()
        {
            using (var reader = File.OpenText("../../../maze.txt"))
            {
                var maze = PlayfieldFactory.Create(reader);

                for (var y = 0; y < maze.Dimentions.Y; y++)
                {
                    for (var x = 0; x < maze.Dimentions.X; x++)
                    {
                        Debug.Write(GetCellChar(maze[x, y].CellType));
                    }
                    Debug.WriteLine("");
                }
            }
        }
Пример #4
0
    static void Main(string[] args)
    {
        map  = PlayfieldFactory.Create(Console.In);
        map1 = new Playfield(map.Dimentions);

        var inputs            = Console.ReadLine().Split(' ');
        int sanityLossLonely  = int.Parse(inputs[0]); // how much sanity you lose every turn when alone, always 3 until wood 1
        int sanityLossGroup   = int.Parse(inputs[1]); // how much sanity you lose every turn when near another player, always 1 until wood 1
        int wandererSpawnTime = int.Parse(inputs[2]); // how many turns the wanderer take to spawn, always 3 until wood 1
        int wandererLifeTime  = int.Parse(inputs[3]); // how many turns the wanderer is on map after spawning, always 40 until wood 1

        var restPlan     = 2;
        var turn         = 0;
        var lastPlanTurn = 0;

        // game loop
        while (true)
        {
            turn++;

            LoadUnits();

            var closeExp = units.Skip(1).Count(x => x.UnitType == EXPLORER && x.Pos.ManhattanDistance(me.Pos) < 3);
            if (restPlan > 0 && me.Sanity < 200 && lastPlanTurn < turn - 5 && closeExp > 2)
            {
                Console.WriteLine("PLAN");
                restPlan--;
                lastPlanTurn = turn;
                continue;
            }

            Vector2D t = null;

            var shelters = units
                           .Where(x => x.UnitType == EFFECT_SHELTER && x.Param0 > 0)
                           .OrderBy(x => x.Pos.ManhattanDistance(me.Pos))
                           .ToArray();

            if (shelters.Any())
            {
                t = FindNextCell(map1, me.Pos, shelters.Select(x => x.Pos));
            }

            if (t == null)
            {
                t = Vector2D
                    .DirectionsAndMe
                    .Select(x => Vector2D.Add(me.Pos, x))
                    .Where(x => map.IsWalkable(x))
                    .OrderBy(x => CalcBadCellRank(x))
                    .FirstOrDefault();
            }

            if (t != null)
            {
                Console.WriteLine($"MOVE {t.X} {t.Y}");
            }
            else
            {
                Console.WriteLine("WAIT");
            }
        }
    }