国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

ホームページ バックエンド開発 Python チュートリアル 楽しいターミナル限定のサイコロゲーム

楽しいターミナル限定のサイコロゲーム

Nov 14, 2024 pm 02:24 PM

Fun terminal only dice game

これは初期のプロジェクトの 1 つです。プログラミングに関しては、まださまざまな要素を理解しているところです。

これは、カインドムカムデリバランスのサイコロゲームをベースに作った楽しいサイコロゲームです。ターミナルのみで作成しました。その主な理由は、私がまだオープン gl やその他のグラフィカル出力を使用しようとしているという事実です。

フィードバックは大歓迎です。


import random


# menu to welcome the player
def menu():
    print("""
    Welcome to dice\n
      Would you like to: \n
         1. Review the rule, \n
         2. play a new game \n
         3. review scoring of dice \n
         """)
    try:
        menu_choice = input("")
    except EOFError:
        print("No input received. Please run the program in an interactive environment.")
        return
    if menu_choice == "1":
        print_rules()
    elif menu_choice == "2":
        new_game()
    elif menu_choice == "3":
        print_scroing_values()
        second_meu()
    else:
        print("Invalid choice please choose again")
        second_meu()


#second menu to allow for a alteration of language

def second_meu():
    print("""
  What would you like to do now?
      Would you like to: \n
         1. Review the rule, \n
         2. play a new game \n
         3. review scoring of dice \n
         """)
    menu_choice = input("Please enter your choice: ")
    if menu_choice == "1":
        print_rules()
    elif menu_choice == "2":
        new_game()
    elif menu_choice == "3":
        print_scroing_values()
        second_meu()
    else:
        print("Invalid choice please choose again")
        second_meu()

#explantion of rules
def print_rules():
    print("""
  A player's turn always begins by throwing all six dice. The player then selects and set aside scoring dice, and at least one die must always be set aside. Then the player can throw the remaining dice again and the situation repeats. \n

  Scoring combinations are counted only for the current throw, not the entire turn.\n

  The key element of the game is that if a throw does not produce a single scoring die, then the player's turn is over and all points scored up to that throw are forfeit. It is then the opposing player's turn to throw. \n

  For that reason, it's best to end your turn before the risk that not a single die will score gets too high. Sometimes it's better not to set aside all the scoring dice you you've thrown, so you stand a better chance of scoring higher on the next throw.\n\n
  """)
    second_meu()

#and the scroing system
def print_scroing_values():
    print("""Scoring is as follows:
    - a single 1 is worth 100 points; \n
    - a single 5 is worth 50 points; \n
    - three of a kind is worth 100 points multiplied by the given number, e.g. three 4s are worth 400 points; \n
    - three 1s are worth 1,000 points;\n
    - four or more of a kind is worth double the points of three of a kind, so four 4s are worth 800 points, five 4s are worth 1,600 points etc.\n
    - full straight 1-6 is worth 1500 points.\n
    - partial straight 1-5 is worth 500 points.\n
    - partial straight 2-6 is worth 750 points.\n\n """)


# This die clas allows funtionality to roll a six sided dice and output the value.
class die:
    def __init__(self):
        self.value = 0

    def __repr__(self):
        return f"{self.value}"

    def roll(self):
        self.value = random.randint(1, 6)



#here is where the class objects are created and organised into a list for ease of use.
die1 = die()
die2 = die()
die3 = die()
die4 = die()
die5 = die()
die6 = die()

dice = [die1, die2, die3, die4, die5, die6]


