#!/usr/bin/python

import sys

def str_to_ind(str):
	if str >= 'a' and str <= 'z':
		ind = ord(str) - ord('a')
	elif str >= 'A' and str <= 'Z':
		ind = ord(str) - ord('A') + 26
	else:
		print 'bad chr in str_to_ind',str
		sys.exit(1)
	return ind

def process(file,board,piece):
	while 1:
		line = file.readline()
		if not line:
			break
		rowstr = line[0:1]
		colstr = line[1:2]
		row = str_to_ind(rowstr)
		col = str_to_ind(colstr)
		board[row][col] = piece


def black_output(file,x,y):

	s='''
	sphere {
        <0,0,0> stonesize scale <0.5,0.5,0.2> translate z*0.1
        texture {
	  T_Stone16 scale 0.6 
	  translate <rand(R1)*200, rand(R1)*213, rand(R1)*321>
	}
	scale <rand(R5)*0.2+0.8, rand(R5)*0.2+0.8, 1> 
	rotate x*(rand(R5)*20-10) rotate y*(rand(R5)*20-10) rotate z*rand(R5)*90
	translate <0.55-linespace/2+xp*linespace+rand(R4)*Jitter-Jitter/2, 
	           0.55-linespace/2+yp*linespace+rand(R4)*Jitter-Jitter/2, 0>
      }
'''
	file.write('#declare xp='+str(x+1)+';\n')
	file.write('#declare yp='+str(y+1)+';\n')
	file.write(s)

def black_skip(file):

	s='''
      #declare h = rand(R1);  #declare h = rand(R1);  #declare h = rand(R1);
      #declare h = rand(R5);  #declare h = rand(R5);
      #declare h = rand(R5);  #declare h = rand(R5);  #declare h = rand(R5);
      #declare h = rand(R4);  #declare h = rand(R4);
'''
	file.write(s)


def white_output(file,x,y):

	s='''
      sphere {
        <0,0,0> stonesize scale <0.5,0.5,0.2> translate z*0.1
  	texture {
	  T_Stone17 scale 0.6 
	  translate <rand(R2)*200, rand(R2)*213, rand(R2)*321>
	}
	scale <rand(R6)*0.2+0.8, rand(R6)*0.2+0.8, 1> 
	rotate x*(rand(R6)*20-10) rotate y*(rand(R6)*20-10) rotate z*rand(R6)*90
	translate <0.5-linespace/2+xp*linespace+rand(R7)*Jitter-Jitter/2, 
	           0.5-linespace/2+yp*linespace+rand(R7)*Jitter-Jitter/2, 0> 
      }
'''
	file.write('#declare xp='+str(x+1)+';\n')
	file.write('#declare yp='+str(y+1)+';\n')
	file.write(s)

def white_skip(file):
	s='''
      #declare h = rand(R2);  #declare h = rand(R2);  #declare h = rand(R2);
      #declare h = rand(R6);  #declare h = rand(R6);
      #declare h = rand(R6);  #declare h = rand(R6);  #declare h = rand(R6);
      #declare h = rand(R7);  #declare h = rand(R7);
'''
	file.write(s)

def main():
	b = open('b','r')
	w = open('w','r')
	size = 35
	board=[]
	for i in range(0,size):
		board.append([])
		for j in range(0,size):
			board[i].append('0')
	#print board

	process(b,board,'1')
	#print
	#print board
	process(w,board,'2')
	#print
	
	for x in range(0,size):
		for y in range(0,size):
			if board[x][y] == '0':
				black_skip(sys.stdout)
				white_skip(sys.stdout)
			elif board[x][y] == '1':
				black_output(sys.stdout,x,y)
				white_skip(sys.stdout)
			elif board[x][y] == '2':
				black_skip(sys.stdout)
				white_output(sys.stdout,x,y)

main()