鱼C论坛

 找回密码
 立即注册
查看: 1173|回复: 4

[已解决]python

[复制链接]
发表于 2023-12-7 21:59:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
有没有会英文的大神帮我看一下final!
最佳答案
2023-12-7 22:04:50
pan11 发表于 2023-12-07 22:01
General considerations:
• Start the code ex ...

这是一个关于实现二人黑杰克/21点游戏的需求。根据要求,你需要编写一系列的函数,并在main()函数中调用这些函数。下面将逐个解释需要实现的函数及其功能。

a) instructions(): 这个函数应该简要介绍游戏规则和玩法。

b) makeADeckOf52()和shuffle: 这两个函数用于生成并洗牌一副有52个字符串元素的牌组。

c) update_hand_value(String c): 这个函数接受一个字符串参数,使用之前创建的字典来计算并更新玩家的手牌的黑杰克值。

d) dealAHand(deck): 这个函数从牌组中发出两张牌给玩家,并将这两张牌存入一个名为"hand"的列表。

e) displayHand(hand): 这个函数用于显示玩家的手牌。

f) bjHandValue(hand): 这个函数用于计算玩家手牌的总黑杰克值。

g) main(): 这个函数用于整个程序的流程控制,可以在其中声明并初始化玩家的名字和黑杰克值,调用dealAHand()、displayHand()和bjHandValue()等函数来进行发牌和计算黑杰克值的操作,并判断胜负。

根据题目要求,你还可以编写Player类来管理玩家对象的名字、手牌和黑杰克值等信息。

另外,在完成C级要求的基础上,你可以创建一个Card类,它具有rank(牌面)和suit(花色)两个属性。可以为Card类添加一个名为bjValue的整型属性,用于计算卡牌的黑杰克值。你还需要根据Card类对之前的函数进行适当的修改,使其能够处理Card对象。

在A级的要求中,你需要实现玩家可以选择是否继续要牌的功能。这意味着游戏将分为发牌和玩牌两个阶段。你需要在turn(deck)函数中实现这一部分的逻辑,直到玩家不再要牌或者手牌的黑杰克值超过21点为止。

最后,你需要在main函数中声明胜利者,即手牌总黑杰克值最高的玩家。

希望以上解释对你有所帮助!如果你需要更具体的代码示例,请告诉我,我会尽力提供给你。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-12-7 22:00:03 | 显示全部楼层
当然可以帮你看一下final!请你把需要帮助的代码或问题提供给我,我会尽力解答和帮助你的。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-7 22:01:32 | 显示全部楼层
General considerations:
• Start the code execution in a main() function
• Don’t use global variables.
• All variable names should be helpful (but don’t have to match variable names in functions)
• Use functions, loops, lists, classes whenever necessary to decrease repeated/ redundant code
• All functions must have small, well-defined tasks with appropriate function names
• You must document #INPUT, #PROCESS and #OUTPUT in all function definitions
• Don’t return more than one value from a function unless you can convince me that the function is
still a small, single tasked bundle of code
• Do not use break or return to get out of a loop

For credit in the C-/ C/C+ range:
Implement a Blackjack/21 game for two players, with cards dealt until one and/or the other go “bust”
(their cards in their hands total more than 21). You can use my makeADeckOf52()code (→ a list of 52
strings) and my create_BJValue_LookUp code (→ dictionary to look up any card’s black jack value; a
variation on Q9.9 solution). Look in the final project files folder for Exercise 9-9_adapted.py.
a) Implement this program with a series of function calls from main( ). For each function include a
description of the input, process and output
b) Write a Player class that has attributes for the Player’s name and a BlackJack hand value for their
hand (which will be updated every time they get a new card).
The functions must include:
c) instructions() Introduce the game and rules briefly using a function.
d) makeADeckOf52()and shuffle (you can use mine) to make a list of 52 strings like 7♣
e) update_hand_value(String c) using that dictionary to add to the blackjack value for each Player
Use my create_BJValue_LookUp()
f) Once you have these functions, write the initial setup for a single turn for one player by
i) Initializing the Player’s name and bjvalue=0.
ii) Write dealAHand(deck) that moves two items (‘cards’) from the deck to a list (‘hand’)
iii) Displaying the hand with displayHand(hand), e.g. 7♣Q♡
iv) Displaying total BJ value of the hand at the end of the turn with bjHandValue(hand) (e.g. 17
for the hand in (f.ii)) and save that value in the Player object
You will notice that the C code doesn’t actually play the game but sets it up with dealing a hand and
instantiating a single Player.

