桂林北站附近有什么好玩的网站设计推广

pingmian/2025/10/12 7:27:50/文章来源:
桂林北站附近有什么好玩的,网站设计推广,网络营销平台有哪些?,seo三人行论坛#xff08;第一阶段#xff09;问题 5a#xff08;3 分#xff09; 实现该函数#xff0c;该函数模拟了完整的 Hog 游戏。球员 交替轮流掷骰子#xff0c;直到其中一名玩家达到分数。playgoal 您现在可以忽略 Feral Hogs 规则和论点; 您将在问题 5b 中实现它。feral_h…第一阶段问题 5a3 分 实现该函数该函数模拟了完整的 Hog 游戏。球员 交替轮流掷骰子直到其中一名玩家达到分数。playgoal 您现在可以忽略 Feral Hogs 规则和论点; 您将在问题 5b 中实现它。feral_hogs 为了确定每回合掷出多少骰子每个玩家使用他们的 各自的策略玩家 0 使用玩家 1 使用。 策略是一种函数给定玩家的分数和对手的分数 score返回当前玩家想要掷的骰子数量 转。每个策略函数每回合只能调用一次。不用担心 关于实施策略的细节。您将在以下方面开发它们 第 3 阶段。strategy0strategy1 游戏结束后返回双方玩家的最终总分其中 玩家 0 得分第一玩家 1 得分第二。play 以下是一些提示 你应该使用你已经写好的函数您将需要使用所有三个参数进行调用。take_turn每回合只能呼叫一次。take_turn执行除野猪以外的所有特殊规则。您可以通过调用来获取其他玩家的号码0 或 1 提供的功能。other您可以暂时忽略该函数的参数。您将使用 它在项目的第 2 阶段。sayplay 在编写任何代码之前请解锁测试以验证您对问题的理解。 python3 ok -q 05a -u 完成解锁后开始实施解决方案。您可以通过以下方式检查您的正确性 python3 ok -q 05a def play(strategy0, strategy1, score00, score10, dicesix_sided,goalGOAL_SCORE, saysilence, feral_hogsTrue):Simulate a game and return the final scores of both players, with Player0s score first, and Player 1s score second.A strategy is a function that takes two total scores as arguments (thecurrent players score, and the opponents score), and returns a number ofdice that the current player will roll this turn.strategy0: The strategy function for Player 0, who plays first.strategy1: The strategy function for Player 1, who plays second.score0: Starting score for Player 0score1: Starting score for Player 1dice: A function of zero arguments that simulates a dice roll.goal: The game ends and someone wins when this score is reached.say: The commentary function to call at the end of the first turn.feral_hogs: A boolean indicating whether the feral hogs rule should be active.who 0 # Who is about to take a turn, 0 (first) or 1 (second)# BEGIN PROBLEM 5*** YOUR CODE HERE ***实现逻辑 1.循坏条件满足两人分数均小于规定分数 2.两人逻辑分别写 3.以其中一人0为例首先计算当前回合抛骰子的次数strategy0 计算当前得分(take_turn) 如果满足交换规律就交换is_swap 4.当前回合结束更换下一个直至结束 AC代码  while score0 goal and score1 goal:if who0:getstrategy0(score0,score1)score0take_turn(get,score1,dice)if is_swap(score0,score1):score0,score1score1,score0else:get strategy1(score1, score0)score1take_turn(get,score0,dice)if is_swap(score1,score0):score0,score1score1,score0whoother(who)# END PROBLEM 5# (note that the indentation for the problem 6 prompt (***YOUR CODE HERE***) might be misleading)# BEGIN PROBLEM 6*** YOUR CODE HERE ***# END PROBLEM 6return score0, score1AC情况注意要解锁之后才能测试 Test summary3 test cases passed before encountering first failed test caseBackup... 100% complete Backup past deadline by 1241 days, 23 hours, 51 minutes, and 24 seconds Backup successful for user: mxylms1210163.comOK is up to date PS D:\python文件\hog python3 ok -q 05aAssignment: Project 1: Hog OK, version v1.18.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests--------------------------------------------------------------------- Test summary11 test cases passed! No cases failed.Backup... 100% complete Backup past deadline by 1241 days, 23 hours, 52 minutes, and 25 seconds Backup successful for user: mxylms1210163.comOK is up to date问题 5b 1 pt 现在实施野猪规则。当被调用并且它的参数是 时则应该强加此规则。如果是则应忽略此规则。 这样在解决 5b 后5a 的测试用例仍将通过。playferal_hogsTrueferal_hogsFalse 野猪规则转载如下 野猪。如果您掷出的骰子数量与您在上一回合获得的分数正好相差 2 分绝对差异则该回合将获得 3 分的额外积分。将第一回合前的回合视为得分 0。在计算上一回合的得分数时不要考虑任何先前的野猪奖金或猪交换下一个规则。 例子 示例 1 两位球员都从 0 开始。(0, 0)玩家 0 掷 3 个骰子并获得 7 分。(7, 0)玩家 1 掷 1 个骰子并获得 4 分。(7, 4)玩家 0 掷 5 个骰子并获得 10 分。5 与 7 相差 2因此玩家 0 获得 3 的加成。(20, 4)玩家 1 掷 2 个骰子并获得 8 分。2 是 2 与 4 相差 2因此玩家 1 获得 3 的奖金。(20, 15)玩家 0 掷 8 个骰子并获得 20 分。8 是 2 与 10 相差 10因此玩家 0 获得 3 的奖励。(43, 15)玩家 1 掷 6 个骰子并获得 1 分。6 与 8 相差 2因此玩家 1 获得 3 的奖金。(43, 19) 示例 2 两位球员都从 0 开始。(0, 0)玩家 0 掷 2 个骰子并获得 3 分。2 是 2 与 0 相差 2因此玩家 0 获得 3 的奖励。(6, 0) 解锁时注意这里坑爹的strat1 s0-仍然指向s1s0只是形参 之前我总把s0代入s0难受 --------------------------------------------------------------------- Question 5b Suite 1 Case 1 (cases remaining: 103) import hogalways_one hog.make_test_dice(1)always_two hog.make_test_dice(2)always_three hog.make_test_dice(3)always hog.always_roll# example 1def strat0(s0, s1): ... if s0 0: return 3 ... if s0 7: return 5 ... return 8def strat1(s0, s1): ... if s0 0: return 1 ... if s0 4: return 2 ... return 6s0, s1 hog.play( ... strat0, strat1, score00, score10, goal21, ... dicehog.make_test_dice(2, 2, 3, 4, 2, 2, 2, 2, 2, 3, 5, 2, 2, 2, 2, 2, 2, 2, 6, 1))s01. s043(野猪*2) (计算注意野猪的加分算额外加分不算计算野猪加分的上回合加分) s115(野猪*1) 2.dice()每次调用后下一次初始值为上一次调用结尾的后一位 代码 add00add10while score0 goal and score1 goal:if who0:get0strategy0(score0,score1) # 当前回合的次数if feral_hogs:if abs(get0-add0)2:score03add0take_turn(get0,score1,dice) # 当前回合的加分score0add0if is_swap(score0,score1):score0,score1score1,score0else:get1 strategy1(score1, score0) # 当前回合的次数if feral_hogs:if abs(get1-add1)2:score13add1 take_turn(get1,score0,dice) # 当前回合的加分score1 add1if is_swap(score1,score0):score0,score1score1,score0whoother(who)# END PROBLEM 5# (note that the indentation for the problem 6 prompt (***YOUR CODE HERE***) might be misleading)# BEGIN PROBLEM 6*** YOUR CODE HERE ***# END PROBLEM 6return score0, score1 pass情况 OK! All cases for Question 5b unlocked.Backup... 100% complete Backup past deadline by 1242 days, 56 minutes, and 10 seconds Backup successful for user: mxylms1210163.comOK is up to date PS D:\python文件\hog python3 ok -q 05bAssignment: Project 1: Hog OK, version v1.18.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests--------------------------------------------------------------------- Test summary103 test cases passed! No cases failed.Backup... 100% complete Backup past deadline by 1242 days, 56 minutes, and 26 seconds Backup successful for user: mxylms1210163.com第一阶段总算是完结啦 Assignment: Project 1: Hog OK, version v1.18.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scoring tests--------------------------------------------------------------------- Question 0Passed: 0Failed: 1 [k..........] 0.0% passed--------------------------------------------------------------------- Question 1Passed: 3Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 2Passed: 1Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 3Passed: 2Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 4Passed: 1Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 5aPassed: 3Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 5bPassed: 2Failed: 0 [ooooooooook] 100.0% passed--------------------------------------------------------------------- Question 6Passed: 0Failed: 2 [k..........] 0.0% passed--------------------------------------------------------------------- Question 7 Suite 2 Case 1 from hog import play, always_roll, announce_highest, bothfrom dice import make_test_dice# this might not technically be a possible game for the current rules, this shouldnt be relevantf0 announce_highest(1) # Only announce Player 1 score gainsf1 f0(12, 0) TypeError: NoneType object is not callable# Error: expected# but got # Traceback (most recent call last): # ... # TypeError: NoneType object is not callableRun only this test case with python3 ok -q 07 --suite 2 --case 1 --------------------------------------------------------------------- Question 7Passed: 0Failed: 1 [k..........] 0.0% passed--------------------------------------------------------------------- Question 8 Suite 3 Case 1 from hog import *hundred_range range(1, 100)hundred_dice make_test_dice(*hundred_range)averaged_hundred_dice make_averaged(hundred_dice, 5*len(hundred_range))correct_average sum(range(1, 100)) / len(hundred_range)averaged_hundred_dice() TypeError: NoneType object is not callable# Error: expected # 50.0 # but got # Traceback (most recent call last): # ... # TypeError: NoneType object is not callableRun only this test case with python3 ok -q 08 --suite 3 --case 1 --------------------------------------------------------------------- Question 8Passed: 0Failed: 2 [k..........] 0.0% passed--------------------------------------------------------------------- Question 9Passed: 0Failed: 2 [k..........] 0.0% passed--------------------------------------------------------------------- Question 10 Suite 2 Case 1 from hog import *bacon_strategy(44, 47, 0, 4) 6# Error: expected # 0 # but got # 6Run only this test case with python3 ok -q 10 --suite 2 --case 1 --------------------------------------------------------------------- Question 10Passed: 0Failed: 2 [k..........] 0.0% passed--------------------------------------------------------------------- Question 11 Suite 2 Case 1 from hog import *swap_strategy(47, 64, 3, 4) 6# Error: expected # 0 # but got # 6Run only this test case with python3 ok -q 11 --suite 2 --case 1 --------------------------------------------------------------------- Question 11Passed: 0Failed: 2 [k..........] 0.0% passed--------------------------------------------------------------------- Question 12Passed: 0Failed: 0 [k..........] 0.0% passed--------------------------------------------------------------------- Point breakdownQuestion 0: 0.0/0Question 1: 2.0/2Question 2: 1.0/1Question 3: 2.0/2Question 4: 2.0/2Question 5a: 3.0/3Question 5b: 1.0/1Question 6: 0.0/2Question 7: 0.0/3Question 8: 0.0/2Question 9: 0.0/2Question 10: 0.0/1Question 11: 0.0/2Question 12: 0.0/0Score:Total: 11.0Backup... 100% complete Backup past deadline by 1242 days, 1 hour, 23 minutes, and 40 seconds Backup successful for user: mxylms1210163.comOK is up to date第二阶段问题62分 更新您的play函数以便在最后调用注释函数 每一个转身。调用注释函数的返回值为您提供 评论功能以调用下一轮。 例如say(score0, score1)应该在第一个 依次它的返回值另一个注释函数应该在最后调用 的第二个转折点。每一个连续的回合调用返回的函数 通过调用前一回合的评论功能 解锁遇到的坑点(line3) 轮到参数者第二加分时得到13此时对手为12(两者交换) line3:12 13 --------------------------------------------------------------------- Question 6 Suite 2 Case 3 (cases remaining: 4)from hog import play, always_rollfrom dice import make_test_dice#def echo(s0, s1): ... print(s0, s1) ... return echostrat0 lambda score, opponent: 1 - opponent // 10strat1 always_roll(3)s0, s1 play(strat0, strat1, dicemake_test_dice(4, 2, 6), goal15, sayecho)问题73分 实现announce_highest函数这是一个高阶函数 返回一个注释函数。每当出现 某个玩家在一个回合中获得的点数比以往任何时候都多。例如在一个示例中 announce_highest(1)及其返回值完全忽略参与人0 打印有关参与人1的信息。为了计算增益它必须比较 从最后一轮到这轮的得分这是 由who参数指定。此函数还必须跟踪 这是迄今为止玩家获得的最高收益。 announce_highest宣布的方式是非常具体的你的 实现应该匹配所提供的doctests。不要担心单数 而不是复数时宣布点收益;你应该简单地使用“点s”为 两个案子 Hint.提供给您的announce_lead_changes函数是一个示例 如何使用评论功能跟踪信息。如果你被卡住了 首先请确保您了解announce_lead_changes如何工作。 注意hog.py中both/announce_highest的文档测试可能描述 一个不可能按照规则发生的游戏这不应该是一个问题 评论功能因为它们不执行任何游戏规则。 Hint.如果你得到一个local variable [var] reference before assignment错误 这是因为在Python中通常不允许修改 父框架中定义的变量。而不是重新分配[var] 解释器认为你试图在当前的 frame.我们将在以后的讲座中学习如何解决这个问题 这个问题不需要。 要解决这个问题你有两个选择 1)与其将[var]重新分配给它的新值不如创建一个新变量 保留新值。在以后的计算中使用这个新变量。 2)对于此问题请通过不使用 所有的赋值语句而是将新值作为参数传递给 打电话给#1。 分析由于形参无法直接赋值新值 我们可以采用递归的方法利用新函数重新赋值新的形参  anounce_highest()函数 我们分为两个情况考虑 一种是当前分数-之前分数最高增加数 返回新函数的形参 之前分数为当前分数 最高增加数为当前分数-之前分数 另一种是当前分数-之前分数最高增加数 返回新函数的形参 之前分数为当前分数 最高增加数为当前最高增加数 pass代码 def announce_highest(who, last_score0, running_high0):Return a commentary function that announces when WHOs scoreincreases by more than ever before in the game.NOTE: the following game is not possible under the rules, its justan example for the sake of the doctest f0 announce_highest(1) # Only announce Player 1 score gains f1 f0(12, 0) f2 f1(12, 11)11 point(s)! Thats the biggest gain yet for Player 1 f3 f2(20, 11) f4 f3(13, 20) f5 f4(20, 35)15 point(s)! Thats the biggest gain yet for Player 1 f6 f5(20, 47) # Player 1 gets 12 points; not enough for a new high f7 f6(21, 47) f8 f7(21, 77)30 point(s)! Thats the biggest gain yet for Player 1 f9 f8(77, 22) # Swap! f10 f9(33, 77) # Swap!55 point(s)! Thats the biggest gain yet for Player 1assert who 0 or who 1, The who argument should indicate a player.# BEGIN PROBLEM 7*** YOUR CODE HERE ***def bumble(player1,player2):if who1:current1player2else:current1player1if (current1-last_score) running_high:print(str(current1-last_score) point(s)! Thats the biggest gain yet for Player str(who))return announce_highest(who,current1,current1-last_score)return announce_highest(who,current1,running_high)return bumblepass情况 OK is up to date PS D:\python文件\hog python3 ok -q 07Assignment: Project 1: Hog OK, version v1.18.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests--------------------------------------------------------------------- Test summary5 test cases passed! No cases failed.Backup... 100% complete Backup past deadline by 1242 days, 4 hours, 44 minutes, and 54 seconds Backup successful for user: mxylms1210163.comOK is up to date问题92分 实现max_scoring_num_rolls函数该函数运行一个实验 确定给出最大平均值的卷数从1到10 一个转身得分。 您的实现应该使用make_averaged和 roll_dice. 如果两个掷骰数相等则返回 更低的数字。例如如果3和6都达到了最高平均分 返回3. 在编写任何代码之前解锁测试以验证您对问题的理解。 python3 ok -q 09 -u 完成解锁后开始实施解决方案。您可以通过以下方式检查您的正确性 python3 ok -q 09 要在随机骰子上运行此实验请使用 run_experiments选项 python3 hog.py -r 运行实验对于本项目的剩余部分您可以更改 run_experiments1average_win_rate1if False:1if True:1always_roll(8)1always_roll(6)1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1undefined1#1 通过调用 undefined你可以评估各种猪策略。比如说 将第一个undefined更改为undefined以评估 undefined对比undefined的基线策略。 某些实验可能需要一分钟才能运行。你总是可以减少 调用make_averaged中的试验次数以加快实验速度。 分析此题函数需要返回最小的达到最大平均值的骰子个数 利用roll_dice实现多个骰子同时使用但返回的是int 利用make_average()实现计算平均值 形参骰子的函数和抛骰子的次数 (注意需要把roll_dice利用lambda表达式转换为函数) pass代码  def max_scoring_num_rolls(dicesix_sided, trials_count1000):Return the number of dice (1 to 10) that gives the highest average turnscore by calling roll_dice with the provided DICE over TRIALS_COUNT times.Assume that the dice always return positive outcomes. dice make_test_dice(1, 6) max_scoring_num_rolls(dice)1# BEGIN PROBLEM 9*** YOUR CODE HERE ***aver{}max1-1.0for i in range(1,11):avmake_averaged(lambda :roll_dice(i,dice),trials_count)aver[i-1]av()if max1 aver[i-1]:max1aver[i-1]for i in range(0,10):if max1 aver[i]:return i1pass情况 PS D:\python文件\hog python3 ok -q 09Assignment: Project 1: Hog OK, version v1.18.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests--------------------------------------------------------------------- Test summary8 test cases passed! No cases failed.Backup... 100% complete最后的final策略就之后再实现吧毕竟没有学分...hahaha 以下为完整代码 CS 61A Presents The Game of Hog.from dice import six_sided, four_sided, make_test_dice from ucb import main, trace, interactGOAL_SCORE 100 # The goal of Hog is to score 100 points.###################### # Phase 1: Simulator # ######################def roll_dice(num_rolls, dicesix_sided):Simulate rolling the DICE exactly NUM_ROLLS 0 times. Return the sum ofthe outcomes unless any of the outcomes is 1. In that case, return 1.num_rolls: The number of dice rolls that will be made.dice: A function that simulates a single dice roll outcome.# These assert statements ensure that num_rolls is a positive integer.assert type(num_rolls) int, num_rolls must be an integer.assert num_rolls 0, Must roll at least once.# BEGIN PROBLEM 1*** YOUR CODE HERE ***ret 0pig_out Falsefor _ in range(num_rolls):score dice()if score 1:pig_out Truecontinueret scorereturn 1 if pig_out else ret# END PROBLEM 1def free_bacon(score):Return the points scored from rolling 0 dice (Free Bacon).score: The opponents current score.assert score 100, The game should be over.# BEGIN PROBLEM 2*** YOUR CODE HERE ***return 10 - score%10 int(score / 10)# END PROBLEM 2def take_turn(num_rolls, opponent_score, dicesix_sided):Simulate a turn rolling NUM_ROLLS dice, which may be 0 (Free Bacon).Return the points scored for the turn by the current player.num_rolls: The number of dice rolls that will be made.opponent_score: The total score of the opponent.dice: A function that simulates a single dice roll outcome.# Leave these assert statements here; they help check for errors.assert type(num_rolls) int, num_rolls must be an integer.assert num_rolls 0, Cannot roll a negative number of dice in take_turn.assert num_rolls 10, Cannot roll more than 10 dice.assert opponent_score 100, The game should be over.# BEGIN PROBLEM 3*** YOUR CODE HERE ***if num_rolls0:return roll_dice(num_rolls,dice)else:return free_bacon(opponent_score)# END PROBLEM 3def is_swap(player_score, opponent_score):Return whether the two scores should be swapped# BEGIN PROBLEM 4*** YOUR CODE HERE ***if abs(player_score%10-opponent_score%10)(opponent_score//10)%10:return Trueelse:return False# END PROBLEM 4def other(who):Return the other player, for a player WHO numbered 0 or 1. other(0)1 other(1)0return 1 - whodef silence(score0, score1):Announce nothing (see Phase 2).return silencedef play(strategy0, strategy1, score00, score10, dicesix_sided,goalGOAL_SCORE, saysilence, feral_hogsTrue):Simulate a game and return the final scores of both players, with Player0s score first, and Player 1s score second.A strategy is a function that takes two total scores as arguments (thecurrent players score, and the opponents score), and returns a number ofdice that the current player will roll this turn.strategy0: The strategy function for Player 0, who plays first.strategy1: The strategy function for Player 1, who plays second.score0: Starting score for Player 0score1: Starting score for Player 1dice: A function of zero arguments that simulates a dice roll.goal: The game ends and someone wins when this score is reached.say: The commentary function to call at the end of the first turn.feral_hogs: A boolean indicating whether the feral hogs rule should be active.who 0 # Who is about to take a turn, 0 (first) or 1 (second)# BEGIN PROBLEM 5*** YOUR CODE HERE ***add00add10while score0 goal and score1 goal:if who0:get0strategy0(score0,score1) # 当前回合的次数if feral_hogs:if abs(get0-add0)2:score03add0take_turn(get0,score1,dice) # 当前回合的加分score0add0if is_swap(score0,score1):score0,score1score1,score0say say(score0, score1)else:get1 strategy1(score1, score0) # 当前回合的次数if feral_hogs:if abs(get1-add1)2:score13add1 take_turn(get1,score0,dice) # 当前回合的加分score1 add1if is_swap(score1,score0):score0,score1score1,score0say say(score0, score1)whoother(who)# END PROBLEM 5# (note that the indentation for the problem 6 prompt (***YOUR CODE HERE***) might be misleading)# BEGIN PROBLEM 6*** YOUR CODE HERE ***# END PROBLEM 6return score0, score1####################### # Phase 2: Commentary # #######################def say_scores(score0, score1):A commentary function that announces the score for each player.print(Player 0 now has, score0, and Player 1 now has, score1)return say_scoresdef announce_lead_changes(last_leaderNone):Return a commentary function that announces lead changes. f0 announce_lead_changes() f1 f0(5, 0)Player 0 takes the lead by 5 f2 f1(5, 12)Player 1 takes the lead by 7 f3 f2(8, 12) f4 f3(8, 13) f5 f4(15, 13)Player 0 takes the lead by 2def say(score0, score1):if score0 score1:leader 0elif score1 score0:leader 1else:leader Noneif leader ! None and leader ! last_leader:print(Player, leader, takes the lead by, abs(score0 - score1))return announce_lead_changes(leader)return saydef both(f, g):Return a commentary function that says what f says, then what g says.NOTE: the following game is not possible under the rules, its justan example for the sake of the doctest h0 both(say_scores, announce_lead_changes()) h1 h0(10, 0)Player 0 now has 10 and Player 1 now has 0Player 0 takes the lead by 10 h2 h1(10, 6)Player 0 now has 10 and Player 1 now has 6 h3 h2(6, 17)Player 0 now has 6 and Player 1 now has 17Player 1 takes the lead by 11def say(score0, score1):return both(f(score0, score1), g(score0, score1))return saydef announce_highest(who, last_score0, running_high0):Return a commentary function that announces when WHOs scoreincreases by more than ever before in the game.NOTE: the following game is not possible under the rules, its justan example for the sake of the doctest f0 announce_highest(1) # Only announce Player 1 score gains f1 f0(12, 0) f2 f1(12, 11)11 point(s)! Thats the biggest gain yet for Player 1 f3 f2(20, 11) f4 f3(13, 20) f5 f4(20, 35)15 point(s)! Thats the biggest gain yet for Player 1 f6 f5(20, 47) # Player 1 gets 12 points; not enough for a new high f7 f6(21, 47) f8 f7(21, 77)30 point(s)! Thats the biggest gain yet for Player 1 f9 f8(77, 22) # Swap! f10 f9(33, 77) # Swap!55 point(s)! Thats the biggest gain yet for Player 1assert who 0 or who 1, The who argument should indicate a player.# BEGIN PROBLEM 7*** YOUR CODE HERE ***def bumble(player1,player2):if who1:current1player2else:current1player1if (current1-last_score) running_high:print(str(current1-last_score) point(s)! Thats the biggest gain yet for Player str(who))return announce_highest(who,current1,current1-last_score)return announce_highest(who,current1,running_high)return bumble# END PROBLEM 7####################### # Phase 3: Strategies # #######################def always_roll(n):Return a strategy that always rolls N dice.A strategy is a function that takes two total scores as arguments (thecurrent players score, and the opponents score), and returns a number ofdice that the current player will roll this turn. strategy always_roll(5) strategy(0, 0)5 strategy(99, 99)5def strategy(score, opponent_score):return nreturn strategydef make_averaged(original_function, trials_count1000):Return a function that returns the average value of ORIGINAL_FUNCTION when called.To implement this function, you will have to use *args syntax, a new Pythonfeature introduced in this project. See the project description. dice make_test_dice(4, 2, 5, 1) averaged_dice make_averaged(dice, 1000) averaged_dice()3.0# BEGIN PROBLEM 8*** YOUR CODE HERE ***def average1():sum0.0for i in range(1,trials_count1):sumoriginal_function()return sum/trials_countreturn average1# END PROBLEM 8def max_scoring_num_rolls(dicesix_sided, trials_count1000):Return the number of dice (1 to 10) that gives the highest average turnscore by calling roll_dice with the provided DICE over TRIALS_COUNT times.Assume that the dice always return positive outcomes. dice make_test_dice(1, 6) max_scoring_num_rolls(dice)1# BEGIN PROBLEM 9*** YOUR CODE HERE ***aver{}max1-1.0for i in range(1,11):avmake_averaged(lambda :roll_dice(i,dice),trials_count)aver[i-1]av()if max1 aver[i-1]:max1aver[i-1]for i in range(0,10):if max1 aver[i]:return i1# END PROBLEM 9def winner(strategy0, strategy1):Return 0 if strategy0 wins against strategy1, and 1 otherwise.score0, score1 play(strategy0, strategy1)if score0 score1:return 0else:return 1def average_win_rate(strategy, baselinealways_roll(6)):Return the average win rate of STRATEGY against BASELINE. Averages thewinrate when starting the game as player 0 and as player 1.win_rate_as_player_0 1 - make_averaged(winner)(strategy, baseline)win_rate_as_player_1 make_averaged(winner)(baseline, strategy)return (win_rate_as_player_0 win_rate_as_player_1) / 2def run_experiments():Run a series of strategy experiments and report results.if True: # Change to False when done finding max_scoring_num_rollssix_sided_max max_scoring_num_rolls(six_sided)print(Max scoring num rolls for six-sided dice:, six_sided_max)if False: # Change to True to test always_roll(8)print(always_roll(8) win rate:, average_win_rate(always_roll(8)))if False: # Change to True to test bacon_strategyprint(bacon_strategy win rate:, average_win_rate(bacon_strategy))if False: # Change to True to test swap_strategyprint(swap_strategy win rate:, average_win_rate(swap_strategy))if False: # Change to True to test final_strategyprint(final_strategy win rate:, average_win_rate(final_strategy))*** You may add additional experiments as you wish ***def bacon_strategy(score, opponent_score, cutoff8, num_rolls6):This strategy rolls 0 dice if that gives at least CUTOFF points, androlls NUM_ROLLS otherwise.# BEGIN PROBLEM 10if free_bacon(opponent_score)cutoff:return 0else:return num_rolls# END PROBLEM 10def swap_strategy(score, opponent_score, cutoff8, num_rolls6):This strategy rolls 0 dice when it triggers a beneficial swap. It alsorolls 0 dice if it gives at least CUTOFF points and does not trigger anon-beneficial swap. Otherwise, it rolls NUM_ROLLS.# BEGIN PROBLEM 11baconfree_bacon(opponent_score)if is_swap(baconscore,opponent_score):if baconscoreopponent_score:return num_rollselse:return 0if bacon cutoff:return 0else:return num_rolls# END PROBLEM 11def final_strategy(score, opponent_score):Write a brief description of your final strategy.*** YOUR DESCRIPTION HERE ***# BEGIN PROBLEM 12return 6 # Replace this statement# END PROBLEM 12########################## # Command Line Interface # ########################### NOTE: Functions in this section do not need to be changed. They use features # of Python not yet covered in the course.main def run(*args):Read in the command-line argument and calls corresponding functions.This function uses Python syntax/techniques not yet covered in this course.import argparseparser argparse.ArgumentParser(descriptionPlay Hog)parser.add_argument(--run_experiments, -r, actionstore_true,helpRuns strategy experiments)args parser.parse_args()if args.run_experiments:run_experiments() pass情况 --------------------------------------------------------------------- Point breakdownQuestion 0: 0.0/0Question 1: 2.0/2Question 2: 1.0/1Question 3: 2.0/2Question 4: 2.0/2Question 5a: 3.0/3Question 5b: 1.0/1Question 6: 2.0/2Question 7: 3.0/3Question 8: 0.0/2Question 9: 2.0/2Question 10: 1.0/1Question 11: 2.0/2Question 12: 0.0/0Score:Total: 21.0Backup... 0.0% completeOK is up to date

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88529.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

