示例#1
0
 /// <summary>
 /// Execute turntable moves
 /// </summary>
 public static void executeTurnTables()
 {
     lock (gameStatus.locker)
     {
         playerSignals.Instance.showMessage("Turntables Rotating");
         // Find all bots on turntables
         Robot[] bots = gameStatus.robots.Where(r => gameStatus.gameBoard.turntables.Any(t => (t.location[0] == r.x_pos && t.location[1] == r.y_pos))).ToArray();
         foreach (Robot _bot in bots)
         {
             // Determine in which direction to rotate that bot, and craft the movement
             turntable table = gameStatus.gameBoard.turntables.Single(t => (t.location[0] == _bot.x_pos && t.location[1] == _bot.y_pos));
             moveModel movement = new moveModel
             {
                 card = new Hubs.cardModel
                 {
                     direction = table.dir,
                     cardNumber = 1,
                     priority = 1,
                     magnitude = 1
                 },
                 bot = _bot
             };
             // Rotate the robot
             moveCalculator.processMoveOrder(moveCalculator.calculateMove(movement)[0]);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Execute turntable moves
 /// </summary>
 public static void executeTurnTables()
 {
     lock (gameStatus.locker)
     {
         serviceHelpers.signals.showMessage("Turntables Rotating");
         // Find all bots on turntables
         Robot[] bots = gameStatus.robots.Where(r => gameStatus.gameBoard.turntables.Any(t => (t.location[0] == r.x_pos && t.location[1] == r.y_pos))).ToArray();
         foreach (Robot _bot in bots)
         {
             // Determine in which direction to rotate that bot, and craft the movement
             turntable table    = gameStatus.gameBoard.turntables.Single(t => (t.location[0] == _bot.x_pos && t.location[1] == _bot.y_pos));
             moveModel movement = new moveModel
             {
                 card = new cardModel
                 {
                     direction  = table.dir,
                     cardNumber = 1,
                     priority   = 1,
                     magnitude  = 1
                 },
                 bot = _bot
             };
             // Rotate the robot
             moveCalculator.processMoveOrder(moveCalculator.calculateMove(movement)[0]);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Executes all the player moves in the current register
        /// </summary>
        /// <param name="regsiter">The current register being executed</param>
        private static void executePlayerMoves(int regsiter)
        {
            List <orderModel> orders = new List <orderModel>();

            // Set the size of the register list to all the currently active players
            moveModel[] register = new moveModel[gameStatus.players.Count(p => (!p.dead && !p.shutdown))];
            // Add the cards to the register
            int reg = 0;

            for (int j = 0; j < gameStatus.players.Count; j++)
            {
                if (!gameStatus.players[j].dead && !gameStatus.players[j].shutdown)
                {
                    Player mover = gameStatus.players[j];
                    register[reg] = new moveModel {
                        card = mover.move[regsiter], bot = mover.playerRobot
                    };
                    reg++;
                }
            }
            // Sort the register by card priority
            register = register.OrderByDescending(order => order.card.priority).ToArray();
            // Resolve a move for each card
            foreach (moveModel move in register)
            {
                // Check if robot has died during the register
                if (!move.bot.controllingPlayer.dead)
                {
                    serviceHelpers.signals.displayMove(move, regsiter);
                    orders = calculateMove(move);
                    // Send each order to the appropriate robot
                    foreach (orderModel order in orders)
                    {
                        processMoveOrder(order);
                    }
                }
                if (gameStatus.botless)
                {
                    Thread.Sleep(1000);
                }
            }
        }
示例#4
0
 /// <summary>
 /// Sends the current move being executed to the players
 /// </summary>
 /// <param name="move">The move model being executed</param>
 public void displayMove(moveModel move, int register)
 {
     lock (gameStatus.locker)
     {
         string card = gameStatus.movementCards[move.card.cardNumber];
         string robot = move.bot.robotName;
         Clients.All.showMove(card, robot, register + 1);
     }
 }
示例#5
0
 /// <summary>
 /// Executes all the player moves in the current register
 /// </summary>
 /// <param name="regsiter">The current register being executed</param>
 private static void executePlayerMoves(int regsiter)
 {
     List<orderModel> orders = new List<orderModel>();
     // Set the size of the register list to all the currently active players
     moveModel[] register = new moveModel[gameStatus.players.Count(p => (!p.dead && !p.shutdown))];
     // Add the cards to the register
     int reg = 0;
     for (int j = 0; j < gameStatus.players.Count; j++)
     {
         if (!gameStatus.players[j].dead && !gameStatus.players[j].shutdown)
         {
             Player mover = gameStatus.players[j];
             register[reg] = new moveModel { card = mover.move[regsiter], bot = mover.playerRobot };
             reg++;
         }
     }
     // Sort the register by card priority
     register = register.OrderByDescending(order => order.card.priority).ToArray();
     // Resolve a move for each card
     foreach (moveModel move in register)
     {
         // Check if robot has died during the register
         if (!move.bot.controllingPlayer.dead)
         {
             playerSignals.Instance.displayMove(move, regsiter);
             orders = calculateMove(move);
             // Send each order to the appropriate robot
             foreach (orderModel order in orders)
             {
                 processMoveOrder(order);
             }
         }
         if (gameStatus.noBots)
         {
             Thread.Sleep(1000);
         }
     }
 }
示例#6
0
        /// <summary>
        /// Calculates and resolves all necessary moves for a robot and
        /// any other robots affected by the move.
        /// </summary>
        /// <param name="move">The movmeModel to resolve</param>
        /// <returns>A list of orders for robots</returns>
        public static List<orderModel> calculateMove(moveModel move)
        {
            lock (gameStatus.locker)
            {
                Random rand = new Random();
                List<orderModel> orders = new List<orderModel>();
                // Check for the kind of movement, and resolve turns here
                switch (move.card.direction)
                {
                    case ("forward"):
                        // Resolve complicated move here
                        resolveMove(move.bot, move.bot.currentDirection, move.card.magnitude, ref orders, false);
                        break;

                    case ("left"):
                        // Change the robot's oreientation to what it will be after the move
                        if (move.bot.currentDirection == Robot.orientation.NEG_Y)
                        {
                            move.bot.currentDirection = Robot.orientation.X;
                        }
                        else
                        {
                            move.bot.currentDirection++;
                        }
                        orders.Add(new orderModel { botNumber = move.bot.robotNum, move = movement.Left, magnitude = 1, outOfTurn = false });
                        break;

                    case ("right"):
                        if (move.bot.currentDirection == Robot.orientation.X)
                        {
                            move.bot.currentDirection = Robot.orientation.NEG_Y;
                        }
                        else
                        {
                            move.bot.currentDirection--;
                        }
                        orders.Add(new orderModel { botNumber = move.bot.robotNum, move = movement.Right, magnitude = 1, outOfTurn = false });
                        break;

                    case ("backup"):
                        Robot.orientation opposite = Robot.orientation.Y;
                        switch (move.bot.currentDirection)
                        {
                            case Robot.orientation.X:
                                opposite = Robot.orientation.NEG_X;
                                break;
                            case Robot.orientation.NEG_X:
                                opposite = Robot.orientation.X;
                                break;
                            case Robot.orientation.Y:
                                opposite = Robot.orientation.NEG_Y;
                                break;
                            case Robot.orientation.NEG_Y:
                                opposite = Robot.orientation.Y;
                                break;
                        }
                        resolveMove(move.bot, opposite, move.card.magnitude, ref orders, false);
                        break;

                    case ("uturn"):
                        switch (move.bot.currentDirection)
                        {
                            case Robot.orientation.X:
                                move.bot.currentDirection = Robot.orientation.NEG_X;
                                break;
                            case Robot.orientation.NEG_X:
                                move.bot.currentDirection = Robot.orientation.X;
                                break;
                            case Robot.orientation.Y:
                                move.bot.currentDirection = Robot.orientation.NEG_Y;
                                break;
                            case Robot.orientation.NEG_Y:
                                move.bot.currentDirection = Robot.orientation.Y;
                                break;
                        }
                        orders.Add(new orderModel { botNumber = move.bot.robotNum, move = (movement)rand.Next(0, 2), magnitude = 2, outOfTurn = false });
                        break;
                }
                return orders;
            }
        }
示例#7
0
        /// <summary>
        /// Calculates and resolves all necessary moves for a robot and
        /// any other robots affected by the move.
        /// </summary>
        /// <param name="move">The movmeModel to resolve</param>
        /// <returns>A list of orders for robots</returns>
        public static List <orderModel> calculateMove(moveModel move)
        {
            lock (gameStatus.locker)
            {
                Random            rand   = new Random();
                List <orderModel> orders = new List <orderModel>();
                // Check for the kind of movement, and resolve turns here
                switch (move.card.direction)
                {
                case ("forward"):
                    // Resolve complicated move here
                    resolveMove(move.bot, move.bot.currentDirection, move.card.magnitude, ref orders, false);
                    break;

                case ("left"):
                    // Change the robot's oreientation to what it will be after the move
                    if (move.bot.currentDirection == Robot.orientation.NEG_Y)
                    {
                        move.bot.currentDirection = Robot.orientation.X;
                    }
                    else
                    {
                        move.bot.currentDirection++;
                    }
                    orders.Add(new orderModel {
                        botNumber = move.bot.robotNum, move = movement.Left, magnitude = 1, outOfTurn = false
                    });
                    break;

                case ("right"):
                    if (move.bot.currentDirection == Robot.orientation.X)
                    {
                        move.bot.currentDirection = Robot.orientation.NEG_Y;
                    }
                    else
                    {
                        move.bot.currentDirection--;
                    }
                    orders.Add(new orderModel {
                        botNumber = move.bot.robotNum, move = movement.Right, magnitude = 1, outOfTurn = false
                    });
                    break;

                case ("backup"):
                    Robot.orientation opposite = Robot.orientation.Y;
                    switch (move.bot.currentDirection)
                    {
                    case Robot.orientation.X:
                        opposite = Robot.orientation.NEG_X;
                        break;

                    case Robot.orientation.NEG_X:
                        opposite = Robot.orientation.X;
                        break;

                    case Robot.orientation.Y:
                        opposite = Robot.orientation.NEG_Y;
                        break;

                    case Robot.orientation.NEG_Y:
                        opposite = Robot.orientation.Y;
                        break;
                    }
                    resolveMove(move.bot, opposite, move.card.magnitude, ref orders, false);
                    break;

                case ("uturn"):
                    switch (move.bot.currentDirection)
                    {
                    case Robot.orientation.X:
                        move.bot.currentDirection = Robot.orientation.NEG_X;
                        break;

                    case Robot.orientation.NEG_X:
                        move.bot.currentDirection = Robot.orientation.X;
                        break;

                    case Robot.orientation.Y:
                        move.bot.currentDirection = Robot.orientation.NEG_Y;
                        break;

                    case Robot.orientation.NEG_Y:
                        move.bot.currentDirection = Robot.orientation.Y;
                        break;
                    }
                    orders.Add(new orderModel {
                        botNumber = move.bot.robotNum, move = (movement)rand.Next(0, 2), magnitude = 2, outOfTurn = false
                    });
                    break;
                }
                return(orders);
            }
        }