How To Cheat In A Game Of Rock Paper Scissors

  1. How To Cheat On Rock Paper Scissors
  2. How To Cheat In A Game Of Rock Paper Scissors Free
  3. How To Cheat In A Game Of Rock Paper Scissors Paper
  4. How To Cheat In A Game Of Rock Paper Scissors Step By Step
  5. How Do You Cheat In Rock Paper Scissors

Creating a basic Rock Paper Scissors game in PHP

'r' stands for Rock, 'p' stands for Paper and 's' stands for Scissors. Now, let's write some code that chooses rock, paper or scissors randomly. Computer = trandint(0,2) Now we will set a variable to false and by using it in a while loop, we can keep the game playing infinitely!


Rock-paper-scissors chart (Photo credit: Wikipedia)

This tutorial will outline the creation of a very basic game I created a long time ago in PHP for the purpose of learning some basic concepts around inputs/outputs from the command-line, decision trees (nested “if-elseif-else” type statements) and variability in PHP’s presentation layer. I thought I’d dust this one off in particular to emphasize how easy it is to create a basic game and encourage readers to tinker with their own simple game creation.

This is the first part of a four part series. The first part is reading from the command-line if the program is run from a console/terminal (and how to determine this). The next part will show how to convert the same program to work via a browser as well if run from there (and how to detect this). The third part shows how you can extend the game to allow different formats for displaying it (depending on where it was being integrated) via SOAP Web Services. The fourth part shows how to create a basic Java-based desktop application that consumes the SOAP Web Service. Yes you heard right, SOAP not REST, because I created this example over a decade ago just before AJAX, REST and later JSON started taking the development world by storm.

These experiments would shine an important light on the diverse capabilities of PHP for me in my early days of learning the language, some 11-12 years ago, and also demonstrated some of its limitations (i.e. did not realize at the outset that PHP had no GUI system on its own like Java’s AWT or Swing, and that without somewhat obscure 3rd-party C-based frameworks like GTK+, Qt-php, wxWidgets, etc your only choice for interaction is command-line, browser or exposing an API that can be consumed by another programming language).

Inputs
You will be given the selection of any of the following values:

  • Rock (also accept “R” or the representative number “0” which looks kinda like a rock)
  • Paper (also accept “P” or the representative number “1” which kind of looks like a flat piece of paper)
  • Scissors (also accept “S” or the representative number “2” which might require a bit more imagination, but just use your fingers to say “2” and it seems like a good fit as well)

This can be presented to the player and read in to the game via a variety of possible entry methods (i.e. toggling a Radio box, selecting from a single-value dropdown, typing in command-line, or in our case, clicking on an image).

Outputs

The game will randomize three possible outcomes on the competitor/server (aka “computer”) side:

  • 0 = Rock
  • 1 = Paper
  • 2 = Scissors

Based on your selection you will be told whether you won, lost or had a draw with (picked the same value as) the computer player.

Rules

The rules of the game are simple, so evaluating a win or loss couldn’t be easier:

  • Rock (0) smashes Scissors (2)
  • Paper (1) covers Rock (0)
  • Scissors (2) cut Paper (1)
  • The same selection is always a draw (i.e. 0=0, 1=1, 2=2)

Why bother with the numbers? It’s slightly faster than comparing strings each time, and allows us to do more expensive operations like “equalsIgnoreCase” just once, at the onset of determining the user’s input. In general, machines excel in crunching numbers, its just what they do, not necessarily true for text.

Game Logic

With some added bits of logic for creating a User Session to persist wins/losses/draws data, the game code looks roughly as follows:

To run the game, type the following from a terminal/console and hit enter:
> php RPS.php

It will ask you for your choice of Rock (R or 0), Paper (P or 1) or Scissors (S or 2) and tell you whether you won or lost.


-or-

Conclusion