#player class hold the dice values, the player name a method for rolling all 6 dice at one and rerolling specific dice.
class player:
    def __init__(self, name, dice_list, score=4000):
        self.name = name
        self.score = score
        self.dice_list = dice_list

    def deduct_score(self, deduction):
        self.score -= deduction
        return self.score

    def roll_d6(self):
        roll_string: str = ""                  #this funtion rolls all the dice coverts them to string and labels them 1 to 6 producing eg 1: 6, 2: 6, 3: 1, 4: 2, 5: 3, 6: 2
        i = 1
        for die in dice:
            die.roll()
            data = die.value
            str_data = str(data)
            str_i = str(i)
            roll_string += str_i + ": " + str_data + ", "
            i += 1
        return roll_string

    def print_d6(self):                                     #just print the values
        roll_string: str = ""
        i = 1
        for die in dice:
            data = die.value
            str_data = str(data)
            str_i = str(i)
            roll_string += str_i + ": " + str_data + ", "
            i += 1
        return roll_string


    def re_roll(self, index):                         #re rolls dice speficed
        index-=1
        dice[index].roll()
        return dice[index].value


#This is the main game loop it has a lot of moving parts. Take your time reviewing.
def new_game():
    print("Hi so what is your name?\n")
    human_name = input("")
    human_player = player(human_name, dice, 4000)   #creating objects for both human and computer players in the player class
    print("who do you wish to play against?")
    computer_name = input("")
    computer_player = player(computer_name, dice, 4000)
    play = True
    while (play):
        print("""ok here is your roll: 
    you roll a: """)
        print(human_player.roll_d6())     #use of the player class function roll_d6 to give a string of rolled dice
        print("Time to score you dice")
        total_dice_score = possible_to_score(human_player.dice_list)   #this function is below and check to see if any of the dice can score
        print(total_dice_score)
        print("Whould you like to re-roll you any dice? Y/N")  #allowing the player a chance to re roll dice
        lroll = input("")
        roll = lroll.upper()
        if (roll == "Y"):
            dice_choice(human_player)
        #print(dice)
        print("Time to score you dice")
        total_dice_score = possible_to_score(dice)
        print(total_dice_score)
        human_player.deduct_score(total_dice_score)
        print(f"Your score is now {human_player.score}")
        print(f"Ok it's {computer_player.name} go they rolled")
        print(computer_player.roll_d6())
        print("They scored:")
        total_dice_score = possible_to_score(dice)
        print(total_dice_score)
        computer_player.deduct_score(total_dice_score)
        print(f"{computer_player.name} score is now {computer_player.score}")
        input("")
        if human_player.score <= 0 or computer_player.score <= 0:
            if human_player.score <= 0:
                print("You win well done!!")
            else:
                print("You lose to bad.")
            play = False



def possible_to_score(dice):    #dice is a alis for eaither human_player.dice_list or computer_player.dice_list which would look like [1, 2, 3, 4, 5, 6] with random numbers beteen 1 and 6 in each index.
    dice_score = 0
    numbers = count(dice)   #this function count the number of each dice rolled is is a little complex
    #print(dice)             #more functionality checking
    #print(numbers)
    isone = one(numbers)      #each of these are seperate function that check for andy 1s, 5s, any kinds e.g. dice that rolled the same number like four 5s, a full straight or a parital stright
    isfive = five(numbers)
    isthree_of_kind = three_of_kind(numbers)
    isfour_of_kind = four_of_kind(numbers)
    isfive_of_kind = five_of_kind(numbers)
    issix_of_kind = six_of_kind(numbers)
    isfull_straight = full_straight(numbers)
    isone_to_five = one_to_five(numbers)
    istwo_to_six = two_to_six(numbers)
    #print(isone, isfive, isthree_of_kind, isfour_of_kind, isfive_of_kind, issix_of_kind, isfull_straight, isone_to_five, istwo_to_six)      #used this to check the function was working in construction
    if (isone == True):
        dice_score = 10

    if (isfive == True):
        dice_score = 50

    if (isthree_of_kind[0] == True):
        dice_score = 100 * isthree_of_kind[1]    #these function woudl assign score to the dice depeding on valibles

    if (isfour_of_kind[0] == True):
        dice_score = 200 * isfour_of_kind[1]

    if (isfive_of_kind[0]):
        dice_score = 400 * isfive_of_kind[1]

    if (issix_of_kind[0]):
        dice_score = 800 * issix_of_kind[1]

    if (isfull_straight == True):
        temp_dice_score = 1500
        if temp_dice_score > dice_score:
            dice_score = temp_dice_score

    if (isone_to_five == True):
        temp_dice_score = 500
        if temp_dice_score > dice_score:
            dice_score = temp_dice_score
    if (istwo_to_six == True):
        temp_dice_score = 600

        if temp_dice_score > dice_score:
            dice_score = temp_dice_score
    return dice_score

