Пример #1
0
        public void ExecuteTest_MapWithWalls_ActorAvoidWalls()
        {
            // ARRANGE

            var map = new TestGridGenWallMap();

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();


                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #2
0
        public async System.Threading.Tasks.Task ExecuteTest_MapWithWalls_ActorAvoidWallsAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10);

            map.RemoveEdge(3, 3, 3, 4);
            map.RemoveEdge(3, 3, 2, 3);

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();


                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #3
0
        public async System.Threading.Tasks.Task ExecuteTest_FindingPathAndMove_IsCompleteTrueAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10);

            var expectedPath = new IMapNode[] {
                map.Nodes.Cast <HexNode>().SelectBy(4, 4),
                map.Nodes.Cast <HexNode>().SelectBy(3, 4),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                map.Nodes.Cast <HexNode>().SelectBy(1, 5),
            };

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();


            var actor = CreateActor(map, (HexNode)startNode);

            var task = new MoveTask(actor, finishNode, map);



            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();
            }



            // ASSERT
            task.IsComplete.Should().BeTrue();
        }
Пример #4
0
        public async Task ExecuteTest_MapWithWalls_ActorAvoidWallsAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10).ConfigureAwait(false);

            map.RemoveEdge(3, 3, 3, 4);
            map.RemoveEdge(3, 3, 2, 3);

            var expectedPath = CreateExpectedPath(map);

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();

            var actor = CreateActor(map, (HexNode)startNode);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new MoveTask(actor, context, finishNode, map);

            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();

                // ASSERT
                actor.Node.Should().Be(expectedPath[step]);
            }
        }
Пример #5
0
        public async Task ExecuteTest_FindingPathAndMove_IsCompleteTrueAsync()
        {
            // ARRANGE

            var map = await SquareMapFactory.CreateAsync(10).ConfigureAwait(false);

            var expectedPath = CreateExpectedPath(map);

            var startNode  = expectedPath.First();
            var finishNode = expectedPath.Last();

            var actor = CreateActor(map, (HexNode)startNode);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new MoveTask(actor, context, finishNode, map);

            // ACT
            for (var step = 1; step < expectedPath.Length; step++)
            {
                task.Execute();
            }

            // ASSERT
            task.IsComplete.Should().BeTrue();
        }
Пример #6
0
        public void ExecuteTest_OpenGridMap_ActorReachPointAndTaskComplete()
        {
            // ARRANGE
            var map = new TestGridGenMap();

            var startNode  = map.Nodes.Cast <HexNode>().SelectBy(3, 3);
            var finishNode = map.Nodes.Cast <HexNode>().SelectBy(1, 5);

            var expectedPath = new[] {
                map.Nodes.Cast <HexNode>().SelectBy(2, 3),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                finishNode
            };

            var actor = CreateActor(map, startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step <= expectedPath.Count(); step++)
            {
                task.Execute();



                // ASSERT
                var expectedIsComplete = step >= 3;
                task.IsComplete.Should().Be(expectedIsComplete);


                actor.Node.Should().Be(expectedPath[step - 1]);
            }



            // ASSERT

            task.IsComplete.Should().Be(true);
            actor.Node.Should().Be(finishNode);
        }
Пример #7
0
        public async System.Threading.Tasks.Task ExecuteTest_OpenGridMap_ActorReachPointAndTaskCompleteAsync()
        {
            // ARRANGE
            var map = await SquareMapFactory.CreateAsync(10);

            var startNode  = map.Nodes.Cast <HexNode>().SelectBy(3, 3);
            var finishNode = map.Nodes.Cast <HexNode>().SelectBy(1, 5);

            var expectedPath = new[] {
                map.Nodes.Cast <HexNode>().SelectBy(2, 3),
                map.Nodes.Cast <HexNode>().SelectBy(2, 4),
                finishNode
            };

            var actor = CreateActor(map, startNode);

            var task = new MoveTask(actor, finishNode, map);


            // ACT
            for (var step = 1; step <= expectedPath.Length; step++)
            {
                task.Execute();



                // ASSERT
                var expectedIsComplete = step >= 3;
                task.IsComplete.Should().Be(expectedIsComplete);


                actor.Node.Should().Be(expectedPath[step - 1]);
            }



            // ASSERT

            task.IsComplete.Should().Be(true);
            actor.Node.Should().Be(finishNode);
        }
Пример #8
0
        public async Task ExecuteTest_OpenGridMap_ActorReachPointAndTaskCompleteAsync()
        {
            // ARRANGE
            var map = await SquareMapFactory.CreateAsync(10).ConfigureAwait(false);

            var startNode  = map.Nodes.SelectByHexCoords(3, 3);
            var finishNode = map.Nodes.SelectByHexCoords(1, 5);

            var expectedPath = new[]
            {
                map.Nodes.SelectByHexCoords(2, 3),
                map.Nodes.SelectByHexCoords(2, 4),
                finishNode
            };

            var actor = CreateActor(map, startNode);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new MoveTask(actor, context, finishNode, map);

            // ACT
            for (var step = 1; step <= expectedPath.Length; step++)
            {
                task.Execute();

                // ASSERT
                var expectedIsComplete = step >= 3;
                task.IsComplete.Should().Be(expectedIsComplete);

                actor.Node.Should().Be(expectedPath[step - 1]);
            }

            // ASSERT

            task.IsComplete.Should().Be(true);
            actor.Node.Should().Be(finishNode);
        }
Пример #9
0
        /// <summary>
        /// Executes behavior with given context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override BehaviorReturnCode Behave(IBehaviorContext context)
        {
            UnitBehaviorContext unitContext = context as UnitBehaviorContext;

            if (unitContext == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveableUnit unit = unitContext.Unit as MoveableUnit;

            if (unit == null || !unit.CanMove || unit.SelectedPath == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            MoveTask task = new MoveTask(unit);

            while (!task.IsTurnProcessFinished && !task.IsTaskFinished)
            {
                task.Execute();
            }

            unit.SelectedPath = null;
            if (task.IsTurnProcessFinished)
            {
                returnCode = BehaviorReturnCode.Running;
            }

            if (task.IsTaskFinished)
            {
                returnCode = BehaviorReturnCode.Success;
            }

            return(returnCode);
        }