So if you made it through this part, you’ve learned to take your baby steps with server-side game development by doing some basic but interesting things in PHP with the command-line to create an old school DOS/UNIX command-line style game. Can you believe entire MMORPGs and even visual games (see “bsdgames“) used to be played this way? They even still enjoy a cult following to this day. Speaking of “old school”; nowadays, I’ve seen so many similar tutorial series centered around creating basic command-line game engines (is there some reason its almost always TicTacToe?) as a tool for learning more modern stacks like Ruby/Rails, NodeJS & Google’s Go language, which is what gave me the idea to dust off this old PHP game I had put together back in the day. Despite the fact that we now have high definition 3D/VR/AR real-time image rendering engines like Unreal, there are so many parallels between what was new and innovative back then, and what is being called new and innovative today. At the end of the day, you need to as quickly as possible express some business logic, drop your code on a server or device knowing it can run there without requiring any changes, and expose it to the required platforms for end-user consumption; whether that’s a Computer command-line, Web Browser, Mobile device, connected Car Dashboard, VR headset, or just about anything else. The implementation really doesn’t matter, speed (both in terms of time-to-market for developer and application performance experienced by the user) along with convenience (in terms of maintainability for the developer and ease-of-use for the user) should always be the top priority.

See the other parts here:

  • Part 1: Creating a basic Rock Paper Scissors game in PHP <– you are here
  • Part 2: Moving a command-line PHP Rock Paper Scissors game to the Browser
  • Part 3: Exposing your PHP Rock Paper Scissors game via SOAP Web Services
  • Part 4: Integrate PHP based SOAP RPS game server in another language, JAVA desktop GUI

« previous post

Raspberry PI 2 – Complete Starter Kit unboxing & config (IP/DNS/SSH/FTP/VNC/VPN/HTTP)'>

This blog post will summarize my recent Raspberry PI 2 - Canakit unboxing & config...

  • Comments (1)
  • Trackbacks (0)
  • Related Tags
  • Related Categories
Leave a Reply

No trackbacks yet.

  1. Raspberry PI – Fart Detector experiment

    Perhaps the most 'potent' experiment of them all?...

  2. Noise Isolation .vs. Cancellation .vs. Reduction – protect your ears and work in peace & quiet

    Most of the time, Developers' day-to-day jobs can be a bit stressful. With tight deadlines, high expectations, and often unwieldy applications/codebases to manage, you can see how there really is a need to be able to concentrate in order to succeed in this role. Of course, this applies to non-technical roles as well, but in...

  3. Making a Rock-Paper-Scissors game Multiplayer

    Multiplayer features require networking capabilities of some sort, and typically, a form of persistent data storage (i.e. to save things like 'Leaderboards' to keep track of Wins/Losses/Draws in the case of our RPS game)....

  4. Integrate PHP based SOAP RPS game server in another language, JAVA desktop GUI

    Now that we have a Web Service ready to consume (even though it is SOAP based), it should be pretty easy to extend to Java, which also means it should be possible with a little bit of effort to create a Desktop GUI. For more on creating a Java-based SOAP server to have an all-Java version...

  5. Exposing your PHP Rock Paper Scissors game via SOAP Web Services

    So why SOAP? Well quite simply this was what I used back when I was first working through PHP and learning the hard way how to expose some server-side 'business logic' as a Web Service. This was over a decade ago (late 2006 through 2007), and Google's SOAP Search API had yet to be phased...

  6. Moving a command-line PHP Rock Paper Scissors game to the Browser

    In the first part we saw an example for creating a PHP Rock Paper Scissors game that waits for user input via the command-line and then evaluates the output of the game. Next we see an example for porting our basic command-line PHP Rock Paper Scissors game to the browser to reach a broader audience,...

  7. HSVO project problems and NRC’s SAVOIR 2.0 SDK solution

    In the last post I set the context for the HSVO project and how I winded up a member of it via my contract at NRC, setting the stage to help any potential readers understand all the partners and the objectives they had going in. Now I'll talk about the major problems faced on the...

  8. E-Commerce Shopping Cart in JavaScript and PHP

    In E-Commerce, a 'frictionless experience' is often described as the ultimate design goal when it comes to the consumer's purchasing experience. An easy-to-use, robust shopping cart solution that can easily have any number of diverse types of items added to it, calculate shipping & handling, taxes and any other additional fees (where such apply), provides...

  9. Musa Betsu Kyu Judo club website launch

    Just a quick update on what I've been up to lately in my spare time (well one of the many projects), working on the site for the local (Greater Moncton area) Judo club called 'Musa Betsu Kyu'. It is run by Sensei Earl O'Blenis who is an excellent Judo instructor that we're fortunate to have...

  10. Working with LimeSurvey’s RemoteControl2 JSON-RPC API in PHP

    Recently, I needed to switch away from SurveyMonkey, which, while still a useful free service for quickly collecting some basic Survey results, leaves much to be desired in terms of what they offer in their basic version. Of course the fully paid versions offer significantly more functionality, but the upper-end of the pricing schemes that...

