I tried to refer to the fun rock-paper-scissors poi for beginners with Python

The scene was so free that I remembered an acquaintance making a rock-paper-scissors game.

Referenced articles

@ sandream's article "Python rock-paper-scissors poi for beginners (answers and explanations) " It is a rule of winning three times against a rock-paper-scissors kid. How @sandream came to write an article about rock-paper-scissors, Please refer to the above article for a detailed explanation of the overall function.

code

janken.py


#_*_ coding: utf-8 _*_

import random
import time

dic = {'a':'Goo','b':'Choki','c':'Par'}

#Get a list of hands you can put out
def clist(hands):
    ls =[]
    for i in hands:
        ls.append(i)
    return ls

#Hand message that can be issued
comm_mess = str(','.join(dic))+'Please enter one of them!'

#Victory end message
def good_end():
    mess = str(\
        'Stupid! !!\n'\
        'Rock-paper-scissors-rock-paper-scissors is a rock-paper-scissors game. !!\n'\
        'Hidebu!\n'\
    )
    return mess

#Defeat end message
def bad_end():
    mess = str(\
        'It ’s your bonus! !!\n'\
        'Please clarify the cause and submit the defeat deterrence checklist by 10 am tomorrow morning.\n'\
    )
    return mess

#Rock-paper-scissors kid Esper mode
def kozou_tsuyoi(uch,pch,uco,pco):
    #Rock-paper-scissors kid Esper mode message
    kozou_mess1 = ('Shit ~! Don't mess with rock-paper-scissors! !!')
    #Rock-paper-scissors kid super esper mode message
    kozou_mess2 = ('You can see it! I can see you! !!')
    _random =random.random()
    #Branch to the player's winning star, the kid's winning star, and the hand
    if uco == 2 and pco <= 1 and uch == dic['a']:
        print(kozou_mess1)
        hands = dic['c']
    elif uco == 2 and pco <= 1 and uch == dic['b']:
        print(kozou_mess1)
        hands = dic['a']
    elif uco == 2 and pco <= 1 and uch == dic['c']:
        print(kozou_mess1)
        hands = dic['b']
    #Rock-paper-scissors kid goes into super esper mode
    elif _random < 0.01 and uch == dic['a']:
        print(kozou_mess2)
        hands = dic['c']
    elif _random < 0.01 and uch == dic['b']:
        print(kozou_mess2)
        hands = dic['a']
    elif _random < 0.01 and uch == dic['c']:
        print(kozou_mess2)
        hands = dic['b']
    else:
        hands = pch
    return hands

choice_list = clist(dic)
judge = None
player_win ='You WIN !!\n'
player_lose ='You LOSE !!\n'
player_draw ='DRAW !!\n'

user_co = 0
pc_co = 0
print(\
'I'm rock-paper-scissors\n'\
'Let's play rock-paper-scissors\n'\
'It ’s better to have 3 before\n'\
)

for i in clist(dic):
    print (i+'Is'+' '+dic[i])
time.sleep(2)
print(comm_mess+'\n')

while True:
    if judge == player_draw:
        print('Ah! Kodetsu! !!')
    else:
        print('Jean! Ken! !!')
    
    #Player chooses a hand
    print('(What are you going to do !?')
    user = input(':')
    user_choice = user.lower()
    try:
        user_choice = dic[user]
    except:
        print(comm_mess)
        continue
    
    #Rock-paper-scissors kid chooses a hand
    pc_choice = dic[str(random.choice(clist(dic)))]
    
    #Rock-paper-scissors kid Esper mode
    _random = random.random()
    if _random < 0.5:
        pc_choice = kozou_tsuyoi(user_choice,pc_choice,user_co,pc_co)
    
    if judge == player_draw:
        print('Shock! !!')
    else:
        print('Poit! !!')
    time.sleep(1.5)
    
    #Check your hands
    print(\
    'Player's choice:'+str(user_choice)+'\n'\
    'Rock-paper-scissors elephant's hand:'+str(pc_choice)+'\n'\
    )
    time.sleep(1.5)
    
    #Win / loss judgment
    if user_choice == pc_choice:
        judge = player_draw
        print(player_draw)
    elif user_choice == dic['a']:
        if pc_choice ==dic['b']:
            judge = player_win
            print(player_win)
            user_co += 1
        elif pc_choice == dic['c']:
            judge = player_lose
            print(player_lose)
            pc_co += 1
        else:
            print('Rock-paper-scissors law is disturbed! A')
    elif user_choice == dic['b']:
        if pc_choice ==dic['c']:
            judge = player_win
            print(player_win)
            user_co += 1
        elif pc_choice == dic['a']:
            judge = player_lose
            print(player_lose)
            pc_co += 1
        else:
            print('Rock-paper-scissors law is disturbed! B')
    elif user_choice == dic['c']:
        if pc_choice ==dic['a']:
            judge = player_win
            print(player_win)
            user_co += 1
        elif pc_choice == dic['b']:
            judge = player_lose
            print(player_lose)
            pc_co += 1
        else:
            print('Rock-paper-scissors law is disturbed! C')
    else:
        print('Rock-paper-scissors law is disturbed! D')
    
    print(\
    'Number of player wins:'+str(user_co)+'\n'\
    'Number of rock-paper-scissors wins:'+str(pc_co)+'\n'\
    )
    time.sleep(1.5)
    
    #Progress-based event (thinking)
    
    #Ending judgment
    if user_co == 3:
        print(good_end())
        break
    elif pc_co == 3:
        print(bad_end())
        break

print('THE END')

When I tried it with Repl.it, it seemed to work as expected, so Yoshi! 無題.png

Tokucho

Choosing a simple choice is chaotic enough, which is interesting. Speaking of rock-paper-scissors games that were in the arcade, it's *** the unreasonable strength of the opponent ***. It is a thing that was often rolled up by medal games in the past. I added such a function.

Esper function

Name it *** Esper function *** It executes a function at random and activates when certain conditions are met. Around ↓

def kozou_tsuyoi(uch,pch,uco,pco):
    _random =random.random()
    #Branch to the player's winning star, the kid's winning star, and the hand
    if uco == 2 and pco <= 1 and uch == dic['a']:
        hands = dic['c']
    #Random value
    elif _random < 0.01 and uch == dic['a']:
        hands = dic['c']
    else:
        hands = pch
    return hands

The conditions are divided, but the design is as follows.

*** I think that you can make it unreasonable strength by loosening the activation conditions and branching conditions. *** ***

It's not fun to change it 100% according to the player's hand. I changed it a little.

The part I care about

while True bomb

Because the condition of loop exit is *** win or lose ***, which is a masculine specification I left the input restrictions for the articles I referred to.

if branch else escape

Since there are a lot of branches, I am doing something like exception handling by giving if else else. Well, even so, the game won't end unless you win or lose ***.

Finally

Those who lost to rock-paper-scissors kid in rock-paper-scissors Please clarify the cause and submit the defeat deterrence checklist by 10 am tomorrow morning.

Recommended Posts

I tried to refer to the fun rock-paper-scissors poi for beginners with Python
I tried to solve the ant book beginner's edition with python
[Pandas] I tried to analyze sales data with Python [For beginners]
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I tried to divide the file into folders with Python
[For beginners in competition professionals] I tried to solve 40 AOJ "ITP I" questions with python
I tried to improve the efficiency of daily work with Python
I tried running the TensorFlow tutorial with comments (_TensorFlow_2_0_Introduction for beginners)
I tried "smoothing" the image with Python + OpenCV
The fastest way for beginners to master Python
vprof --I tried using the profiler for Python
I tried "differentiating" the image with Python + OpenCV
I tried to save the data with discord
I tried to get CloudWatch data with Python
I tried python programming for the first time.
I tried to output LLVM IR with Python
I tried to get the authentication code of Qiita API with Python.
I tried "binarizing" the image with Python + OpenCV
I tried to automate sushi making with python
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to streamline the standard role of new employees with Python
I tried to get the movie information of TMDb API with Python
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried searching for files under the folder with Python by file name
I tried to automatically send the literature of the new coronavirus to LINE with Python
python beginners tried to predict the number of criminals
I tried to graph the packages installed in Python
I tried Python on Mac for the first time.
I tried the MNIST tutorial for beginners of tensorflow.
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to draw a route map with Python
I tried python on heroku for the first time
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
I want to inherit to the back with python dataclass
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to automatically generate a password with Python3
I tried to analyze J League data with Python
I tried hitting the API with echonest's python client
I tried to summarize the string operations of Python
I tried to solve AOJ's number theory with Python
I tried fp-growth with python
I tried scraping with Python
I tried gRPC with Python
I tried scraping with python
~ Tips for beginners to Python ③ ~
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to put out the frequent word ranking of LINE talk with Python
I tried to automate the article update of Livedoor blog with Python and selenium.
I tried to find out how to streamline the work flow with Excel x Python ①
[For beginners] Web scraping with Python "Access the URL in the page to get the contents"
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to compare the processing speed with dplyr of R and pandas of Python
I tried to build an environment for machine learning with Python (Mac OS X)
The 15th offline real-time I tried to solve the problem of how to write with python