def one(counts):
    if counts[0] >= 1:
        return True
    else:
        return False

def five(counts):
    if counts[4] >= 1:
        return True
    else:
        return False


def three_of_kind(counts):
    if 3 in counts:
        return True, counts.index(3)
    else:
        return False, None


def four_of_kind(counts):
    if 4 in counts:
        return True, counts.index
    else:
        return False, None


def five_of_kind(counts):
    if 5 in counts:
        return True, counts.index
    else:
        return False, None


def six_of_kind(counts):
    if 6 in counts:
        return True, counts.index
    else:
        return False, None


def full_straight(counts):
    if all(value == 1 for value in counts):
        return True
    else:
        return False

def one_to_five(counts):
    if counts[0] <= 1 & counts[1] <= 1 & counts[2] <= 1 & counts[3] <= 1 & counts[4] <= 1:
        return True
    else:
        return False


def two_to_six(counts):
    if counts[1] <= 1 & counts[2] <= 1 & counts[3] <= 1 & counts[4] <= 1 & counts[5] <= 1:
        return True
    else:
        return False

def count(dice):                   #dice is a alis for eaither human_player.dice_list or computer_player.dice_list which would look like [1, 2, 3, 4, 5, 6] with random numbers beteen 1 and 6 in each index.
    value_counts = count_values(dice)
    num_ones = value_counts[1]         #the job of this to take the 1: prefix to all the counts to leave behind only the count itself
    num_twos = value_counts[2]
    num_threes = value_counts[3]
    num_fours = value_counts[4]
    num_fives = value_counts[5]
    num_sixes = value_counts[6]
    numbers_list = [num_ones, num_twos, num_threes, num_fours, num_fives, num_sixes]
    return numbers_list   #this goes back to new game

def count_values(dice_list):
    counts = {i: 0 for i in range(1, 7)}     #this created this {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
    for die in dice_list:
        counts[die.value] += 1 #assins each of the dice to a value in numerical order eg of output {1: 1, 2: 1, 3: 2, 4: 1, 5: 1, 6: 0}
    return counts

def dice_choice(player):    #alis for human_player
    rolling = True
    print("Please type the dice you want to re-roll after each choice press enter. When you finish type exit and press enter.")
    while (rolling):
        player_input = input("")
        if player_input.isdigit():                     #checks is the input is a number
            number = int(player_input)
            if 1 <= number <= 6:                        #checks if it falls between 1 and 6
                player.re_roll(number)                         #rolls the dice specified
            else:
                print("Invalid entry must be a value between 1 and 6")
        elif player_input == "exit":
            print(f"Your new values are: {player.print_d6()} .")              #outputs the results
            rolling = False
        else:
            print("invalid entry must be a number or exit, please try again.")


menu()


以上が楽しいターミナル限定のサイコロゲームの詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國語 Web サイトの他の関連記事を參照してください。

このウェブサイトの聲明
この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當(dāng)する法的責(zé)任を負(fù)いません。盜作または侵害の疑いのあるコンテンツを見つけた場(chǎng)合は、admin@php.cn までご連絡(luò)ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫像を無料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡(jiǎn)単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中國語版

SublimeText3 中國語版

中國語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強(qiáng)力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Pythonの不適格またはPytestフレームワークは、自動(dòng)テストをどのように促進(jìn)しますか? Pythonの不適格またはPytestフレームワークは、自動(dòng)テストをどのように促進(jìn)しますか? Jun 19, 2025 am 01:10 AM

