#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  mastermind.py
#  
#  Copyright 2015 Arne Hueffmeier <ahueffme@techfak.uni-bielefeld.de>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.


import random
import sys 

color = []

def chouseStartCode():
	global color
	for i in range(0,5):
		color.append(str(random.randrange(1,8)))
	print("\t\t ?????")


def userinput(round_cound):
	inp = input(str(round_cound)+")\t\t:")
	if (len(inp) != 5):
		return 0
	else:
		print("\t\t\t\t",end="")
		answer = []
		for i in range(0,5):
			if (inp[i] == color[i]):
				answer.append("P")
			elif (color.count(inp[i]) > 0):
				answer.append("C")
		answer.sort(reverse=True)
		for i in answer:
			print(i,end=",")
		print("")
		if (answer.count("P") == 5 ):
			print("Du hast die richtige Antwort nach",round_cound,"gefunden")
			return 2
	return 1



def main():
	round_cound = 12
	chouseStartCode()
	while(round_cound > 0):
		ret = userinput(round_cound)
		if (ret == 1):
			round_cound -= 1
		elif(ret == 2):
			sys.exit()
	print("Du hast es nicht geschaft in 12 zügen die Lösung zu finden:")
	print("\t\t",end="")
	for i in color:
		print(i,end="")


if __name__ == '__main__':
	main()
