Example #1
0
 public void IncrementEpochAndVC()
 {
     Epoch = VC.Tick(Mid);
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid} [Increment]");
     }
 }
Example #2
0
 public void JoinThenIncrement(VectorClock other)
 {
     JoinEpochAndVC(other);
     IncrementEpochAndVC();
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid}");
     }
 }
Example #3
0
 public void JoinEpochAndVC(VectorClock other)
 {
     VC.Max(other);
     Epoch = this.VC.GetComponent(this.Mid);
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid} [Join {other.ToString()}]");
     }
 }
Example #4
0
 public MachineState(ulong id, ILogger logger, bool enableLogging)
 {
     this.VC            = new VectorClock(0);
     this.Mid           = (long)id;
     this.Logger        = logger;
     this.EnableLogging = enableLogging;
     this.IncrementEpochAndVC();  // initialize
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Created {VC.ToString()} for {Mid}");
     }
 }
Example #5
0
        static void Main(string[] args)
        {
            //variáveis
            int    VJ;
            int    VC;
            string OD;
            int    NR   = 0;
            var    A    = new Random();
            double TT   = 0;
            int    Rslt = 0;


            Console.WriteLine("Bem vindo ao jogo! A menor pontuação vence.");
            NR = ValorJogadorDigitado("Diga quantas rodadas voce quer jogar. Deve ser menor que 5", "Voce nao atendeu os requisitos", 0, 5);

            double[] medidas = new double[NR];

            //loop de rodadas

            for (int R = 0; R < NR; R = R + 1)
            {
                Console.WriteLine($"Vamos jogar uma rodada {R + 1} de {NR} ");

                //input do jogador
                VJ = ValorJogadorDigitado("Digite um valor entre 1 e 50", "O que voce digitou nao atende os requisitos", 1, 50);

                //vez do computador e input de operação
                Console.WriteLine("O Computador vai gerar um número.");
                VC = A.Next(1, 11);

                string[] valores_validos = { "A", "S", "M", "CANCEL" };

                OD = ValorDigitadoTratado("Digite A para adição e S para subtração M para multiplicação (ou CANCEL)",
                                          "Você não digitou algo válido. Tente novamente. A para + e S para -",
                                          valores_validos);

                //seleção de operação
                switch (OD)
                {
                case "A":
                    Console.WriteLine("Você escolheu adição.");
                    Rslt = VJ + VC;
                    break;

                case "S":
                    Console.WriteLine("Você escolheu subtração.");
                    Rslt = VJ - VC;
                    break;

                case "M":
                    Console.WriteLine("Você escolheu multiplicação.");
                    Rslt = VJ * VC;
                    break;

                default:
                    Console.WriteLine("não resolvi.");
                    break;
                }


                //resultado e input do palpite
                Console.WriteLine("O resultado da operação foi: " + Rslt);

                DateTime antes = DateTime.Now;

                string[] valor_valido = { VC.ToString() };
                string   valor_certo  = ValorDigitadoTratado("Tente acertar o número gerado pelo computador.",
                                                             "Você errou ou não digitou um número. Tente novamente.",
                                                             valor_valido);

                //sucesso
                Console.WriteLine("Você acertou!");
                medidas[R] = (int)DateTime.Now.Subtract(antes).TotalMilliseconds;
                TT         = TT + (int)DateTime.Now.Subtract(antes).TotalMilliseconds;
            }

            //fim de jogo
            Console.WriteLine("O jogo terminou. Suas pontuacoes em milisegundos:");
            for (int Q = 1; Q <= NR; Q = Q + 1)
            {
                Console.WriteLine("Rodada" + Q + ": " + medidas[Q - 1]);
            }


            int QQ = 1;

            while (QQ <= NR)
            {
                int a = 1;
                Console.WriteLine("Rodada" + QQ + ": " + medidas[QQ - 1]);
                a  = a + 1;
                QQ = QQ + 1;
            }

            TT = MediaTempo(medidas);
            Console.WriteLine("A media entre as rodadas foi: " + TT);
            Console.ReadLine();
        }
Example #6
0
 private void cmdCalcVert_Click(object eventSender, EventArgs eventArgs)
 {
     H1 = (float)(0.5d * Conversion.Val(txtMTR.Text) + Conversion.Val(txtMTL.Text)); // H1 is height of MHW above MLLW
     H1 = (float)(Convert.ToInt32(H1 * 10f + 0.5d) / 10d);
     VC = (float)(Conversion.Val(txtCH.Text) + H1 - Conversion.Val(txtHeight.Text));
     AC = (float)(VC - Conversion.Val(txtBH.Text));
     AC = (float)(Convert.ToInt32(AC * 10f + 0.5d) / 10d);
     DC = (float)(Conversion.Val(txtCD.Text) + Conversion.Val(txtHeight.Text) - Conversion.Val(txtDraft.Text));
     VerticalTxtBx.SelectionAlignment = HorizontalAlignment.Center;
     VerticalTxtBx.AppendText("Height of MHW above MLLW = 1/2 Mean Range + Mean Tide");
     VerticalTxtBx.AppendText(" = 1/2 (" + Conversion.Val(txtMTR.Text) + ") + " + Conversion.Val(txtMTL.Text).ToString() + " = " + H1.ToString() + Environment.NewLine);
     VerticalTxtBx.AppendText("Vertical Clearance = Charted Height + Height of MHW above MLLW - Height of Tide above MLLW");
     VerticalTxtBx.AppendText(" = " + Conversion.Val(txtCH.Text) + " + " + H1.ToString() + " - " + Conversion.Val(txtHeight.Text).ToString() + " = " + VC.ToString() + Environment.NewLine);
     VerticalTxtBx.AppendText("Actual Clearance = Vertical Clearance - Boat Height");
     VerticalTxtBx.AppendText(" = " + VC + " - " + Conversion.Val(txtBH.Text).ToString() + " = " + AC.ToString() + Environment.NewLine);
     DepthTxtBx.SelectionAlignment = HorizontalAlignment.Center;
     DepthTxtBx.AppendText("Depth Clearance (under keel) = Charted Depth + Height of Tide above MLLW - Boat's Draft");
     DepthTxtBx.AppendText(" = " + Conversion.Val(txtCD.Text) + " + " + Conversion.Val(txtHeight.Text).ToString() + " - " + Conversion.Val(txtDraft.Text).ToString() + " = " + DC.ToString());
 }