BC$ = Behavior, Content, Money

The goal of the BC$ project is to raise awareness and make changes with respect to the three pillars of information freedom - Behavior (pursuit of interests and passions), Content (sharing/exchanging ideas in various formats), Money (fairness and accessibility) - bringing to light the fact that:
1. We regularly hand over our browser histories, search histories and daily online activities to companies that want our money, or, to benefit from our use of their services with lucrative ad deals or sales of personal information.
2. We create and/or consume interesting content on their services, but we aren't adequately rewarded for our creative efforts or loyalty.
3. We pay money to be connected online (and possibly also over mobile), yet we lose both time and money by allowing companies to market to us with unsolicited advertisements, irrelevant product offers and unfairly structured service pricing plans.

Have you ever wondered how to build a game with Python? Have you ever wanted to build your own game but didn't because it was hard? Well, today I'm going to show you how to build one and show you just how simple it can be!

Here's the live demo and final code.

Part 1: Prerequisites

You should have a beginner understanding of:

  • Python

Part 2: Setup

Setting up your code environment on Repl.it

Repl.it is an online code editor where you can build your game. You don't have to use Repl.it but I suggest you do as it sets everything up for you and you don't require any installations.

Scissors

To get started, go to repl.it/languages/python. Your coding environment will spin up in just a few seconds!

You should see something like the following:

Part 3: Making The Game

1) Importing Modules

First, we'll need to import the randint module. To learn more about the randint package click here.

On the first line of the main.py file, type from random import randint. This will import the randint module.

2) Giving values to the variables

Let's make a list for all the entries a player could enter. In your main.py file, add:

'r' stands for Rock, 'p' stands for Paper and 's' stands for Scissors.

Now, let's write some code that chooses rock, paper or scissors randomly.

Now we will set a variable to false and by using it in a while loop, we can keep the game playing infinitely! To do that, just type

Now, let's write some code so the player can enter their name.

Also to make a scoring system, we'll write the following code:

Next, we want to give an option to the player to reset the game.

Here's the code so far:

3) Keeping the game in a loop

For this, I'll use a while loop but you can also use for loops!

At the bottom of the main.py file, add this:

Next, we'll use input to allow the player to choose either Rock, Paper, or Scissors.

There are 5 possibilities:1. The player chooses Rock2. The player chooses Paper3. The player chooses Scissors4. The player enters reset5. The word entered is invalid

How to cheat in a game of rock paper scissors free

4) Producing separate outcomes for all possibilities

To make things easier I will be making functions to print if the player wins or loses.First I will write the following before we make the function.

This will help us by printing different message by calling the same function.

Now I will be making a function that will be called only when the player wins. To do that enter the following code:

How To Cheat On Rock Paper Scissors

Now we will make a function that will be called only when the player losses.

Now we have to call these functions in the right places.

First we will assume that the outcome is a tie to do that enter the following code:

Next, we want to write some code for each action that someone can take.

What would the code be for paper and scissors?

How To Cheat In A Game Of Rock Paper Scissors Free

Now for the last part we are going to assume that the player wants to reset the game or he/she entered a invalid entry

5) Keeping the loop going

Now as we have completed building the game we need it to run infinitely.

To do this you just need to add the following statement after the while statement at the end,

This will instantly trigger the loop and keep the game going.

And at last, you need to add the following command so the computer chooses a different outcome every time

So, this is the final code:

6) The End

And congratulations! You just made your own game using Python!

If you haven't created an account on repl.it, make sure to make an account to save this wonderful creation!

If you are facing difficulties signing up watch this.

Here are some things which you can do:

  • Consider changing and adding more features!
  • Making it a two-player game.
  • Make the game only of 3 turns instead of running it infinitely.
  • You can give the text a typewriter effect. (If you don't know how to do it watch this video)

Demos from people who have hacked this workshop:

How To Cheat In A Game Of Rock Paper Scissors Paper

Now that you have finished building your game, you should share your beautiful creation with other people! Remember, it's as easy as giving them your URL!

How To Cheat In A Game Of Rock Paper Scissors Step By Step

You probably know the best ways to get in touch with your friends and family, but if you want to share your project with the worldwide Hack Club community there is no better place to do that than on Slack.

How Do You Cheat In Rock Paper Scissors

  1. In a new tab, open and follow these directions to signup for our Slack.
  2. Then, post the link to the #scrapbook channel to share it with everyone!