Exemplo n.º 1
0
 public static void DisplayMatrix(string replicaId, MovingRobotIntoMatrixStateMachine stateMachine)
 {
     Console.WriteLine($"Replica ID:{replicaId} has in memory this statemachine:");
     for (int i = 0; i < stateMachine.Matrix.Length; i++)
     {
         for (int n = 0; n < stateMachine.Matrix[i].Length; n++)
         {
             Console.Write("|");
             Console.Write(stateMachine.Matrix[i][n]);
             Console.Write("|");
         }
         Console.WriteLine();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initialize what the state machine should be
 /// This state machine will be the one replicated accross all replicas
 /// </summary>
 static void initializeStateMachine()
 {
     stateMachine = new MovingRobotIntoMatrixStateMachine();
 }
Exemplo n.º 3
0
        static void readUserInput()
        {
            while (true)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();

                if (pressedKey.Key == ConsoleKey.Spacebar)
                {
                    Console.Clear();
                    foreach (Replica replica in replicas)
                    {
                        MovingRobotIntoMatrixStateMachine.DisplayMatrix(replica.RoleState.MessageSender.UniqueId,
                                                                        (replica.RoleState as ReplicaState).StateMachine as MovingRobotIntoMatrixStateMachine);
                    }
                }
                //We will use two different client/threads to simulate simultaneous command send
                //use LEFT/RIGHT/UP/DOWN for thread 2, and "1234" for thread 1
                else if (pressedKey.KeyChar >= '1' && pressedKey.KeyChar <= '4')
                {
                    RobotMove move = RobotMove.Down;
                    if (pressedKey.KeyChar == '1')
                    {
                        move = RobotMove.Left;
                    }
                    else if (pressedKey.KeyChar == '2')
                    {
                        move = RobotMove.Up;
                    }
                    else if (pressedKey.KeyChar == '3')
                    {
                        move = RobotMove.Right;
                    }

                    MoveRobotCommand command = new MoveRobotCommand();
                    command.Move = move;
                    Thread thread = new Thread(() =>
                    {
                        sendPaxosRequest(command, 0);
                    });
                    thread.Start();
                }
                else
                {
                    RobotMove move = RobotMove.Down;
                    if (pressedKey.Key == ConsoleKey.LeftArrow)
                    {
                        move = RobotMove.Left;
                    }
                    else if (pressedKey.Key == ConsoleKey.UpArrow)
                    {
                        move = RobotMove.Up;
                    }
                    else if (pressedKey.Key == ConsoleKey.RightArrow)
                    {
                        move = RobotMove.Right;
                    }

                    MoveRobotCommand command = new MoveRobotCommand();
                    command.Move = move;
                    Thread thread = new Thread(() =>
                    {
                        sendPaxosRequest(command, 1);
                    });
                    thread.Start();
                }
            }
        }