Exemplo n.º 1
0
        /// <summary>
        /// Run the simulations and save result to ViewState and JS script block
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRunSimulations_OnClick(object sender, EventArgs e)
        {
            var deck = new Deck();
            List<int> position = Request.Form["robotPosition"].Split(',').Select(int.Parse).ToList();
            var cards = Request.Form["cards"].Split(',').Select(x => GetCardPriority(deck, x));

            var robot = new Robot
            {
                Position = new Coordinate {X = position[0], Y = position[1]},
                Facing = (Orientation)Enum.Parse(typeof(Orientation), Request.Form["robotOrientation"])
            };

            foreach (var priority in cards)
            {
                robot.DealCard(priority);
            }

            var map = MapParser.JsonToMap(LoadMapJson("~/Maps/ScottRallyMap.rrdl"));

            var game = new Game(new Map {Squares = map}, new List<Robot> {robot});
            game.Initialize();

            List<List<CardExecutionResult>> results = Simulator.Simulate(robot);
            List<List<CardExecutionResult>> productiveResults = results.Where(result => result.Last().Position.X != -1).ToList();

            ViewState["PosX"] = position[0];
            ViewState["PosY"] = position[1];
            ViewState["Facing"] = Request.Form["robotOrientation"];
            ViewState["Cards"] = Request.Form["cards"];

            ClientScript.RegisterClientScriptBlock(GetType(), "results", "results = " + JsonConvert.SerializeObject(productiveResults, Formatting.Indented), true);
        }
Exemplo n.º 2
0
        protected void btnRunSimulations_OnClick(object sender, EventArgs e)
        {
            List<int> position = Request.Form["robotPosition"].Split(',').Select(int.Parse).ToList();
            var cards = Request.Form["cards"].Split(',').Select(int.Parse);

            var robot = new Robot
            {
                Position = new Coordinate {X = position[0], Y = position[1]},
                Facing = (Orientation)Enum.Parse(typeof(Orientation), Request.Form["robotOrientation"])
            };
            foreach (var c in cards)
            {
                robot.DealCard(c);
            }

            var game = new Game { Board = { Squares = Maps.GetMap(Maps.MapLayouts.ScottRallyMap) }, Robots = new List<Robot> { robot } };
            game.Initialize();

            List<List<CardExecutionResult>> results = Simulator.RunSimulations(robot);
            List<List<CardExecutionResult>> productiveResults = results.Where(result => result.Last().Position.X != -1).ToList();

            ViewState["PosX"] = position[0];
            ViewState["PosY"] = position[1];
            ViewState["Facing"] = Request.Form["robotOrientation"];
            ViewState["Cards"] = Request.Form["cards"];

            ClientScript.RegisterClientScriptBlock(GetType(), "results", "results = " + JsonConvert.SerializeObject(productiveResults, Formatting.Indented), true);
        }
Exemplo n.º 3
0
        public static string RunSimulations(string body)
        {
            JToken json = JToken.Parse(body);

            var deck = new Deck();
            IEnumerable<int> cards = json["cards"].ToString().Split(',').Select(x => GetCardPriority(deck, x));
            List<int> robotPosition = json["robotPosition"].ToString().Split(',').Select(int.Parse).ToList();
            string robotOrientation = json["robotOrientation"].ToString();

            var robot = new Robot
            {
                Position = new Coordinate { X = robotPosition[0], Y = robotPosition[1] },
                Facing = (Orientation)Enum.Parse(typeof(Orientation), robotOrientation)
            };

            foreach (var priority in cards)
            {
                robot.DealCard(priority);
            }

            var map = MapParser.JsonToMap(LoadMapJson(ActiveMap));

            var game = new Game(new Map { Squares = map }, new List<Robot> { robot });
            game.Initialize();

            List<List<CardExecutionResult>> results = Simulator.Simulate(robot);
            List<List<CardExecutionResult>> productiveResults = results.Where(result => result.Last().Position.X != -1).ToList();

            return JsonConvert.SerializeObject(productiveResults, Formatting.Indented);
        }
Exemplo n.º 4
0
        public override void Execute(Game game, TileExecution execution)
        {
            if (execution == TileExecution.Conveyer)
            {
                Convey(RobotOnTile(game));
            }

            base.Execute(game, execution);
        }
Exemplo n.º 5
0
Arquivo: Floor.cs Projeto: wbish/wirk
        public virtual void Execute(Game game, TileExecution execution)
        {
            if (execution == TileExecution.Lasers)
            {
                // TODO: FIRE ZE MISILES!
            }

            if (execution == TileExecution.Pushers)
            {
                // TODO: ACTIVATE PUSHERS
            }
        }
Exemplo n.º 6
0
 public void Initialize(Game game)
 {
     Game = game;
 }
Exemplo n.º 7
0
        public void Simulator_RunSimulations_7Cards2TypeRepeatedTwice()
        {
            // Arrange
            var robot = new Robot();
            robot.DealCard(10);		// UTurn
            robot.DealCard(20);		// UTurn
            robot.DealCard(70);		// RotateLeft
            robot.DealCard(80);		// RotateRight
            robot.DealCard(430);	// BackUp
            robot.DealCard(490);	// Move1
            robot.DealCard(500);	// Move1
            var game = new Game(new Map {Squares = Maps.GetMap(Maps.MapLayouts.ScottRallyMap)}, new List<Robot> {robot});
            game.Initialize();

            // Act
            List<List<CardExecutionResult>> results = Simulator.Simulate(robot);

            // Assert
            Assert.AreEqual(690, results.Count);
        }
Exemplo n.º 8
0
Arquivo: Floor.cs Projeto: wbish/wirk
 protected Robot RobotOnTile(Game game)
 {
     Coordinate pos = game.Board.Position(this);
     return game.RobotAt(pos);
 }