Pythonの不適格でPytestは、自動(dòng)テストの書き込み、整理、および実行を簡(jiǎn)素化する2つの広く使用されているテストフレームワークです。 1.両方とも、テストケースの自動(dòng)発見をサポートし、明確なテスト構(gòu)造を提供します。 pytestはより簡(jiǎn)潔で、テスト\ _から始まる関數(shù)が必要です。 2。それらはすべて組み込みのアサーションサポートを持っています:Unittestはアサートエクイアル、アサートトルー、およびその他の方法を提供しますが、Pytestは拡張されたアサートステートメントを使用して障害の詳細(xì)を自動(dòng)的に表示します。 3.すべてがテストの準(zhǔn)備とクリーニングを処理するためのメカニズムを持っています:un

Pythonは、NumpyやPandasなどのライブラリとのデータ分析と操作にどのように使用できますか? Pythonは、NumpyやPandasなどのライブラリとのデータ分析と操作にどのように使用できますか? Jun 19, 2025 am 01:04 AM

pythonisidealfordataanalysisduetonumpyandpandas.1)numpyexcelsatnumericalcompitations withfast、多次元路面およびベクトル化された分離likenp.sqrt()

動(dòng)的なプログラミング技術(shù)とは何ですか?また、Pythonでそれらを使用するにはどうすればよいですか? 動(dòng)的なプログラミング技術(shù)とは何ですか?また、Pythonでそれらを使用するにはどうすればよいですか? Jun 20, 2025 am 12:57 AM

動(dòng)的プログラミング(DP)は、複雑な問題をより単純なサブ問題に分解し、結(jié)果を保存して繰り返し計(jì)算を回避することにより、ソリューションプロセスを最適化します。主な方法は2つあります。1。トップダウン(暗記):?jiǎn)栴}を再帰的に分解し、キャッシュを使用して中間結(jié)果を保存します。 2。ボトムアップ(表):基本的な狀況からソリューションを繰り返し構(gòu)築します。フィボナッチシーケンス、バックパッキングの問題など、最大/最小値、最適なソリューション、または重複するサブ問題が必要なシナリオに適しています。Pythonでは、デコレータまたはアレイを通じて実裝でき、再帰的な関係を特定し、ベンチマークの狀況を定義し、空間の複雑さを最適化することに注意する必要があります。

__iter__と__next__を使用してPythonにカスタムイテレーターを?qū)g裝するにはどうすればよいですか? __iter__と__next__を使用してPythonにカスタムイテレーターを?qū)g裝するにはどうすればよいですか? Jun 19, 2025 am 01:12 AM

カスタムイテレーターを?qū)g裝するには、クラス內(nèi)の__iter__および__next__メソッドを定義する必要があります。 __iter__メソッドは、ループなどの反復(fù)環(huán)境と互換性があるように、通常は自己の反復(fù)オブジェクト自體を返します。 __next__メソッドは、各反復(fù)の値を制御し、シーケンスの次の要素を返し、アイテムがもうない場(chǎng)合、停止例外をスローする必要があります。 statusステータスを正しく追跡する必要があり、無限のループを避けるために終了條件を設(shè)定する必要があります。 fileファイルラインフィルタリングなどの複雑なロジック、およびリソースクリーニングとメモリ管理に注意を払ってください。 simple単純なロジックについては、代わりにジェネレーター関數(shù)の収率を使用することを検討できますが、特定のシナリオに基づいて適切な方法を選択する必要があります。

Pythonプログラミング言語とそのエコシステムの新たな傾向または將來の方向性は何ですか? Pythonプログラミング言語とそのエコシステムの新たな傾向または將來の方向性は何ですか? Jun 19, 2025 am 01:09 AM

