Beispiel #1
0
 protected override LightStyle.Simulation ConstructSimulation(LightStylist stylist)
 {
     if (this.singletonSimulation == null)
     {
     }
     return(this.singletonSimulation = new DefaultSimulation(this));
 }
        /// <summary>
        /// Creates a new server listening on the specified port and allowing
        /// for the specified number of players.
        /// </summary>
        /// <param name="port">The port to listen on.</param>
        /// <param name="maxPlayers">The maximum number of players supported.</param>
        /// <param name="commandHandler">The command handler to use in the
        /// simulation.</param>
        public SimpleServerController(ushort port, int maxPlayers, CommandHandler commandHandler)
            : base(new HybridServerSession <TPlayerData>(port, maxPlayers))
        {
            var simulation = new DefaultSimulation();

            simulation.Command += commandHandler;
            Tss.Initialize(simulation);
        }
        /// <summary>
        /// Creates a new game client, ready to connect to an open game.
        /// </summary>
        /// <param name="commandHandler">The command handler to use.</param>
        public SimpleClientController(CommandHandler commandHandler)
            : base(new HybridClientSession <TPlayerData>())
        {
            var simulation = new DefaultSimulation();

            simulation.Command += commandHandler;
            Tss.Initialize(simulation);
        }
        public void Simulation_SavesDataCorrectly_WhenPassingPosition()
        {
            var positionMock = new Position(0, 0);

            var createdSimulation = new DefaultSimulation(positionMock);

            Assert.Equal(createdSimulation.plateau.boundary, positionMock);
        }
        public void Simulation_SavesDataCorrectly_WhenPassingPoints()
        {
            int x = 1;
            int y = 1;

            var createdSimulation = new DefaultSimulation(x, y);

            Assert.True(x == createdSimulation.plateau.boundary.X && y == createdSimulation.plateau.boundary.Y);
        }
        public void Simulation_AddRover_AddsRoversToList()
        {
            var simulationBoundary = new Position(1, 1);
            var createdSimulation  = new DefaultSimulation(simulationBoundary);

            var roverInitialPosition = new Position(0, 0);
            var roverInstructions    = new RoverInstruction[] { RoverInstruction.Left, RoverInstruction.Move };

            createdSimulation.AddRover(roverInitialPosition, roverInstructions);

            var(rover, currentPosition, instructionList) = createdSimulation.roverList[0];

            Assert.IsType <DefaultRover>(rover);
            Assert.Equal(currentPosition, roverInitialPosition);
            Assert.Equal(instructionList, roverInstructions);
        }
        //TODO: Find a better way to check the results of running a simulation
        public void Simulation_Runs_details_Correctly(int simIndex)
        {
            var simulationDetails = GetSimulationDetails(simIndex);

            var testSimulation = new DefaultSimulation(simulationDetails.simulationBoundary);

            foreach (var RoverEntry in simulationDetails.roverList)
            {
                testSimulation.AddRover(RoverEntry.initialPosition, RoverEntry.instructions);
            }

            var results = testSimulation.RunSimulation();

            var comparedResultList = results.Select((result, index) =>
            {
                var expectedPosition = simulationDetails.roverList[index].ExpectedFinalPosition;
                return(expectedPosition.X == result.X && expectedPosition.Y == result.Y, index);
            });

            foreach (var(resultValue, index) in comparedResultList)
            {
                Assert.True(resultValue, $"There was an issue with Simulation no. {simIndex}. On rover {index}");
            }
        }