Ejemplo n.º 1
0
def Build(c, what_to_build):
	if api.type_case(c[2],c[1]) != VIDE:
		return False
	best_place = (-1,-1)
	mincost = 1000
	for i in range(TAILLE_CARTE):
		for j in range(TAILLE_CARTE):
			if api.type_case(j,i) != ROUTE:
				continue
			d = api.distance(j,i,c[2],c[1])
			if d > 0 and d < mincost:
				mincost = d;
				best_place = (i,j)
				
	assert best_place[0] > 0
	
	while max(abs(c[1]-best_place[0]), abs(c[2]-best_place[1])) > 1:
		if api.finances(0) == 0:
			vendre_pour(api.cout_achat_route())
		best = api.distance(best_place[1],best_place[0],c[2],c[1])
		bestdir = 0
		for dir in directions4:
			d = api.distance(best_place[1] + dir[1], best_place[0] + dir[0], c[2], c[1])
			if d < best:
				best = d;
				bestdir = dir		
		if best >= TROP_LOIN:
			return False
		best_place = (best_place[0] + bestdir[0], best_place[1] + bestdir[1])
		api.construire_route(best_place[1], best_place[0])
	
	if what_to_build == "maison":
		vendre_pour(api.cout_achat_route() - api.finances(0))
		api.construire_maison(c[2],c[1])
	else:
		assert what_to_build == "monument"
		api.construire_maison(c[2],c[1])
	return True
Ejemplo n.º 2
0
def jouer():
	if not api.mon_tour():
		return
	pos = []
	for i in range(TAILLE_CARTE):
		for j in range(TAILLE_CARTE):			
			if api.type_case(j,i) == VIDE or api.type_case(j,i) == RESERVATION \
				    and api.appartenance(j,i) == 0 and api.construction_possible(j,i) != BLOCAGE:
				v = api.valeur_case(j,i) - plus_proche_route((0,i,j));
				pos.append((v, i, j));
	pos.sort()
	for k in range(2):
		c = pos.pop()
		Build(c, "maison")
	if api.numero_tour() == 15:
		print "******** Python Final score = ", api.score(0) + api.finances(0), " **********"