For more credit, in the B-/B/B+ range:
Do everything listed in the C program, but also
a) Write and use a Card Class with __init__( ), __str__( ) and at least two attributes: rank and suit
(both strings) . You can adapt makeADeckOf52() to generate rank/ suit pairs for each Card.
b) If you want, you can add a Card int attribute called bjValue that calculates the black jack value of
the card right when you construct the Card (Aces still low, i.e. bjValue is 1)
c) Adapt all functions to use that Card Class. You can use my makeADeckOf52(),
create_BJValue_LookUp()and your C-code dealAHand(), displayHand() and bjHandValue()
with slight modifications.
d) main() may not change at all for these changes so far, but also
e) Add the option for the single player to get another card (“hit me”) or not (“stay”) until the game
ends. You might notice that the game now has two parts: dealing and then playing. Write this
second part by giving player 1 cards until they declines a new card or goes bust (sum of card
bjValues worth > 21)

For more credit, in the A-/A range:
Do everything listed in the C and B programs (B program supersedes), but also write a turn(deck) function
that calculates and returns the player’s bjvalue (and the smaller deck):
a) Implement the ability for the player to ask for more cards, one at a time until
i) they don’t want more or
ii) the BlackJack value is >=21
b) Implement a Player class that keeps track of the hand, the hand value and the number of games
won and possibly the player’s name
c) Implement turn(deck)to easily include the second player (whose turn is completely after the 1st’s
player stops) and have them repeat these steps USING THE SAME FUNCTION and functions inside
turn for both players.
i) Deal a 2 card hand with dealAHand(deck)
ii) Display the hand (e.g. 7♣, Q♡) with, e.g. displayHand(hand)
iii) Request a card or hold
iv) Display the value of the cards at each move with bjHandValue(hand1)
f) Consider that the game has two parts: dealing and then playing. Write the second part by
i) giving player 1 cards until she declines a new card or goes bust (cards worth > 21)
ii) repeating the same for player 2
g) Back in main, declare the winner as the player who has the greatest Blackjack hand value <=21 or
tie.

Extra Credit:
Write the code that lets Aces be high (count as high) if the resulting hand value is less than 21;
otherwise, make Aces low (count as 1)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-7 22:04:50 | 显示全部楼层    本楼为最佳答案   
pan11 发表于 2023-12-07 22:01
General considerations:
&#8226; Start the code ex ...

这是一个关于实现二人黑杰克/21点游戏的需求。根据要求,你需要编写一系列的函数,并在main()函数中调用这些函数。下面将逐个解释需要实现的函数及其功能。

a) instructions(): 这个函数应该简要介绍游戏规则和玩法。

b) makeADeckOf52()和shuffle: 这两个函数用于生成并洗牌一副有52个字符串元素的牌组。

c) update_hand_value(String c): 这个函数接受一个字符串参数,使用之前创建的字典来计算并更新玩家的手牌的黑杰克值。

d) dealAHand(deck): 这个函数从牌组中发出两张牌给玩家,并将这两张牌存入一个名为"hand"的列表。

e) displayHand(hand): 这个函数用于显示玩家的手牌。

f) bjHandValue(hand): 这个函数用于计算玩家手牌的总黑杰克值。

g) main(): 这个函数用于整个程序的流程控制,可以在其中声明并初始化玩家的名字和黑杰克值,调用dealAHand()、displayHand()和bjHandValue()等函数来进行发牌和计算黑杰克值的操作,并判断胜负。

根据题目要求,你还可以编写Player类来管理玩家对象的名字、手牌和黑杰克值等信息。

另外,在完成C级要求的基础上,你可以创建一个Card类,它具有rank(牌面)和suit(花色)两个属性。可以为Card类添加一个名为bjValue的整型属性,用于计算卡牌的黑杰克值。你还需要根据Card类对之前的函数进行适当的修改,使其能够处理Card对象。

在A级的要求中,你需要实现玩家可以选择是否继续要牌的功能。这意味着游戏将分为发牌和玩牌两个阶段。你需要在turn(deck)函数中实现这一部分的逻辑,直到玩家不再要牌或者手牌的黑杰克值超过21点为止。

最后,你需要在main函数中声明胜利者,即手牌总黑杰克值最高的玩家。

希望以上解释对你有所帮助!如果你需要更具体的代码示例,请告诉我,我会尽力提供给你。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-10 03:18:57 | 显示全部楼层
可以给点详细代码吗
我怎么样可以做到让两个玩家都参与游戏?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-8 11:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表