예제 #1
0
def plus_proche_route(c):
	best_place = ()
	mincost = 1000
	how_far = 6
	for i in range(c[1]-how_far, c[1]+how_far+1):
		for j in range(c[2]-how_far, c[2]+how_far+1):
			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)
	return mincost
예제 #2
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