#!/usr/bin/env python
#
# Mastermind 1.0
# Copyright (C) 2008
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# file: maker.py
# purpose: provide the behavior of a code maker

######################################################

import random

class Maker:

	# parametrize by the number of colors and pegs
	def __init__(self, colors=6, pins=4):
		self.colors = colors
		self.pins   = pins
		self.seq    = ""

		# use a fake brain to score the input
		from brains import Brain
		self.b = Brain(self.colors, self.pins, False)

	# prepare a secret key
	def generate(self, seq=""):
		self.seq = ""
		if len(seq) != self.pins:
			for i in range(self.pins):
				self.seq += "%d" % random.randint(0,self.colors-1)
		else:
			self.seq = seq

	# use the brain to compute the score of an input
	def reply(self, seq):
		return self.b.diff( seq, self.seq )

