Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise: MiniWarGame. In this exercise, we will implement a mini version of the card game War. There are 2 players, each having a deck

image text in transcribed imageimageimageimage

Exercise: MiniWarGame. In this exercise, we will implement a mini version of the card game "War". There are 2 players, each having a deck with 6 "cards": There are two cards with value 1, two cards with value 2, and two cards with value 3. In every round each player pulls the top card from the deck - the player that has the highest number, will take both cards and add them at the rear of his deck (his original card first, then the opponent's card). If both players pull the same number - we flip a coin and the winner will take both cards. The game ends when one of the players has won all cards and the other player has an empty deck. We initialize the game by (randomly) setting a deck for each player. Then, as long as no deck is empty, we play the rounds. At the end we announce the winner. At the beginning of each round, print out the decks. If a coin was flipped, print out the player that won that round. At the end, print the decks and announce the winner. Alice starts with deck: 3 2 3 1 2 1 bob starts with deck: 3 1 3 2 2 1 Round: 1 ********** Alice: 3 2 3 1 21 bob: 3 1 3 2 2 1 flipped coin! bob won Round: 2 ****: ***** Alice: 2 3 1 2 1 bob: 1 3 2 2 1 3 3 Round: 3 ***** **** Alice: 3 1 2 1 2 1 bob: 3 2 2 1 3 3 flipped coin! bob won Round: 4 ********** Alice: 1 2 1 2 1 bob: 2 2 1 3 3 3 3 Round: 5 ********** Alice: 2 1 2 1 bob: 2 1 3 3 3 3 2 1 flipped coin! Alice won Round: 6 ********** Alice: 1 2 1 2 2 bob: 1 3 3 3 3 2 1 flipped coin! Alice won Round: 7 ********** Alice: 2 1 2 2 11 bob: 3 3 3 3 2 1 Round: 8 ********** Alice: 1 2 2 11 bob: 3 3 3 2 1 3 2 Round: 9 ********** Alice: 2 2 1 1 bob: 3 3 2 1 3 2 3 1 Round: 10 ********** Alice: 2 1 1 bob: 3 2 1 3 2 3 1 32 Round: 11 ****: *** Alice: 1 1 bob: 2 1 3 2 3 1 3 232 Round: 12 ********** Alice: 1 bob: 1 3 2 3 1 3 2 3 2 2 1 flipped coin! bob won bob won!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import random class MiniWarGame def initself selfplayer1deck 1 1 2 2 3 3 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Programming questions