@ThomasS1/

MineSweeper-4

Python

No description

fork
loading
Files
  • main.py
  • instructions.txt
  • replit.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5178967970323181","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJhbmRvbSwgdGltZSwgY29weSwgcmVwbGl0CmZyb20gdGVybWNvbG9yIGltcG9ydCBjcHJpbnQKCiNJbnRyb2R1Y3Rpb24KcHJpbnQoKQpjcHJpbnQoJ1dlbGNvbWUgdG8gTWluZVN3ZWVwZXIgdi4zLjAhJywgJ3JlZCcpCmNwcmludCgnPT09PT09PT09PT09PT09PT09PT09PT09PT09PT0nLCAncmVkJykKcHJpbnQoKQpwcmludCgnRXhjaXRlZCB0byBkZWNsYXJlIHZlcnNpb24gMy4wIG9mIE1pbmVTd2VlcGVyIGFzIGFsbW9zdCBmdWxseSBmdW5jdGlvbmFsIScpCgoKI1NldHMgdXAgdGhlIGdhbWUuCmRlZiByZXNldCgpOgogICAgcHJpbnQoJycnCk1BSU4gTUVOVQo9PT09PT09PT0KCi0+IEZvciBpbnN0cnVjdGlvbnMgb24gaG93IHRvIHBsYXksIHR5cGUgJ0knCi0+IFRvIHBsYXkgaW1tZWRpYXRlbHksIHR5cGUgJ1AnCicnJykKCiAgICBjaG9pY2UgPSBpbnB1dCgnVHlwZSBoZXJlOiAnKS51cHBlcigpCgogICAgaWYgY2hvaWNlID09ICdJJzoKICAgICAgICByZXBsaXQuY2xlYXIoKQoKICAgICAgICAjUHJpbnRzIGluc3RydWN0aW9ucy4KICAgICAgICBwcmludChvcGVuKCdpbnN0cnVjdGlvbnMudHh0JywgJ3InKS5yZWFkKCkpCgogICAgICAgIGlucHV0KCdQcmVzcyBbZW50ZXJdIHdoZW4gcmVhZHkgdG8gcGxheS4gJykKICAgICAgICAKICAgIGVsaWYgY2hvaWNlICE9ICdQJzoKICAgICAgICByZXBsaXQuY2xlYXIoKQogICAgICAgIHJlc2V0KCkKCiA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ICcgJ10sIFsnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnXSwgWycgJywgJyAnLCAnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnLCAnICddLCBbJyAnLCAnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnLCAnICcsICcgJ10sIFsnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnLCAnICcsICcgJywgJyAnXV0KCiAgICBwcmludEJvYXJkKGspCgojR2V0cyB0aGUgdmFsdWUgb2YgYSBjb29yZGluYXRlIG9uIHRoZSBncmlkLgpkZWYgbChyLCBjLCBiKToKICAgIHJldHVybiBiW3JdW2NdCgojUGxhY2VzIGEgYm9tYiBpbiBhIHJhbmRvbSBsb2NhdGlvbi4KZGVmIHBsYWNlQm9tYihiKToKICAgIHIgPSByYW5kb20ucmFuZGludCgwLCA4KQogICAgYyA9IHJhbmRvbS5yYW5kaW50KDAsIDgpCiAgICAjQ2hlY2tzIGlmIHRoZXJlJ3MgYSBib21iIGluIHRoZSByYW5kb21seSBnZW5lcmF0ZWQgbG9jYXRpb24uIElmIG5vdCwgaXQgcHV0cyBvbmUgdGhlcmUuIElmIHRoZXJlIGlzLCBpdCByZXF1ZXN0cyBhIG5ldyBsb2NhdGlvbiB0byB0cnkuCiAgICBjdXJyZW50Um93ID0gYltyXQogICAgaWYgbm90IGN1cnJlbnRSb3dbY10gPT0gJyonOgogICAgICAgIGN1cnJlbnRSb3dbY10gPSAnKicKICAgIGVsc2U6CiAgICAgICAgcGxhY2VCb21iKGIpCgojQWRkcyAxIHRvIGFsbCBvZiB0aGUgc3F1YXJlcyBhcm91bmQgYSBib21iLgpkZWYgdXBkYXRlVmFsdWVzKHJuLCBjLCBiKToKCiAgICAjUm93IGFib3ZlLgogICAgaWYgcm4tMSA+IC0xOgogICAgICAgIHIgPSBiW3JuLTFdCiAgICAgICAgCiAgICAgICAgaWYgYy0xID4gLTE6CiAgICAgICAgICAgIGlmIG5vdCByW2MtMV0gPT0gJyonOgogICAgICAgICAgICAgICAgcltjLTFdICs9IDEKCiAgICAgICAgaWYgbm90IHJbY10gPT0gJyonOgogICAgICAgICAgICByW2NdICs9IDEKCiAgICAgICAgaWYgOSA+IGMrMToKICAgICAgICAgICAgaWYgbm90IHJbYysxXSA9PSAnKic6CiAgICAgICAgICAgICAgICByW2MrMV0gKz0gMQoKICAgICNTYW1lIHJvdy4gICAgCiAgICByID0gYltybl0KCiAgICBpZiBjLTEgPiAtMToKICAgICAgICBpZiBub3QgcltjLTFdID09ICcqJzoKICAgICAgICAgICAgcltjLTFdICs9IDEKCiAgICBpZiA5ID4gYysxOgogICAgICAgIGlmIG5vdCByW2MrMV0gPT0gJyonOgogICAgICAgICAgICByW2MrMV0gKz0gMQoKICAgICNSb3cgYmVsb3cuCiAgICBpZiA5ID4gcm4rMToKICAgICAgICByID0gYltybisxXQoKICAgICAgICBpZiBjLTEgPiAtMToKICAgICAgICAgICAgaWYgbm90IHJbYy0xXSA9PSAnKic6CiAgICAgICAgICAgICAgICByW2MtMV0gKz0gMQoKICAgICAgICBpZiBub3QgcltjXSA9PSAnKic6CiAgICAgICAgICAgIHJbY10gKz0gMQoKICAgICAgICBpZiA5ID4gYysxOgogICAgICAgICAgICBpZiBub3QgcltjKzFdID09ICcqJzoKICAgICAgICAgICAgICAgIHJbYysxXSArPSAxCgojUHJpbnRzIHRoZSBnaXZlbiBib2FyZC4KZGVmIHByaW50Qm9hcmQoYik6CiAgICByZXBsaXQuY2xlYXIoKQogICAgcHJpbnQoJyAgICBBICAgQiAgIEMgICBEICAgRSAgIEYgICBHICAgSCAgIEknKQogICAgcHJpbnQoJyAg4pWU4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWm4pWQ4pWQ4pWQ4pWXJykKICAgIGZvciByIGluIHJhbmdlICgwLCA5KToKICAgICAgICBwcmludChyLCfilZEnLGwociwwLGIpLCfilZEnLGwociwxLGIpLCfilZEnLGwociwyLGIpLCfilZEnLGwociwzLGIpLCfilZEnLGwociw0LGIpLCfilZEnLGwociw1LGIpLCfilZEnLGwociw2LGIpLCfilZEnLGwociw3LGIpLCfilZEnLGwociw4LGIpLCfilZEnKQogICAgICAgIGlmIG5vdCByID09IDg6CiAgICAgICAgICAgIHByaW50KCcgIOKVoOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVrOKVkOKVkOKVkOKVoycpCiAgICBwcmludCgnICDilZrilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilanilZDilZDilZDilZ0nKQoKCgoKCgpyZXNldCgp"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import random, time, copy, replit