平面设计类网站有哪些做网站建设公司crm在线的培训服务

文章目录 炸铁路题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1 题意解析思路CODE 炸铁路 题目描述 A 国派出将军 uim,对 B 国进行战略性措施,以解救涂炭的生灵。 B 国有 n n n 个城市,这些城市以铁路相连。任意两个城市都可以通…

大连网站建设外包公司商丘网络第一媒体

在流媒体项目中字幕显示是不可或缺的一环,一般会有字幕流在视频播放过程中进行显示;不过还有很多情况是从头到尾只在视频的某个区域显示某些文字,例如某个电视台的log;这种也称为字幕,如果想要将这些字符串显示到视频&…

西乡县门户网站宁波市网站排名优化

先贴上关于使用这个日志组件的一些使用方法,等有时间了在吧官方的文档翻译一下吧,现在真是没时间。 Serilog在使用上主要分为两大块: 第一块是主库,包括Serilog以及Serilog.AspNetCore,如果导入后一个的话会自动导入前…

国内虚拟助手网站国外打开网站会不会乱码

参考资料:https://blog.51cto.com/u_11984354/4907646 NO.21-SAP S4 HANA Cloud API接口测试(1)-CSDN博客

dede网站名称不能保存网站开发与建设方向

前面学习了一个简单的例子,这是多年来学习应用程序开发的经典路径,在这里也是这种待遇,通过这样的学习明白了一个简单应用是怎么样构成的,知道它是怎么运行输出的。在这个基础之上,你还是不会开发应用程序的,因为你还没有学习鸿蒙应用的开发语言基础,所以在这里要学习一…

