#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
import json

def drawBitboard(onefish, twofish, threefish):
	output = [" "]
	for i in range(59, -1, -1):
		if((onefish >> i) & 1) == 1:
			output.append("|1")
		elif ((twofish >> i) & 1) == 1:
			output.append("|2")
		elif ((threefish >> i) & 1) == 1:
			output.append("|3")
		else:
			output.append("| ")
		
		if(i % 15 == 0):
			output.append("|\n ")
		elif(i % 15 == 8):
			output.append("|\n")		
			
	print(''.join(output))

def drawPenguin(penguin):
	args = {
		"pos": str(penguin & 63).rjust(2),
		"A" : str((penguin >> 12) & 7),
		"B" : str((penguin >> 15) & 7), 
		"C" : str((penguin >> 18) & 7), 
		"D" : str((penguin >> 21) & 7), 
		"E" : str((penguin >> 24) & 7), 
		"F" : str((penguin >> 27) & 7), 
		"tot" : str((penguin >> 6) & 63).rjust(2)
	}
	print("Pos: {pos}, A:{A}, B:{B}, C:{C}, D:{D}, E:{E}, F:{F}, Tot: {tot}".format(**args))

if __name__ == "__main__":
	try:
		while True:
			read = []
			print("Enter state:")
			while True:
				line = input()
				if line == "":
					break
				read.append(line)
				
			state = json.loads(''.join(read))
			drawBitboard(state["bitboards"]["onefish"],state["bitboards"]["twofish"],state["bitboards"]["threefish"])
			print("Red penguins")
			for i in range(4):
				drawPenguin(state["penguins"]["red"][i])
			print("Blue penguins")
			for i in range(4):
				drawPenguin(state["penguins"]["blue"][i])
			
	except KeyboardInterrupt:
		print("\nMay the fish be with you.")