示例#1
0
        // 複数の手で判定
        static public RPS judge(int rock, int paper, int scissor)
        {
            RPS result = RPS.__reserved;

            // グーチョキパーが全部出ていたら強制あいこ
            if (!(rock > 0 && paper > 0 && scissor > 0))
            {
                RPS expr1 = RPS.__reserved;
                RPS expr2 = RPS.__reserved;
                // グーとパーで判定
                if (rock > 0 && paper > 0)
                {
                    expr1 = RPS.rock;
                    expr2 = RPS.paper;
                }
                // パーとチョキで判定
                if (paper > 0 && scissor > 0)
                {
                    expr1 = RPS.paper;
                    expr2 = RPS.scissor;
                }
                // チョキとグーで判定
                if (scissor > 0 && rock > 0)
                {
                    expr1 = RPS.scissor;
                    expr2 = RPS.rock;
                }
                result = judge(expr1, expr2);
            }
            return(result);
        }
示例#2
0
    public void Testing()
    {
        try
        {
            playerChoice = RPS.Rock;
            AIChoice     = RPS.Scisors;
            Assert.AreEqual(hasWon(), Result.WIN);

            playerChoice = RPS.Rock;
            AIChoice     = RPS.Rock;
            Assert.AreEqual(hasWon(), Result.DRAW);

            playerChoice = RPS.Rock;
            AIChoice     = RPS.Paper;
            Assert.AreEqual(hasWon(), Result.LOSE);

            playerChoice = RPS.Paper;
            AIChoice     = RPS.Rock;
            Assert.AreEqual(hasWon(), Result.WIN);
        }
        catch (AssertionException e)
        {
            Debug.Log("RPS Fail" + e.ToString());
        }

        playerChoice = RPS.NotPlayed;
        AIChoice     = RPS.NotPlayed;
    }
示例#3
0
 /// <summary>
 /// Calculates the winner
 /// </summary>
 /// <param name="player"></param>
 /// <param name="computer"></param>
 void CalculateWinner(RPS player, RPS computer)
 {
     //tie game
     if (player == computer)
     {
         Console.WriteLine($"The game is a tie.");
         playerWins++;
         computerWins++;
     }
     else
     {
         //calculating the winner is simple, simply get the
         //winning combination for the player
         //if the result equals the computers roll then the player wins
         //otherwise the computer wins.
         // such as player calls rock, winners[rock] == scissors. If computer == scissors then
         // player wins otherwise the computer wins as the only other option is paper
         // remeber the options of the computer has a rock is negated in the tie selection
         //
         var p = winners[player];
         if (p == computer)
         {
             Console.WriteLine($"Congratulations you won. {player} beats {computer}.");
             playerWins++;
         }
         else
         {
             Console.WriteLine($"Computer Wins. {computer} beats {player}.");
             computerWins++;
         }
     }
 }
示例#4
0
    // Use this for initialization
    void Start()
    {
        controller = GetComponent <CharacterController> ();

        //initialize RPS values
        int i       = Random.Range(1, 4);
        RPS tempRPS = RPS.Rock;

        switch (i)
        {
        case 1:
            tempRPS = RPS.Rock;
            break;

        case 2:
            tempRPS = RPS.Paper;
            break;

        case 3:
            tempRPS = RPS.Scissors;
            break;
        }
        P1Drawer.SendMessage("Draw", i);
        P2Drawer.SendMessage("Draw", i);
        P1RPSValue = tempRPS;
        P2RPSValue = tempRPS;

        playerSpeed = 0;
        //Init ();
    }
示例#5
0
        // 一対一で判定
        static public RPS judge(RPS expr1, RPS expr2)
        {
            // 下の判定に引っかからなければあいこ
            RPS result = RPS.__reserved;

            // グー対パーはパーの勝ち
            if ((expr1 == RPS.rock && expr2 == RPS.paper) ||
                (expr2 == RPS.rock && expr1 == RPS.paper))
            {
                result = RPS.paper;
            }
            // パー対チョキはチョキの勝ち
            if ((expr1 == RPS.paper && expr2 == RPS.scissor) ||
                (expr2 == RPS.paper && expr1 == RPS.scissor))
            {
                result = RPS.scissor;
            }
            // チョキ対グーはグーの勝ち
            if ((expr1 == RPS.scissor && expr2 == RPS.rock) ||
                (expr2 == RPS.scissor && expr1 == RPS.rock))
            {
                result = RPS.rock;
            }
            return(result);
        }
