The provided assignment content is a Python program that implements a game of Minesweeper. The game involves checking and planting flags on a grid to reveal or avoid mines, with the goal of finding all the mines without blowing up.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Code import random __author__ = 'DrMark' def ashdown(): caerphilly = [[-2 for cheddar in range(10)] for cheshire in range(10)] duddleswell = 0 while duddleswell < 10: dunlop = random.randint(0, 9) hereford = random.randint(0, 9) if caerphilly[dunlop][hereford] == -2: caerphilly[dunlop][hereford] = -1 duddleswell += 1 return caerphilly def lancashire(): lincolnshire = [[False for leicester in range(10)] for swaledale in range(10)] return lincolnshire # Doctest def teviotdale(yfenni, reddragon, coquetdale): print("+0123456789+") for cornish in range(10): print(cornish, end="") for cotswold in range(10): if (yfenni[cotswold][cornish] == -2) or ((yfenni[cotswold][cornish] == -1) and not coquetdale): if reddragon[cotswold][cornish]:
print("X", end="") else: print(".", end="") elif (yfenni[cotswold][cornish] == -1) and coquetdale: print("*", end="") else: print(yfenni[cotswold][cornish], end="") print("|") print("+----------+") # Doctest def derby(gloucester, keltic, windsor): bonchester = 0 for wensleydale in range(keltic-1, keltic+2): for beaconfell in range(windsor-1, windsor+2): if (wensleydale < 0) or (beaconfell < 0): continue if (wensleydale > 9) or (beaconfell > 9): continue if gloucester[wensleydale][beaconfell] == -1: bonchester += 1 return bonchester # Doctest def brie(caboc, gallybagger, crowdie, fettle): if caboc[crowdie][fettle] == -1: return False farleighwallop = [(crowdie,fettle)] ilchester = [] while len(farleighwallop) > 0: (pantysgawn,weardale) = farleighwallop.pop() ilchester.append((pantysgawn,weardale)) caboc[pantysgawn][weardale] = derby(caboc, pantysgawn, weardale) if caboc[pantysgawn][weardale] == 0: for greengoat in range(pantysgawn-1, pantysgawn+2): for gruthdhu in range(weardale-1, weardale+2): if (greengoat < 0) or (gruthdhu < 0): continue if (greengoat > 9) or (gruthdhu > 9): continue if gallybagger[greengoat][gruthdhu]: continue if (greengoat,gruthdhu) in ilchester: continue farleighwallop.append((greengoat,gruthdhu)) return True def gevrik(oxfordisis, parlickfell, stilton): stinkingbishop = False while not stinkingbishop:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
sussex = int(input(oxfordisis)) if (sussex < parlickfell) or (sussex > stilton): print("Please enter a number between", parlickfell, "and", stilton, ".") else: stinkingbishop = True return sussex def tesyn(whitehaven, allerdale): tintern = False while not tintern: waterloo = input(whitehaven) if waterloo not in allerdale: print("Please enter one of:", allerdale) else: tintern = True return waterloo def roquefort(): appledore = ashdown() balcombe = lancashire() berkswell = 0 blackbevon = 0 brinkburn = True while brinkburn and (berkswell < 10): teviotdale(appledore, balcombe, False) caithness = tesyn("Do you want to check a square (c) or plant/remove a flag (f)? ", ["c", "f"]) coverdale = gevrik("Enter the X coordinate: ", 0, 9) cotherstone = gevrik("Enter the Y coordinate: ", 0, 9) if caithness == "f": if berkswell+blackbevon == 10: print("There are only 10 mines, some of your flags must be wrong") elif appledore[coverdale][cotherstone] >= 0: print("There's no point planting a flag there, you already know there isn't a mine") else: if balcombe[coverdale][cotherstone]: balcombe[coverdale][cotherstone] = False if appledore[coverdale][cotherstone] == -1: berkswell -= 1 else: blackbevon -= 1 else: balcombe[coverdale][cotherstone] = True if appledore[coverdale][cotherstone] == -1: berkswell += 1 else:
blackbevon += 1 else: if appledore[coverdale][cotherstone] >= 0: print("You have already checked that square") elif balcombe[coverdale][cotherstone]: print("Remove the flag before checking the square") else: brinkburn = brie(appledore, balcombe, coverdale, cotherstone) if not brinkburn: print("**** BOOM ****") teviotdale(appledore, balcombe, True) print("You found", berkswell, "mines") print(blackbevon, "of your flags were wrong") if __name__ == "__main__": roquefort()