# Rachel Lloy d
#March 10, 2010
#ACSL - #3
#Senior-3
#Potter
#Enloe High School
BLACK="X"
WHITE="O"
def make_board():
board=[]
for i in
range(1,31):
board.append(i)
return board
def print_board(board):
temp=[]
for i in
range(0,10):
temp.append([])
temp[0].append(b[i])
for i in
range(19,9,-1):
temp.append([])
temp[1].append(b[i])
for i in
range(20,30):
temp.append([])
temp[2].append(b[i])
print temp[0]
print temp[1]
print temp[2]
def make_move(board,rods):
ans=[False,False]
count=0
while count<2:
if
len(rods)%2==0:
turn=BLACK
else:
turn=WHITE
move=False
for i in
range(0,30):
if
turn==board[i]:
move=i+1
new_pos=False
moved=0
while
moved==0 and move!=False:
pos=move+rods[0]
if
pos>26 and move<26:
#print "House of Happinesss"
pos=26
new_pos=pos
moved=1
if
pos==27:
#print "House of Waters"
pos=27
if
board[pos-rods[0]-1]==board[pos-1]:
#print "spot taken by same color"
pos=pos
elif
(str(board[pos-1]) is BLACK) or (str(board[pos-1]) is WHITE):
#print "switching places"
moved=1
if ans[0]-1==pos-1:
ans[0]=move
m=pos-rods[0]
temp=board[pos-1]
board[pos-1]=board[m-1]
board[m-1]=m
board[move-1]=temp
new_pos=pos
pos=15
move=27
else:
#print "moving normally"
moved=1
board[pos-1]=board[move-1]
board[move-1]=move
new_pos=pos
move=27
pos=15
if
move==27 and rods[0] is not 4 and pos!=15:
#print "!!!!!!!!!!!!"
pos=27
if
move==28 and rods[0] is not 3:
#print "House of Three Truths"
pos=28
if
move==29 and rods[0] is not 2:
#print "House of Re-Atoum"
pos=29
if
move==30 and rods[0] is not 1:
#print "Rule of 30"
pos=30
if
pos==31:
#print "Done"
board[move-1]=move
new_pos=31
moved=1
if
pos<31:
if
board[move-1]==board[pos-1]:
#print "spot taken by same color"
pos=pos
elif
(str(board[pos-1]) is BLACK) or (str(board[pos-1]) is WHITE):
#print "switching places"
moved=1
if ans[0]-1==pos-1 or ans[0]==-1:
ans[0]=move
temp=board[pos-1]
board[pos-1]=board[move-1]
board[move-1]=move
board[move-1]=temp
new_pos=pos
else:
#print "moving normally"
moved=1
board[pos-1]=board[move-1]
board[move-1]=move
new_pos=pos
if
moved==0:
m=move
move=-1
for i
in range(0,m-1):
if turn==board[i]:
move=i+1
if
move==-1:
moved=1
new_pos=-1
ans[count]=new_pos
print_board(board)
count+=1
rods=rods[1:]
for i in
range(2):
if ans[i]==31:
ans[i]="DONE"
if ans[i]==-1
or ans[i]==False:
ans[i]="NO VALID MOVES"
print ans
return board,rods
def get_input(board):
f=open('sr.txt','r')
text=f.readlines()
text[0]=text[0][:-1]
text[1]=text[1][:-1]
text[2]=text[2][:-1]
c=int(text[0][:text[0].index(',')])
text[0]=text[0][text[0].index(',')+1:]
for i in
range(0,c):
if ',' in
text[0]:
board[int(text[0][:text[0].index(',')])-1]=BLACK
text[0]=text[0][text[0].index(',')+1:]
board[int(text[0])-1]=BLACK
c=int(text[1][:text[1].index(',')])
text[1]=text[1][text[1].index(',')+1:]
for i in
range(0,c):
if ',' in
text[1]:
board[int(text[1][:text[1].index(',')])-1]=WHITE
text[1]=text[1][text[1].index(',')+1:]
board[int(text[1])-1]=WHITE
rods=[]
while ',' in
text[2]:
rods.append(int(text[2][:text[2].index(',')]))
text[2]=text[2][text[2].index(',')+1:]
rods.append(int(text[2]))
#print_board(board)
# print rods
return board,rods
b=make_board()
b,r=get_input(b)
print
while len(r)>0:
print_board(b)
b,r=make_move(b,r)
print
print
print