示例#6
0
    public static void StartGame(RPS rps)
    {
        while (!rps.CheckForTwoWins())
        {
            Console.WriteLine("Choose rock, paper, or scissors (R/P/S):");
            string input = Console.ReadLine();
            rps.User.ChooseItem(input);
            rps.Comp.ChooseRandomly();
            Console.WriteLine("------------------------------");
            Console.WriteLine("You chose: " + rps.User.Item);
            Console.WriteLine("Computer chose: " + rps.Comp.Item);
            Console.WriteLine(rps.GamePlay());
            Console.WriteLine("------------------------------");
        }
        Console.WriteLine("Play again? (Y/N)");
        string response = Console.ReadLine();

        if (response[0].ToString().ToUpper() == "Y")
        {
            rps.User.Wins = 0;
            rps.Comp.Wins = 0;
            StartGame(rps);
        }
        else
        {
            Console.WriteLine("Bye!");
        }
    }
示例#7
0
        static void Main(string[] args)
        {
            ///RPS teste = new RPS();
            // esta linha é para pegar o caminho do json e ler linha por linha.
            string fileJsonString = File.ReadAllText(@"C:\temp\input\return-api.json");
            //
            RPS      teste  = Newtonsoft.Json.JsonConvert.DeserializeObject <RPS>(fileJsonString);
            Telefone teste2 = Newtonsoft.Json.JsonConvert.DeserializeObject <Telefone>(fileJsonString);
            //Console.WriteLine(fileJsonString);

            // o caminho destinho para a onde o arquivo vai depois de formatado
            string output = string.Format(@"C:\temp\output\.txt", DateTime.Now);

            using (StreamWriter pastadestino = new StreamWriter(fileJsonString))
            {
                pastadestino.WriteLine(fileJsonString);
                pastadestino.WriteLine(teste.documento_orgao_expeditor + teste2.numero);
                //pastadestino.WriteLine();

                pastadestino.Flush();
                pastadestino.Close();
            }
            Statuspedido kleber = new Statuspedido();

            kleber.mensagem = "";

            List <string> jsonlist = new List <string>();
        }
 /// 3rd player adds some complexity :)
 public static string PlayWith3Players(RPS player1, RPS player2, RPS player3)
 {
     var winner = (player1, player2, player3) switch
     {
         // Draw cases (any combination of the three basic options), shotgun cases are handled by this.
         (_, _, _) => "Draw",
     };
示例#9
0
文件: Randy.cs 项目: dylanmrule/Lab13
        public override RPS GetRPS()
        {
            int pick   = r.Next(0, 3);
            RPS output = (RPS)pick;

            return(output);
        }
示例#10
0
        //Methods
        public RPS GenerateRPS()
        {
            bool keepLooping     = true;
            RPS  playerSelection = RPS.scissors;


            while (keepLooping)
            {
                Console.WriteLine("Do you want to play rock, paper, or scissors?");
                string input   = Console.ReadLine().Trim().ToLower();
                bool   isValid = Enum.TryParse <RPS>(input, true, out playerSelection);

                if (isValid == true && playerSelection == RPS.paper)
                {
                    keepLooping = false;
                }
                else if (isValid == true && playerSelection == RPS.rock)
                {
                    keepLooping = false;
                }
                else if (isValid == true && playerSelection == RPS.scissors)
                {
                    keepLooping = false;
                }
                else
                {
                    keepLooping = true;
                }
            }

            return(playerSelection);
        }
示例#11
0
        public IActionResult Index(Guid id, RPS Hand, [FromServices] IGamesService games)
        {
            if (Hand == RPS.UNKNOWN || id == Guid.Empty)
            {
                return(BadRequest());
            }

            if (games.Exist(id))
            {
                Game game = games.Get(id);

                //Game with result
                if (game.Result != Result.UNKNOWN)
                {
                    return(BadRequest());
                }

                //Author
                bool isAuthor = IsAuthor(id, game.ID_Session);
                if (isAuthor)
                {
                    return(BadRequest());
                }

                Result result = CheckResult(game.HandAuthor, Hand);
                game.FinishedAt   = DateTime.UtcNow;
                game.HandOpponent = Hand;
                game.Result       = result;
                games.Update(game);
            }
            return(Redirect("/" + id.ToString()));
        }
    private static void HandleRequestMatch(GameSession session, PacketReader packet)
    {
        long characterId = packet.ReadLong();

        Player otherPlayer = session.FieldManager.State.Players.Values
                             .FirstOrDefault(x => x.Value.CharacterId == characterId)?.Value;

        if (otherPlayer is null)
        {
            return;
        }

        RPS rpsEvent = DatabaseManager.Events.FindRockPaperScissorsEvent();

        if (rpsEvent is null)
        {
            return;
        }

        if (!session.Player.Inventory.HasItem(rpsEvent.VoucherId))
        {
            session.Send(NoticePacket.Notice(SystemNotice.MicrogameRpsOpenBannerFailedNotExistTicket, NoticeType.Chat | NoticeType.FastText));
            return;
        }

        session.Player.RPSOpponentId = otherPlayer.CharacterId;

        otherPlayer.Session.Send(RockPaperScissorsPacket.RequestMatch(session.Player.CharacterId));
    }
示例#13
0
        void InitRps()
        {
            RPS globalRPS = new RPS();

            Application["globalRPS"] = globalRPS;
            globalRPS.Initialize(null);
        }
示例#14
0
        /// <summary>
        /// Runs a player round
        /// </summary>
        /// <param name="roundNumber"></param>
        /// <returns></returns>
        bool PlayRound(int roundNumber)
        {
            DrawGameBoard();

            RPS computerChoice = GetComputerRps();
            RPS playerChoice   = RPS.Invalid;

            Console.WriteLine($"Round {roundNumber + 1}:");
            bool quit = false;

            while (playerChoice == RPS.Invalid)
            {
                Console.Write("Please make your selection. Rock, Paper, Scissors... ");
                string choice = Console.ReadLine();
                switch (choice.ToLowerInvariant().Trim())
                {
                case "rock":
                case "r":
                    playerChoice = RPS.Rock;
                    break;

                case "paper":
                case "p":
                    playerChoice = RPS.Paper;
                    break;

                case "scissors":
                case "s":
                    playerChoice = RPS.Scissors;
                    break;

                case "quit":
                case "q":
                    quit = true;
                    break;

                default:
                    Console.WriteLine($"{choice} is not a valid selection. Please try again.\r\n");
                    break;
                }
                if (quit)
                {
                    break;
                }
            }

            if (quit)
            {
                return(false);
            }

            Console.WriteLine($"The computer chose: {computerChoice}");
            Console.WriteLine($"You chose: {playerChoice}");
            CalculateWinner(playerChoice, computerChoice);

            Console.Write("Press [Enter] to start the next game.");
            Console.ReadLine();
            return(true);
        }
示例#15
0
文件: TestRPS.cs 项目: snownz/RPS
        public void Test02CaseInsensitive()
        {
            var str  = "[[ [ [\"Armando\", \"p\"], [\"Dave\", \"s\"] ], [[\"Richard\", \"r\"], [\"Michael\", \"s\"] ],  ],  [  [ [\"Allen\", \"s\"], [\"Omer\", \"p\"] ],  [ [\"David E.\", \"r\"], [\"Richard X.\", \"P\"] ]  ] ] ";
            var play = new RPS();
            var win  = play.rps_tournament_winner(str);

            Assert.IsTrue("Richard" == win);
        }
示例#16
0
        public void RPSCheckForWinner_CheckIfThereIsAWinner_Player2()
        {
            RPS game = new RPS();

            Assert.AreEqual("player2", RPS.CheckForWinner("paper", "scissor"));
            Assert.AreEqual("player2", RPS.CheckForWinner("rock", "paper"));
            Assert.AreEqual("player2", RPS.CheckForWinner("scissor", "rock"));
        }
示例#17
0
文件: TestRPS.cs 项目: snownz/RPS
        public void Test01Lower()
        {
            var str  = "[ [\"Armando\", \"p\"], [\"Dave\", \"s\"] ]";
            var play = new RPS();
            var win  = play.rps_game_winner(str);

            Assert.IsTrue("Dave" == win);
        }
示例#18
0
文件: RPSGame.cs 项目: nbouteme/rps
 public bool IsBeatenBy(RPS o)
 {
     if (this == Lose)
     {
         return(true);
     }
     return(this != o && !Beats(o));
 }
示例#19
0
文件: TestRPS.cs 项目: snownz/RPS
        public void Test03()
        {
            var str  = "[[ [ [\"Lucas\", \"R\"], [\"Rasul\", \"S\"] ], [ [\"Armando\", \"P\"], [\"Dave\", \"S\"] ], [[\"Richard\", \"R\"], [\"Michael\", \"S\"] ],  ],  [  [ [\"Allen\", \"S\"], [\"Omer\", \"P\"] ],  [ [\"David E.\", \"R\"], [\"Richard X.\", \"P\"] ]  ] ] ";
            var play = new RPS();
            var win  = play.rps_tournament_winner(str);

            Assert.IsTrue("Lucas" == win);
        }
示例#20
0
        //Methods
        public RPS GenerateRPS()
        {
            //generate & return a RPS

            RPS value = RPS.rock;

            return(value);
        }
示例#21
0
        public void Initialize()
        {
            RPS globalRPS = new RPS();

            HttpContext.Current.Application["globalRPS"] = globalRPS;

            globalRPS.Initialize(null);
        }
示例#22
0
 void Application_End(object sender, EventArgs e)
 {
     if (Application["globalRPS"] is RPS)
     {
         RPS globalRPS = (RPS)Application["globalRPS"];
         globalRPS.Shutdown();
         Application["globalRPS"] = null;
     }
 }
示例#23
0
        public void PlayerOneRock_PlayerOneWins_False()
        {
            RPS newGame = new RPS();

            newGame.PlayerOneRock("Paper");
            int POS = newGame.GetPlayerOneScore();

            Assert.AreEqual(POS, 0);
        }
示例#24
0
        public void PlayerOnePaper_PlayerOneWins_True()
        {
            RPS newGame = new RPS();

            newGame.PlayerOnePaper("Rock");
            int POS = newGame.GetPlayerOneScore();

            Assert.AreEqual(POS, 1);
        }
示例#25
0
        public void PlayerOneScissors_PlayerOneWins_True()
        {
            RPS newGame = new RPS();

            newGame.PlayerOneScissors("Paper");
            int POS = newGame.GetPlayerOneScore();

            Assert.AreEqual(POS, 1);
        }
示例#26
0
        public void PlayerOneScissors_PlayerOneWins_False()
        {
            RPS newGame = new RPS();

            newGame.PlayerOneScissors("Rock");
            int POS = newGame.GetPlayerOneScore();

            Assert.AreEqual(POS, 0);
        }
        public void SameShouldDraw(RPS choise)
        {
            // Arrange -> See data rows.

            // Act
            var result = RockPaperScissors.PlayWith2Players(choise, choise);

            // Assert
            Assert.IsTrue(result.Contains("Draw"));
        }
示例#28
0
    static void Main()
    {
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        Console.WriteLine("Welcome to the classic game of Rock, Paper, Scissors!");
        Console.WriteLine("Best two out of three wins the match!!");
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        RPS rps = new RPS();

        StartGame(rps);
    }
        public void ScissorsShouldWinPaper(RPS player1, RPS player2, string winner)
        {
            // Arrange -> See data rows.

            // Act
            var result = RockPaperScissors.PlayWith2Players(player1, player2);

            // Assert
            Assert.IsTrue(result.Contains(winner));
        }
        public void ShotgunShouldThrow(RPS player1, RPS player2)
        {
            // Arrange -> see data rows.

            // Act
            var result = RockPaperScissors.PlayWith2Players(player1, player2);

            // Assert -> unhappy path testing :(
            Assert.Fail();
        }
示例#31
0
        public static void StartGame()
        {
            Console.WriteLine ("Welcome to Rock, Paper, Scissors!");
            Console.WriteLine ("Player One, choose your weapon");
            string PlayerOneWeapon = Console.ReadLine();
            Console.WriteLine ("Player Two, choose your weapon");
            string PlayerTwoWeapon = Console.ReadLine();

            var game = new RPS ();
            Console.WriteLine (game.TwoPlayer (PlayerOneWeapon, PlayerTwoWeapon));
            StartGame ();
        }
        public RPSResult PlayRound(RPS Player1Move, RPS Player2Move)
        {
            List<RoundOutcome> PossibleOutcomes = PossibleOutcomeGenerator.Instance.PossibleOutcomes;
            Player1Throw = Player1Move;
            Player2Throw = Player2Move;

            RPSResult winner = RPSResult.Tie;

            foreach (RoundOutcome outcome in PossibleOutcomes)
            {
                if (Player1Throw == outcome.Play1 && Player2Throw == outcome.Play2)
                {
                    winner = outcome.Winner;
                    break;
                }
            }
            RoundPlayed = true;
            return winner;
        }
        private RPSResult DetermineWinner(RPS play1, RPS play2)
        {
            RPSResult winner = RPSResult.Tie;

            switch (play1)
            {
                case RPS.Rock:
                    if (play2 == RPS.Scissors)
                    {
                        winner = RPSResult.Player1;
                    }
                    else if (play2 == RPS.Paper)
                    {
                        winner = RPSResult.Player2;
                    }

                    break;
                case RPS.Paper:
                    if (play2 == RPS.Rock)
                    {
                        winner = RPSResult.Player1;
                    }
                    else if (play2 == RPS.Scissors)
                    {
                        winner = RPSResult.Player2;
                    }
                    break;
                case RPS.Scissors:
                    if (play2 == RPS.Paper)
                    {
                        winner = RPSResult.Player1;
                    }
                    else if (play2 == RPS.Rock)
                    {
                        winner = RPSResult.Player2;
                    }
                    break;
            }

            return winner;
        }
        /// <summary>
        /// Get the throw that defeats the throw sent
        /// </summary>
        /// <param name="play"></param>
        /// <returns></returns>
        private static RPS GetCounterRPS(RPS play)
        {
            RPS result = RPS.Rock;
            if (play == RPS.Paper) result = RPS.Scissors;
            if (play == RPS.Rock) result = RPS.Paper;
            if (play == RPS.Scissors) result = RPS.Rock;

            return result;
        }
示例#35
0
 /// <summary>
 /// Sets the choice of the player for this round (next round begins when both players have selected their choice)
 /// </summary>
 /// <param name="player"></param>
 /// <param name="choice"></param>
 public void setPlayerChoice(IRPSPlayer player, RPS choice)
 {
     if(matchHasEnded)
     {
         return;
     }
     if(player == player1)
     {
         player1Choice = choice;
         player1HasPlayed = true;
         if(player2HasPlayed)
         {
             endRound();
         }
     }
     else if(player == player2)
     {
         player2Choice = choice;
         player2HasPlayed = true;
         if (player1HasPlayed)
         {
             endRound();
         }
     }
 }
示例#36
0
 public void GetReady()
 {
     game = new RPS ();
 }
示例#37
0
 public int Logic(RPS p1, RPS p2)
 {
     if (p1 == RPS.Paper && p2 == RPS.Paper) {
         return -1;
     } else if (p1 == RPS.Paper && p2 == RPS.Rock) {
         return 1;
     } else if (p1 == RPS.Paper && p2 == RPS.Scissors) {
         return 2;
     } else if (p1 == RPS.Rock && p2 == RPS.Paper) {
         return 2;
     } else if (p1 == RPS.Rock && p2 == RPS.Rock) {
         return -1;
     } else if (p1 == RPS.Rock && p2 == RPS.Scissors) {
         return 1;
     } else if (p1 == RPS.Scissors && p2 == RPS.Paper) {
         return 1;
     } else if (p1 == RPS.Scissors && p2 == RPS.Rock) {
         return 2;
     } else if (p1 == RPS.Scissors && p2 == RPS.Scissors) {
         return -1;
     }
     return -1;
 }