Skip to main content
added flagging - what a horror to do!
Source Link
beary605
  • 4.4k
  • 2
  • 26
  • 52

Python (502502 566)

Checklist:

Randomized mine generation - yes
8x8 field with 10 mines - yes
Mine and "unknown" flags - yes
Reveal nearby blank spaces when a blank space has been revealed. - yes
Input and output code: It must be playable. - yes

It has a win detector as well.

Input is given while the game is running, with (f, x, y). No support for flags yet (x, y) is the coordinates of the grid selection, may getf is whether you want to that soonflag or not. (0, 0, 0) would open up (0, 0), and (1, 2, 3) would flag (2, 3). Flagging works in a cycle: flagging a square twice gives a question mark.

(number) - number of mines
(space) - unexplored
. - 0 mines
! - flag
" - question

import random
A=[-1,0,1]
R=lambda( x,y):[[x+i,y+j]for i in A[x+i for j in Ai if([iin[-9,j]!=[0-8,0])&(-1<x+i<87,-1,1,7,8,9]if(0<x+i<64)&([i,x%8]not in([7,0],[-1<y+j<87,7],[-1,0],[1,7]))]
M=lambda p:sum(G[i][j]=='*'forG[i]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=Mm=M(p);G[a][b]=`m`if;G[p]=`m`if m else' .'
 if m>0:return
 for c in R(p):
  f,g=c
  if'. '!=G[f][g]=G[c]:continue
  m=M(c);G[f][g]=`m`;G[c]=`m`
  if m==0:G[f][g]=' G[c]='.';V(c)
 
G=['. ']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'. 'in`G`:
 for i in Grange(8):print`i`print[j.replace('*','. ')[0]for j in G[8*i:8*i+8]]
 i=input()[::-1]1];a=i[0]*8+i[1];b=G[a]
 if G[i[0]][i[1]]=='*'i[2]:G[a]=(chr(ord(b[0])+1)if'"'!=b[0]else' ')+b[1:];continue
 if'*'==b:print'L';break
 if'!'!=b:V(ia)

ToNeeds to be improved: grid-makingfunction R [get all squares around item p] (71 + 13 import101 chars), revealing codeprinting (16069 chars), flagging (72 chars)

Python (502)

Input is given while the game is running. No support for flags yet, may get to that soon.

import random
A=[-1,0,1]
R=lambda(x,y):[[x+i,y+j]for i in A for j in A if([i,j]!=[0,0])&(-1<x+i<8)&(-1<y+j<8)]
M=lambda p:sum(G[i][j]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=M(p);G[a][b]=`m`if m else' '
 if m>0:return
 for c in R(p):
  f,g=c
  if'.'!=G[f][g]:continue
  m=M(c);G[f][g]=`m`
  if m==0:G[f][g]=' ';V(c)
 
G=['.']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'.'in`G`:
 for i in G:print`i`.replace('*','.')
 i=input()[::-1]
 if G[i[0]][i[1]]=='*':print'L';break
 V(i)

To be improved: grid-making (71 + 13 import chars), revealing code (160 chars)

Python (502 566)

Checklist:

Randomized mine generation - yes
8x8 field with 10 mines - yes
Mine and "unknown" flags - yes
Reveal nearby blank spaces when a blank space has been revealed. - yes
Input and output code: It must be playable. - yes

It has a win detector as well.

Input is given while the game is running, with (f, x, y). (x, y) is the coordinates of the grid selection, f is whether you want to flag or not. (0, 0, 0) would open up (0, 0), and (1, 2, 3) would flag (2, 3). Flagging works in a cycle: flagging a square twice gives a question mark.

(number) - number of mines
(space) - unexplored
. - 0 mines
! - flag
" - question

import random
A=[-1,0,1]
R=lambda x:[x+i for i in[-9,-8,-7,-1,1,7,8,9]if(0<x+i<64)&([i,x%8]not in([7,0],[-7,7],[-1,0],[1,7]))]
M=lambda p:sum(G[i]=='*'for i in R(p))
def V(p):
 m=M(p);G[p]=`m`if m else'.'
 if m>0:return
 for c in R(p):
  if' '!=G[c]:continue
  m=M(c);G[c]=`m`
  if m==0:G[c]='.';V(c)
G=[' ']*54+['*']*10
random.shuffle(G)
while' 'in`G`:
 for i in range(8):print[j.replace('*',' ')[0]for j in G[8*i:8*i+8]]
 i=input()[::-1];a=i[0]*8+i[1];b=G[a]
 if i[2]:G[a]=(chr(ord(b[0])+1)if'"'!=b[0]else' ')+b[1:];continue
 if'*'==b:print'L';break
 if'!'!=b:V(a)

Needs to be improved: function R [get all squares around item p] (101 chars), printing (69 chars), flagging (72 chars)

added 122 characters in body
Source Link
beary605
  • 4.4k
  • 2
  • 26
  • 52

Python (502)

Input is given while the game is running. No support for flags yet, may get to that soon.

import random
A=[-1,0,1]
R=lambda(x,y):[[x+i,y+j]for i in A for j in A if([i,j]!=[0,0])&(-1<x+i<8)&(-1<y+j<8)]
M=lambda p:sum(G[i][j]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=M(p);G[a][b]=`m`if m else' '
 if m>0:return
 for c in R(p):
  f,g=c
  if'.'!=G[f][g]:continue
  m=M(c);G[f][g]=`m`
  if m==0:G[f][g]=' ';V(c)

G=['.']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'.'in`G`:
 for i in G:print`i`.replace('*','.')
 i=input()[::-1]
 if G[i[0]][i[1]]=='*':print'L';break
 V(i)

To be improved: grid-making (71 + 13 import chars), revealing code (160 chars)

Python (502)

import random
A=[-1,0,1]
R=lambda(x,y):[[x+i,y+j]for i in A for j in A if([i,j]!=[0,0])&(-1<x+i<8)&(-1<y+j<8)]
M=lambda p:sum(G[i][j]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=M(p);G[a][b]=`m`if m else' '
 if m>0:return
 for c in R(p):
  f,g=c
  if'.'!=G[f][g]:continue
  m=M(c);G[f][g]=`m`
  if m==0:G[f][g]=' ';V(c)

G=['.']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'.'in`G`:
 for i in G:print`i`.replace('*','.')
 i=input()[::-1]
 if G[i[0]][i[1]]=='*':print'L';break
 V(i)

To be improved: grid-making (71 + 13 import chars)

Python (502)

Input is given while the game is running. No support for flags yet, may get to that soon.

import random
A=[-1,0,1]
R=lambda(x,y):[[x+i,y+j]for i in A for j in A if([i,j]!=[0,0])&(-1<x+i<8)&(-1<y+j<8)]
M=lambda p:sum(G[i][j]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=M(p);G[a][b]=`m`if m else' '
 if m>0:return
 for c in R(p):
  f,g=c
  if'.'!=G[f][g]:continue
  m=M(c);G[f][g]=`m`
  if m==0:G[f][g]=' ';V(c)

G=['.']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'.'in`G`:
 for i in G:print`i`.replace('*','.')
 i=input()[::-1]
 if G[i[0]][i[1]]=='*':print'L';break
 V(i)

To be improved: grid-making (71 + 13 import chars), revealing code (160 chars)

Source Link
beary605
  • 4.4k
  • 2
  • 26
  • 52

Python (502)

import random
A=[-1,0,1]
R=lambda(x,y):[[x+i,y+j]for i in A for j in A if([i,j]!=[0,0])&(-1<x+i<8)&(-1<y+j<8)]
M=lambda p:sum(G[i][j]=='*'for i,j in R(p))
def V(p):
 a,b=p;m=M(p);G[a][b]=`m`if m else' '
 if m>0:return
 for c in R(p):
  f,g=c
  if'.'!=G[f][g]:continue
  m=M(c);G[f][g]=`m`
  if m==0:G[f][g]=' ';V(c)

G=['.']*54+['*']*10
random.shuffle(G)
G=[G[8*i:8*i+8]for i in range(8)]
while'.'in`G`:
 for i in G:print`i`.replace('*','.')
 i=input()[::-1]
 if G[i[0]][i[1]]=='*':print'L';break
 V(i)

To be improved: grid-making (71 + 13 import chars)