from termcolor import cprint

#Introduction
print()
cprint('Welcome to MineSweeper v.3.0!', 'red')
cprint('=============================', 'red')
print()
print('Excited to declare version 3.0 of MineSweeper as almost fully functional!')


#Sets up the game.
def reset():
    print('''
MAIN MENU
=========

-> For instructions on how to play, type 'I'
-> To play immediately, type 'P'
''')

    choice = input('Type here: ').upper()

    if choice == 'I':
        replit.clear()

        #Prints instructions.
        print(open('instructions.txt', 'r').read())

        input('Press [enter] when ready to play. ')
        
    elif choice != 'P':
        replit.clear()
        reset()

    #The solution grid.
    b = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]

    for n in range (0, 10):
        placeBomb(b)

    for r in range (0, 9):
        for c in range (0, 9):
            value = l(r, c, b)
            if value == '*':
                updateValues(r, c, b)

    #Sets the variable k to a grid of blank spaces, because nothing is yet known about the grid.
    k = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']]

    printBoard(k)

#Gets the value of a coordinate on the grid.
def l(r, c, b):
    return b[r][c]

#Places a bomb in a random location.
def placeBomb(b):
    r = random.randint(0, 8)
    c = random.randint(0, 8)
    #Checks if there's a bomb in the randomly generated location. If not, it puts one there. If there is, it requests a new location to try.
    currentRow = b[r]
    if not currentRow[c] == '*':
        currentRow[c] = '*'
    else:
        placeBomb(b)

#Adds 1 to all of the squares around a bomb.
def updateValues(rn, c, b):

    #Row above.
    if rn-1 > -1:
        r = b[rn-1]
        
        if c-1 > -1:
            if not r[c-1] == '*':
                r[c-1] += 1

        if not r[c] == '*':
            r[c] += 1

        if 9 > c+1:
            if not r[c+1] == '*':
                r[c+1] += 1

    #Same row.    
    r = b[rn]

    if c-1 > -1:
        if not r[c-1] == '*':
            r[c-1] += 1

    if 9 > c+1:
        if not r[c+1] == '*':
            r[c+1] += 1

    #Row below.
    if 9 > rn+1:
        r = b[rn+1]

        if c-1 > -1:
            if not r[c-1] == '*':
                r[c-1] += 1

        if not r[c] == '*':
            r[c] += 1

        if 9 > c+1:
            if not r[c+1] == '*':
                r[c+1] += 1

#Prints the given board.
def printBoard(b):
    replit.clear()
    print('    A   B   C   D   E   F   G   H   I')
    print('  ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗')
    for r in range (0, 9):
        print(r,'║',l(r,0,b),'║',l(r,1,b),'║',l(r,2,b),'║',l(r,3,b),'║',l(r,4,b),'║',l(r,5,b),'║',l(r,6,b),'║',l(r,7,b),'║',l(r,8,b),'║')
        if not r == 8:
            print('  ╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣')
    print('  ╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝')






reset()