Python — 982
Count is 982 not counting tabs and newlines. This includes necessary spaces. Started learning python this week, so I had some fun :). Pretty straight forward, nothing fancy here, besides the crappy var names to make it shorter.
import re
def m():
s=''
while 1:
y=raw_input()
if y=='':break
s=s+y+'\n'
t=a(s)
t.s()
t.p()
class a:
def __init__(x,y):
x.t=len(y);
r=re.compile('(.*)\n')
x.z=r.findall(y)
x.w=len(x.z[0])
x.v=len(x.z)
def s(x):
n=0
for i in range(0,x.t):
if(x.x(i,0)):
break
def x(x,d,c):
b=x.z[:]
for i in range(1,x.v+1):
for j in range(1,x.w+1):
if x.c():
break;
x.z=b[:]
x.u(i,j)
if d!=c:
x.x(d,c+1)
if x.c():
break;
if x.c():
return 1
x.z=b[:]
return 0;
def y(x,r,c):
e=x.z[r-1][c-1]
if e=='*':
return '.'
elif e=='x':
return 'X'
elif e=='X':
return 'x'
else:
return '*'
def j(x,r,c):
v=x.y(r+1,c)
x.r(r+1,c,v)
def k(x,r,c):
v=x.y(r-1,c)
x.r(r-1,c,v)
def h(x,r,c):
v=x.y(r,c-1)
x.r(r,c-1,v)
def l(x,r,c):
v=x.y(r,c+1)
x.r(r,c+1,v)
def u(x,r,c):
e=x.z[r-1][c-1]
if e=='*' or e=='x':
v='X'
else:
v='x'
x.r(r,c,v)
if r!=1:
x.k(r,c)
if r!=x.v:
x.j(r,c)
if c!=1:
x.h(r,c)
if c!=x.w:
x.l(r,c)
def r(x,r,c,l):
m=x.z[r-1]
m=m[:c-1]+l+m[c:]
x.z[r-1]=m
def c(x):
for i in x.z:
for j in i:
if j=='*' or j=='x':
return 0
return 1
def p(x):
for i in x.z:
print i
print '\n'
if __name__=='__main__':
m()
Usage:
*...*
**.**
..*..
*.*..
*.**.
X.X.X
..X..
.....
.....
X.X..