抚顺市 网站建设中国移动积分兑换商城官方网站

资料仅供学习分享用,废话不多说,解压密码为:1024文件是切割压缩的,多个part的压缩包,大家需要先下载到本地在解压,直接百度云解压会提示压缩包损坏。------------------------------学习资料java&#xff1…

免费一键自助建站官网软件开发5个过程

什么是HTTP压缩cssHTTP压缩是指: Web服务器和浏览器之间压缩传输的”文本内容“的方法。 HTTP采用通用的压缩算法,好比gzip来压缩HTML,Javascript, CSS文件。 能大大减小网络传输的数据量,提升了用户显示网页的速度。固然,同时会增长一点点服…

建网站申请济南营销型网站制作

-----2017.11.16 最后一次更新----- 小夕也真的没有想到,在万般绝望之时竟然得到了这么多人的帮助。在本文发出后,多位阿里人员积极联系我了解了情况,很感激一位阿里的专家帮我将此事递交给相关部门,让专业的客服直接受理和重审此…

防制网站怎么做wordpress主页视频

作者: 陈斌(redguardtoo) 更新时间: 2012-02-10 五 原创时间: 2012-01-31 周二 15:08 很容易.一年多前我还在Vi阵营,偶尔使用Emacs还总是忘记退出(C-x C-c)的快捷键,但是一年后我跨入高手行列. 现在网上很多中文文章都是和你强调Emacs有多牛,以激发你的兴趣.最有名的大概是王垠…

