#!/usr/bin/python
#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

import string

import kw_cgi
import ascii
import evaluate
import scenarios

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Map(kw_cgi.CGI):

	def header( self, title, id ):

		print ( '<head>\n'
			'<title>Settlers of Catan: %s map (%d)</title>\n'
			'</head>\n'
			'<body bgcolor=#ffffff>\n' 
			'<font size=+1>Settlers of Catan: %s map (%d)</font>\n'
			'<hr>' ) % \
			(title, id, title, id)

	def footer( self ):

		print '</body>'
		print '</html>'

	def action( self ):

		map = string.lower( self.get_arg( 'map', 'normal' ) )
		id  = string.atoi(  self.get_arg( 'id',  '0' ) )
		eval= string.lower( self.get_arg( 'eval', '' ) )

		l = ascii.ASCII()

		if map == 'expansion':
			b = scenarios.Expansion( l, id )
			self.header( '5-6 player', b.seed )

		elif map == 'bigisland':
			b = scenarios.BigIsland( l, id )
			self.header( '7-8 player', b.seed )

		else:
			b = scenarios.Normal( l, id )
			self.header( '3-4 player', b.seed )

		print '<pre>'
		b.draw()
		print '</pre>'

		if eval:
			print '<hr>'
			print '<pre>'
			e = evaluate.Simple( b )
			e.evaluate()
			print '</pre>'

		self.footer()

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Map()