跳至主要內容

University of Pennsylvania Homework 3 Water Tank

AI悦创原创2023年9月20日Python辅导University of PennsylvaniaPython辅导University of Pennsylvania大约 22 分钟...约 6594 字

Homework 3: Water Tank

(Deadline as per Canvas)

This homework covers concepts learned in Modules 1-3. In this homework, we will be implementing the game Water Tank, a card-based game.

这份作业涵盖了第1-3模块所学的概念。在这个作业中,我们将实现一款名为水箱的基于卡片的游戏。

About the Assignment

Water Tank is a competitive card game played between two players. In your case, the players will be a human player and a computer player. Each player starts with an empty water tank, which they need to fill. The goal is to be the first player to fill their tank. A tank is filled if it reaches the value of 75 to 80 units (inclusive). The human player’s moves are decided by the user playing the game, by asking for input, and the computer’s moves are decided by the program that you will write.

水箱是一款两名玩家之间的竞争性卡牌游戏。在您的情况下,玩家将是一名人类玩家和一名电脑玩家。每位玩家开始时都有一个空的水箱,他们需要填满它。目标是成为第一个填满水箱的玩家。当水箱达到75至80单位(包括)时,它就算是被填满了。人类玩家的动作是由玩这个游戏的用户决定的,通过请求输入,而电脑玩家的动作则是由您将要编写的程序决定的。

For the section that asks you to program a strategy for the computer, what we want you to do is come up with a reasonable enough strategy that ensures that a computer makes a logical decision. Example, if the computer’s tank is missing just 1 unit of water to fill the tank, and that card happens to be in the computer’s hand, then the computer should use that card in their move. So, unlike your previous assignments, this one has a creative component to it.

对于要求你为计算机编程策略的部分,我们希望你能提出一个足够合理的策略,确保计算机作出逻辑决策。例如,如果计算机的水箱仅缺少1单位的水来填满,并且该卡恰好在计算机的手中,那么计算机应该在它的动作中使用那张卡。所以,与你之前的任务不同,这次的任务有创意的成分在里面。

There are two types of cards: water cards and power cards. There will be a pile for each type of card (one pile for water and one pile for power). Each water card has a value that represents the amount of water that it contributes to the tank. When a water card is played, that player adds the specified amount of water to their tank. Power cards allow players to perform special actions:

这有两种类型的卡片:水卡和能量卡。每种卡片都会有一个堆叠(一个水卡堆,一个能量卡堆)。每张水卡都有一个代表其为水箱增加的水量的值。当玩家打出一张水卡时,他们会按照卡上指定的数量为自己的水箱加水。能量卡允许玩家执行特殊动作:

Players take turns either using a card or discarding a card. If a player discards a card, it goes to the bottom (last index) of its respective pile. Once the player has used or discarded a card, they draw a new card, from the top of the pile (index 0), of the same type as the card they just used or discarded.

玩家轮流使用或丢弃一张卡片。如果玩家丢弃一张卡片,它将被放到相应堆的最底部(最后一个位置)。一旦玩家使用或丢弃了一张卡片,他们将从堆的顶部(索引0)抽取一张与刚才使用或丢弃的卡片同类型的新卡片。

If a player’s water level exceeds their tank’s maximum fill value, an overflow happens. In the case of an overflow, extra water sloshes out of the tank. The amount of water that remains in the tank is determined by a formula: remaining water = maximum fill value - overflow

如果玩家的水位超过了水箱的最大容量,就会发生溢出。在溢出的情况下,多余的水会从水箱中溢出。水箱中剩余的水量由以下公式决定:剩余水量 = 最大容量 - 溢出量。

For example, if a player’s tank level goes to 90, and its maximum fill value is 80, the overflow is 10. Deduct 10 from the maximum fill value to find the remaining water in the tank, which is 70 in this case.

例如,如果玩家的水箱水位达到90,而其最大填充值是80,那么溢出量就是10。从最大填充值中减去10,可以找到水箱中剩余的水量,本例中是70。

The game continues in turns until one player’s tank is filled. A tank is considered filled when the tank level is between the minimum and maximum fill values (inclusive). The first player to fill their tank wins the game.

这个游戏按轮次进行,直到其中一个玩家的坦克被填满。当坦克的水平介于最小和最大填充值(包括两者)之间时,就认为坦克已被填满。首个填满坦克的玩家赢得游戏。

If a pile of cards is exhausted, the setup function for that type of card will be called to replenish the pile.

如果一堆卡片用尽了,将会调用该类型卡片的设置函数以补充那堆卡片。

Required Functions

所需功能

The following functions must be present in your code with these given names and function signatures exactly. For the autograder to run properly, do not change the function names or the parameters. Do not add optional parameters or change the return types. If a function returns something, make sure what it returns is consistent with what’s mentioned in the details below. Be sure to add docstrings to all of your functions and comments to your code. The water_tank.py should be placed in the submit folder and should not be renamed, otherwise the autograder will fail to locate your program.

以下函数必须准确地以给定的名称和函数签名出现在您的代码中。为了确保自动评分器正常运行,请不要更改函数名称或参数。不要添加可选参数或更改返回类型。如果函数返回某些内容,请确保其返回的内容与下文中提到的内容一致。确保为您的所有函数添加文档字符串,并为您的代码添加注释。water_tank.py 应放置在 submit 文件夹中,并且不应被重命名,否则自动评分器将无法找到您的程序。

The following are the required functions you have to implement:

以下是你需要实现的函数:

(Note: Some functions may be used in another function)

注:某些函数可能会在另一个函数中被使用。

get_user_input(question):

setup_water_cards():

ValueQuantity of Cards
130
515
108

setup_power_cards():

ValueQuantity of Cards
卡片的数量
Description
SOH10Steal half opponent’s tank value. If the opponent’s tank value is an odd integer, it will truncate the decimal value (Example: 1⁄2 of 5 is 2) Hint: You may use the cast to int
窃取对手坦克价值的一半。如果对手的坦克价值是奇数整数,它将截断小数值(例如:5的1⁄2是2)。提示:你可以使用转换为整数。
DOT2Drain opponent’s tank
“排空对手的油箱”或“排空对方的储罐”。具体翻译取决于上下文。
DMT3Double my tank’s value.
翻倍我的坦克的价值。

setup_cards():

get_card_from_pile(pile, index):

arrange_cards(cards_list ):

deal_cards(water_cards_pile, power_cards_pile):

apply_overflow(tank_level)

remaining water = maximum fill value - overflow

use_card(player_tank, card_to_use, player_cards, opponent_tank):

discard_card(card_to_discard, player_cards, water_cards_pile, power_cards_pile):

filled_tank(tank):

check_pile(pile, pile_type):

human_play(human_tank, human_cards, water_cards_pile, power_cards_pile, opponent_tank):

computer_play(computer_tank, computer_cards, water_cards_pile, power_cards_pile, opponent_tank):

main():

公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQ

方法二:微信:Jiabcdefh

你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度
通知
关于编程私教&加密文章