TechieYan Technologies

Python dice rolling game for two players

Abstract

Before we circulate ahead and understand the actual functioning of the dice rolling sport via the aspects of programming, allow us to attempt to understand the identical thru a logical technique.

Libraries:

Random: Random module is an in-built module of Python that is used to generate random numbers. These are pseudo-random numbers because these are not absolutely random. This module can be used to perform random movements which includes generating random numbers, print random a value for a listing or string, and so on.

Code Description & Execution

Program Methodology

We count on two players because the starting point in this dice rolling game. The sport starts with the rolling of the cube separately. At each iteration, we examine the rolling output of both the players. The player with the greater quantity receives the score incremented. And in the end, on the final generation, we calculate the scores of each the players to select the winner.

We will be utilizing Python because the programming language to create the game of cube.

The creation of the sport of cube includes the use and knowledge of the below programming concepts-

  • Creation and Updation of variables
  • Initialization of variables
  • Echo of facts almost about the development, and many others.
  • Apart from the above ideas, we are able to also be using the Python comparison operator to evaluate the scores of the gamer.

Before everything, we create and initialize  variables for the two players in the game.

We then import the random module with a view to make use of random.Randint() characteristic to roll the cube among 1 and 6 as the score.

We plan to have the above undertaking to appear iteratively 5 times before we pick the winner of the cube game. For this reason, we employ the variety() characteristic for the same. That is when the idea of generation comes into the photo.

We then evaluate the rating of the players with the aid of evaluating their cube roll out values. On the same time, we preserve recording their ratings in the variables to check at the cease of the remaining iteration. Here, we employ the selection technique to select the values through contrast based totally on sure conditions.

On the cease of the remaining iteration, we display the rankings of the players collated together for the duration of the iterations.

How to Execute?

Note: Make sure you have added a path while installing the software’s.

http://techieyantechnologies.com/2022/07/how-to-install-anaconda/

http://techieyantechnologies.com/2022/06/get-started-with-creating-new-environment-in-anaconda-configuring-jupyter-notebook-and-installing-libraries-using-requirements-txt-2/

  1. Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.
  2. Press windows key and type in anaconda prompt a terminal opens up.
  3. Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
  4. <<directory of your file:>>. E.g., If my file is in d drive, then.

  5. Type d:
Python dice rolling game for two players execution
  1. cd d:\License-Plate-Recognition-main    #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
Python dice rolling game for two players code execution

          7. If your project is in c drive, you can ignore step 4 and go with step 5

          8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name”.

Results

Python dice rolling game for two players result

Issues Faced

  1. We might face an issue while installing specific libraries, in this case, you might need to install the libraires manually. Example: pip install “module_name/library” i.e., pip install pandas
  2. Make sure you have the latest or specific version of python, since sometimes it might cause version mismatch.

Click Here To Download This Code And Associated File.

Conclusion

It’s a very popular game and there are many websites that allow users to play these games. Instead you can build the game by yourself to play or you can publish it . 

 

+91 7075575787