vb掷骰子程序编写

vb掷骰子程序编写,第1张

我这是 NET 2015 的:

Public 你的选择 As Boolean

Public 掷色子数 As Integer

Public 你的本金 As Integer

Public 你的投注 As Integer

Public 色子结果 As Boolean

Private Sub 开始按钮_Click(sender As Object, e As EventArgs) Handles 开始按钮Click

Randomize()

你的投注 = CInt(扣除标签Text)

你的本金 = CInt(本金标签Text)

If 你的投注 > 你的本金 Then

MsgBox("你投注过大!")

你的投注 = 0

扣除标签Text = 0

Exit Sub

ElseIf 你的投注 <= 你的本金

If 大选项Checked = True Then

你的选择 = True

Else

你的选择 = False

End If

掷色子数 = CInt(Int((6 Rnd()) + 1))

色子数Text = 掷色子数

If 掷色子数 >= 4 Then

色子结果 = True

Else

色子结果 = False

End If

If 色子结果 = 你的选择 Then

你的本金 += 你的投注 2

Else

你的本金 -= 你的投注

End If

本金标签Text = 你的本金ToString

End If

End Sub

参考下面的代码

play 可能有问题,主要是没说清楚在保留牌的时候, 输入Ace 或者 "Ace Ace" 有什么区别,到底是输入一次 Ace 保留手上所有的 Ace 还是只保留一个,这个没说清楚。看例子,这两种用法都有,我按照输入了几个就保留几个来做的。

simulate 没问题,和中的结果完全一样

必须用 python 3

import random

import collections

_dice_type = ['Ace', 'King', 'Queen', 'Jack', '10', '9']

_hand_mapping = collectionsOrderedDict([

    ('5kind',    'Five of a kind'),

    ('4kind',    'Four of a kind'),

    ('full',     'Full house'),

    ('straight', 'Straight'),

    ('3kind',    'Three of a kind'),

    ('2pair',    'Two pair'),

    ('1pair',    'One pair'),

    ('bust',     'Bust'),

])

def _check_hand(dices):

    counter = collectionsCounter(dices)

    if len(counter) == 1:

        return '5kind'

    sorted5 = countermost_common(5)

    if sorted5[0][1] == 4:

        return '4kind'

    if sorted5[0][1] == 3:

        if sorted5[1][1] == 2:

            return 'full'

        else:

            return '3kind'

    if sorted5[0][1] == 2:

        if sorted5[1][1] == 2:

            return '2pair'

        else:

            return '1pair'

    if len(counter) == 5:

        dtype = sorted5[0][0]

        for x in sorted5:

            if dtype != x[0]:

                break

            dtype += 1

        else:

            return 'straight'

            

    return 'bust'

def play():

    dices = []

    retry = 0

    while True:

        remain = 5 - len(dices)

        if remain <= 0:

            break

            

        dicesextend([randomrandint(0,5) for x in range(remain)])

        

        print("The roll is: {}"format(

            " "join([_dice_type[d] for d in sorted(dices)])

        ))

        print("It is a {}"format(_hand_mapping[_check_hand(dices)]))

        if retry > 1:

            break

        

        prompt = "Which dice do you want to keep for the {} roll "format(

            "second" if retry == 0 else "third"

        )

        while True:

            answer = input(prompt)lower()

            if answer == 'all':

                break

            answer = [xcapitalize() for x in answersplit()]

            if set(answer)issubset(set(_dice_type)):

                break

            print("That is not possible, try again!")

        retry += 1

        if answer == 'all':

            print("Ok, done")

            break

        tmp = dices

        dices = []

        for x in tmp:

            if _dice_type[x] in answer:

                dicesappend(x)

                answerremove(_dice_type[x])

def simulate(n, debug=False):

    result = dictfromkeys(_hand_mappingkeys(), 0)

    for _ in range(n):

        dices = [randomrandint(0,5) for x in range(5)]

        if debug:

            print("DEBUG:", " "join([_dice_type[d] for d in sorted(dices)]))

        result[_check_hand(dices)] += 1

    for k, v in _hand_mappingitems():

        cnt = result[k]

        print("{:<16s}: {:2f}%"format(v, 100cnt/n))

以上就是关于vb掷骰子程序编写全部的内容,包括:vb掷骰子程序编写、怎样python 写一个扑克和骰子的程序,模拟的5骰子的滚动,至多三次,具体要求如下:、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10219979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存