Pythonの將來の傾向には、パフォーマンスの最適化、より強(qiáng)力なタイププロンプト、代替ランタイムの増加、およびAI/MLフィールドの継続的な成長が含まれます。第一に、CPYTHONは最適化を続け、スタートアップのより速い時(shí)間、機(jī)能通話の最適化、および提案された整數(shù)操作を通じてパフォーマンスを向上させ続けています。第二に、タイプのプロンプトは、コードセキュリティと開発エクスペリエンスを強(qiáng)化するために、言語とツールチェーンに深く統(tǒng)合されています。第三に、PyscriptやNuitkaなどの代替のランタイムは、新しい機(jī)能とパフォーマンスの利點(diǎn)を提供します。最後に、AIとデータサイエンスの分野は拡大し続けており、新興図書館はより効率的な開発と統(tǒng)合を促進(jìn)します。これらの傾向は、Pythonが常に技術(shù)の変化に適応し、その主要な位置を維持していることを示しています。

ソケットを使用してPythonでネットワークプログラミングを?qū)g行するにはどうすればよいですか? ソケットを使用してPythonでネットワークプログラミングを?qū)g行するにはどうすればよいですか? Jun 20, 2025 am 12:56 AM

Pythonのソケットモジュールは、クライアントおよびサーバーアプリケーションの構(gòu)築に適した低レベルのネットワーク通信機(jī)能を提供するネットワークプログラミングの基礎(chǔ)です。基本的なTCPサーバーを設(shè)定するには、Socket.Socket()を使用してオブジェクトを作成し、アドレスとポートをバインドし、.listen()を呼び出して接続をリッスンし、.accept()を介してクライアント接続を受け入れる必要があります。 TCPクライアントを構(gòu)築するには、ソケットオブジェクトを作成し、.connect()を呼び出してサーバーに接続する必要があります。次に、.sendall()を使用してデータと.recv()を送信して応答を受信します。複數(shù)のクライアントを処理するには、1つを使用できます。スレッド:接続するたびに新しいスレッドを起動(dòng)します。 2。非同期I/O:たとえば、Asyncioライブラリは非ブロッキング通信を?qū)g現(xiàn)できます。注意すべきこと

Pythonクラスの多型 Pythonクラスの多型 Jul 05, 2025 am 02:58 AM

Pythonオブジェクト指向プログラミングのコアコンセプトであるPythonは、「1つのインターフェイス、複數(shù)の実裝」を指し、異なるタイプのオブジェクトの統(tǒng)一処理を可能にします。 1。多型は、メソッドの書き換えを通じて実裝されます。サブクラスは、親クラスの方法を再定義できます。たとえば、Animal ClassのSOCK()方法は、犬と貓のサブクラスに異なる実裝を持っています。 2.多型の実用的な用途には、グラフィカルドローイングプログラムでdraw()メソッドを均一に呼び出すなど、コード構(gòu)造を簡(jiǎn)素化し、スケーラビリティを向上させる、ゲーム開発における異なる文字の共通の動(dòng)作の処理などが含まれます。 3. Pythonの実裝多型を満たす必要があります:親クラスはメソッドを定義し、子クラスはメソッドを上書きしますが、同じ親クラスの継承は必要ありません。オブジェクトが同じ方法を?qū)g裝する限り、これは「アヒル型」と呼ばれます。 4.注意すべきことには、メンテナンスが含まれます

Pythonでリストをスライスするにはどうすればよいですか? Pythonでリストをスライスするにはどうすればよいですか? Jun 20, 2025 am 12:51 AM

Pythonリストスライスに対するコアの答えは、[start:end:step]構(gòu)文をマスターし、その動(dòng)作を理解することです。 1.リストスライスの基本形式はリスト[start:end:step]です。ここで、開始は開始インデックス(含まれています)、endはend index(含まれていません)、ステップはステップサイズです。 2。デフォルトで開始を省略して、0から開始を開始し、デフォルトで終了して終了し、デフォルトでステップを1に省略します。 3。my_list[:n]を使用して最初のnアイテムを取得し、my_list [-n:]を使用して最後のnアイテムを取得します。 4.ステップを使用して、my_list [:: 2]などの要素をスキップして、均一な數(shù)字と負(fù)のステップ値を取得できます。 5.一般的な誤解には、終了インデックスが含まれません

See all articles