中山企业网站建设定制现在都用什么做网站

NaN 是什么 在C中,NaN(Not a Number)是一种特殊的浮点数值,用于表示无法表示的数值或未定义的操作,例如0除以0。如果你的double类型变量显示为NaN,那么可能是在计算过程中出现了这种未定义的操作。 如果你…

如何将别人的网站作为自己的网站报错401

源码简介 超级外链工具,是一款在线全自动化发外链的推广工具。使用本工具可免费为网站在线批量增加外链,大大提高外链发布工作效率,是广大草根站长们必备的站长工具。 搭建环境 PHP 5.6 安装教程 上传源码压缩包到网站目录并解压即可 首…

广州网站优化关键词排名今天广西新闻回放

Atitit。数据库 安全性 重要敏感数据加密存储解决方案 1.1. 加密存储的重要性1 1.2. 使用的加密算法aes1 1.3. 数据加密以后会有一些问题。1 1.3.1. 一个是统计,比如统计资金总额。。就无法直接使用sql的sum等数据库内部聚合函数来处理了。。1 1.3.2. 还有一个就是按…

网站开发项目付款方式如何创建网站快捷方式到桌面

什么是卫语句在方法的开头,我们经常会添加一些检查代码,当检查条件为true时立刻从方法中返回。这样的单独检查代码被称为“卫语句”。例如,我们在添加用户时会检查用户名不能为空,年龄必须大于0:public void AddUser(s…

高端网站制作开发网页应用开发

SDN火热了好一阵子,无论运营商、政府企业、投资机构,一段时间,不知道SDN、不能甩几个SDN相关的名词术语,似乎都落后于时代了。今天,就来看看关于SDN的精华问答吧。1Q:SDN将会提供端到端的IT基础设施可见性&…

鹰手营子矿网站建设qq在线登录聊天

使用w查看系统负载1.w命令,查看系统负载:单位时间内使用cpu的活动的进程有多少个[rootweix01 ~]# w #load average 后面三个数字表示1分钟,5分钟,15分钟的负载值,最合适的是逻辑cpu数量与1分钟负载一致21:10:21 up 8 m…

单页网站排名没有苏州建设工程信息网

最近一直在研究cas登录中心这一块的应用,分享一下记录的一些笔记和心得。后面会把cas-server端的配置和重构,另外还有这几天再搞nginxcas的https反向代理配置,以及cas的证书相关的知识分享出来。 Cas由两部分组成,Cas Server和Cas…

书店建设网站的能力一 网站建设的总体目标

一、微网系统运行优化模型 微电网优化模型介绍: 微电网多目标优化调度模型简介_IT猿手的博客-CSDN博客 二、遗传算法GA 遗传算法(Genetic Algorithm,GA)起源于对生物系统所进行的计算机模拟研究,是一种随机全局搜索…

网站建设中单页面汕头网络公司网站建设

简介 在前一篇文章中,我们讨论了Razor页面。今天我们来谈谈处理方法(Handlers)。我们知道可以将代码和模型放在 .cshtml 文件里面或与 .cshtml 匹配的 .cshtml.cs 文件中。Razor页面处理程序或处理方法将用户请求匹配到我们的方法&#xff1…

口碑好的网站建设无为县城乡建设局网站

Vue常用经典开源项目汇总参考-海量 Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的 渐进式框架。与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计。Vue 的核心库只关注视图层,并且非常…

广西建设学院官方网站德州网站建设

最近在复习C的一些相关知识,正好把智能指针重新梳理一遍。 智能指针 作用 为什么需要智能指针?说白了就是为了更加“方便智能”的管理内存,当使用原始指针有时候会因为忘记释放内存,从而导致内存泄漏 。智能指针则可以帮我们释放…