Cruzada

Upload your latest creations here.
Please note that by posting comments to posts in this forum you forfeit your personal copyright on whatever you post. AI Scripters reserves the right to re-use objective comments in script reviews without requiring the posting author's permission. Credit, where appropriate will be given in such cases.
Post Reply
scripter64
Waheguru
Posts: 5891
Joined: Fri Jan 16, 2009 8:36 pm

Re: Cruzada

Post by scripter64 »

_II2N_ wrote:Shouldn't it be (up-reset-search 1 1 1 1)?
Yes, sorry!

User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

Cruzada updated again, in theory. I'ts better in a few aspects, but buggier in others.

I still have the same mining camp problems. I've took my sns about mining from Crusade because they worked. This code is in the Start file:

Code: Select all

(defrule
	(true)
=>
	(set-strategic-number sn-food-dropsite-distance 30)
	(set-strategic-number sn-wood-dropsite-distance 15)
	(set-strategic-number sn-stone-dropsite-distance IDEAL-DROP-DISTANCE) ; later 100
	(set-strategic-number sn-gold-dropsite-distance IDEAL-DROP-DISTANCE) ; later 35

	(set-strategic-number sn-maximum-food-drop-distance 40)
	(set-strategic-number sn-maximum-wood-drop-distance 255) ; later 15
	(set-strategic-number sn-maximum-stone-drop-distance BUILDING-DROP-DISTANCE) ; later 25
	(set-strategic-number sn-maximum-gold-drop-distance BUILDING-DROP-DISTANCE) ; later 25
	(disable-self)
)

; To avoid gold camps placed in stone and viceversa
(defrule
	(goal g-gold-mine 1)
	(or	(strategic-number sn-gold-dropsite-distance > IDEAL-DROP-DISTANCE)
		(strategic-number sn-maximum-gold-drop-distance > BUILDING-DROP-DISTANCE)
	)
=>
	(set-strategic-number sn-gold-dropsite-distance IDEAL-DROP-DISTANCE)
	(set-strategic-number sn-maximum-gold-drop-distance BUILDING-DROP-DISTANCE)
)

(defrule
	(goal g-stone-mine 1)
	(or	(strategic-number sn-stone-dropsite-distance > IDEAL-DROP-DISTANCE)
		(strategic-number sn-maximum-stone-drop-distance > BUILDING-DROP-DISTANCE)
	)
=>
	(set-strategic-number sn-stone-dropsite-distance IDEAL-DROP-DISTANCE)
	(set-strategic-number sn-maximum-stone-drop-distance BUILDING-DROP-DISTANCE)
)
Such constants are:
(defconst IDEAL-DROP-DISTANCE 4)
(defconst BUILDING-DROP-DISTANCE 6)

My miningg camp rules are inspired by Crusade, but starting camps in different moments and using a goal instead of a taunt because goals are more practical and UP allows a lot of them. This code in the General Economy file:

Code: Select all

(defrule
	;(strategic-number G-AGE-STATUS >= GV-ADVANCING-TO-FEUDAL)
	(goal g-gold-mine 1)
	;(or	(unit-type-count MALE-GOLD-MINER > 0);Male gold miner
		;(unit-type-count FEMALE-GOLD-MINER > 0))  ;Female gold miner 
	(resource-found gold)
	;(or	(current-age >= castle-age)
	;	(building-type-count-total mining-camp < 4)
	;)
	(cc-players-unit-type-count 0 gold-mine > 0) 
	(or	(dropsite-min-distance gold > BUILDING-DROP-DISTANCE)
		(building-type-count-total mining-camp == 0)
	)
	(dropsite-min-distance gold < 255) ; To avoid infinite gold camps with gold exhausted
	(can-build mining-camp)
	(up-pending-objects c: mining-camp < 1)
 =>
	(build mining-camp)
	;(set-goal G-BUILDING 0)
)

(defrule
	;(strategic-number G-AGE-STATUS >= GV-ADVANCING-TO-FEUDAL)
	(goal g-stone-mine 1)
	(resource-found stone)
	;(or	(current-age >= castle-age)
	;	(building-type-count-total mining-camp < 4)
	;)
	(cc-players-unit-type-count 0 stone-mine > 0) 
	(or	(dropsite-min-distance stone > BUILDING-DROP-DISTANCE)
		(building-type-count-total mining-camp == 0)
	)
	(dropsite-min-distance stone < 255) ; To avoid infinite stone camps with stone exhausted
	(can-build mining-camp)
	(up-pending-objects c: mining-camp < 1)
=>
	(build mining-camp)
	;(set-goal G-BUILDING 0)
)

; Extra camps when lost of miners
(defrule
	(up-get-fact unit-type-count villager-gold g-math-1)
	(up-get-fact unit-type-count villager-stone g-math-2)
	(up-get-fact building-type-count-total mining-camp g-math-3)
=>
	(up-modify-goal g-math-1 g:+ g-math-2)
	(up-modify-goal g-math-3 c:* 10)
)
(defrule
	(or	(goal g-gold-mine 1)
		(goal g-stone-mine 1)
	)
	(or	(resource-found gold)
		(resource-found stone)
	)
	(up-compare-goal g-math-1 c:> g-math-3)
	(dropsite-min-distance gold < 255) ; To avoid infinite gold camps with gold exhausted
	(can-build mining-camp)
	(up-pending-objects c: mining-camp < 1)
=>
	(build mining-camp)
	(enable-timer t-new-camp-for-dead-miners tv-new-camp-for-dead-miners)
)

; More camps if dead miner. Based in Echidna's rule for extra lumber camps
(defrule
	(timer-triggered t-new-camp-for-dead-miners)
	(or	(unit-type-count male-dead-miner > 0)
		(unit-type-count female-dead-miner > 0)
	)
	(or	(goal g-gold-mine 1)
		(goal g-stone-mine 1)
	)
	(or	(resource-found gold)
		(resource-found stone)
	)	
	(dropsite-min-distance gold < 255) ; To avoid infinite gold camps with gold exhausted
	(can-build mining-camp)
	(up-pending-objects c: mining-camp < 1)
=>
	(build mining-camp)
	(enable-timer t-new-camp-for-dead-miners tv-new-camp-for-dead-miners)
)

I told that I'd try to ask things in the chat. But I've thought that this was too much info to type it in the chat. Anyway, if you prefer answer this on it instead here, just tell it and I'll chat with you. I just can play at weekends, but I can use internet every day.

Archon
Waheguru
Posts: 1905
Joined: Sat Nov 08, 2003 9:22 am

Re: Cruzada

Post by Archon »

dropsite-min-distance works like this
dropsite-min-distance 255 = no resource on mainland left, but some on other islands
dropsite-min-distance -1 = resources depleted or never sighted
However you should still restrict the number of camps, in case some resources left are trapped by other obstacles or too small that the game engine considers them worth for a camp.

There are some syntax errors in your code:
(up-compare-goal g-math-1 c:> g-math-3)
should be
(up-compare-goal g-math-1 g:> g-math-3)

The dead mining camp build rule never fires, if you never build a camp with the many miner camps rule. Better use (up-timer-status t-new-camp-for-dead-miners != timer-running) instead of (timer-triggered t-new-camp-for-dead-miners)

User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

Thanks Archon, my mining camps seem to work well now. :)

Cruzada updated again. It almost defeats a Celt Crusade in a test, it even doubled him in score, but I lacked still rules for late games and wood starting to be exhausted, so Crusade won by starvation despite to lose thousands of wars. Cruzada is more robust now, bit it was defeated again by (Hun) Crusade, because he built a castle in front of Mayan base, where poor soldiers had problems to win because just a few rams abd problems to train more.

Anyway, I am quite satisfied with the progression of my new AI. It's still incomplete and lacks things which are key in specific situations, but it's evident that in a few aspects is a stronger and more modern AI than his ancestor, Crusade. B)

User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

Cruzada updated again. I call it Cruzada Maya instead of Betha because although it has a lot of things to improve it could be considered complete. If you can call complete an AI for a single civ and just for Arabia 1v1. :P

It has even beaten Crusade.

It's main weakness is its battle performance. My idea are these steps:
1- Superiority => DUC vs lumber and mining camps.
2- No enemy lumber or mining camps => TSA
3- Even if camps detected, after 10'' change into TSA if enough siege units vs enemy towers/castles.

Steps 1 and 2 work. DUC if camps, TSA if not camps. But my idea to change into TSA 10'' secs later doesn't work, so once camps detected DUC is kept until attack finishes or camps destroyed.

This is the code from "Attack.per" that I use to select attack modes. I know that my condition to detect if enough siege for towers is ok, because in flushes even when debug instructions say siege is zero (of course) and threat tower is also zero (just when enemy really doesn't tower), the change into TSA doesn't happen.

Code: Select all

(defrule
	(goal g-attack gv-no-attack)
	(or	(goal g-under-attack gv-no)
		(up-enemy-units-in-town < 2)
	)
	(or	(up-compare-goal g-military-superiority c:>= gv-military-stronger)
		(and	(current-age == imperial-age)
			(and	(up-compare-goal g-population g:>= g-top-population)
				(goal g-military-upgrades 1)
			)
		)
	)
=>
	(set-goal g-attack gv-duc)
	(chat-local-to-self "Attack!")
	(enable-timer t-duc-into-tsa tv-duc-into-tsa)
)
(defrule
	(up-compare-goal g-attack c:!= gv-no-attack)
=>
	(up-get-target-fact building-type-count lumber-camp g-math-1)
	(up-get-target-fact building-type-count mining-camp g-math-2)
	(up-get-target-fact unit-type-count-total battering-ram-line g-math-3)

	(up-get-target-fact unit-type-count-total trebuchet g-math-6)
	(up-get-target-fact unit-type-count-total unpacked-trebuchet g-math-7)
	(up-get-target-fact unit-type-count-total bombard-cannon g-math-8)
	(up-modify-goal g-math-6 g:+ g-math-7)

	(up-modify-goal g-math-6 g:+ g-math-8)
	(up-modify-goal g-math-6 c:* 2)
	(up-modify-goal g-math-3 g:+ g-math-6)

	(up-reset-search 1 1 1 1)
	(up-reset-filters)
)

(defrule
	(goal g-attack gv-duc)
	(up-compare-goal g-math-1 c:>= 1)
	(up-find-remote c: lumber-camp c: 10)
=>
	(set-goal g-attack gv-duc)
	(up-filter-exclude -1 actionid-explore -1 -1)
	(up-filter-exclude -1 -1 -1 warship-class)
	(up-filter-include cmdid-military -1 -1 -1)
	(up-find-local c: -1 c: 200)
	(up-set-target-object search-remote c: 0)
	(up-target-objects 0 action-default -1 stance-aggressive)
	(chat-local-to-self "DUC vs enemy lumber camp!")
)
(defrule
	(goal g-attack gv-duc)
	(up-compare-goal g-math-1 c:== 0)
	(up-compare-goal g-math-2 c:>= 1)
	(up-find-remote c: mining-camp c: 10)
=>
	(up-filter-exclude -1 actionid-explore -1 -1)
	(up-filter-exclude -1 -1 -1 warship-class)
	(up-filter-include cmdid-military -1 -1 -1)
	(up-find-local c: -1 c: 200)
	(up-set-target-object search-remote c: 0)
	(up-target-objects 0 action-default -1 stance-aggressive)
	(chat-local-to-self "DUC vs enemy mining camp!")
)

(defrule
	(goal g-attack gv-duc)
	(or	(and	(up-compare-goal g-math-1 c:== 0)
			(up-compare-goal g-math-2 c:== 0)
		)
		(and	(up-timer-status t-duc-into-tsa != timer-running)
			(up-compare-goal g-math-3 >= g-threat-tower) ; Enough siege vs enemy towers/castles
		)
	)
	(players-building-count every-enemy > 0) ; Targeted enemy has buildings
=>
	(set-goal g-attack gv-tsa)
	(up-modify-goal g-math-4 g:= g-distance-to-enemy)
	(up-modify-goal g-math-4 c:+ 2)
	(up-reset-search 1 1 1 1)
	(up-reset-filters)
	(chat-local-to-self "DUC into TSA")

)

(defrule
	(goal g-attack gv-duc)
	(or	(and	(up-compare-goal g-math-1 c:== 0)
			(up-compare-goal g-math-2 c:== 0)
		)
		(and	(up-timer-status t-duc-into-tsa != timer-running)
			(up-compare-goal g-math-3 >= g-threat-tower) ; Enough siege vs enemy towers/castles
		)
	)
	(players-building-count every-enemy == 0) ; Targeted enemy has NOT buildings
=>
	(set-goal g-attack gv-tsa)
	(up-modify-goal g-math-4 c:= 256)
	(up-reset-search 1 1 1 1)
	(up-reset-filters)
	(chat-local-to-self "DUC into TSA")
)

scripter64
Waheguru
Posts: 5891
Joined: Fri Jan 16, 2009 8:36 pm

Re: Cruzada

Post by scripter64 »

If the DUC units are moving in groups, TSA won't be able to control those units until they're halted/disbanded. Maybe try up-reset-unit on your military to "stop" them, so they are eligible for TSA control. TSA also requires non-monk military to be aggressive stance and monks to be at least defensive stance to control them. This fact can be used to intentionally keep some DUC raiders while everyone else attacks with TSA.

User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

Ok, I'll try to do it with the adequate changes. In worst case at least I will know that I should send TSA and change into DUC if required. Perhaps even cancel the attack and advance to next age, like Barbarian does, leaving DUC just to send a few camp raiders while most of the army TSA.

Another thing. I was thinking about to check the distance of interesting enemy points like nearest camps and nearest towers/castles. Here there is an example to get distance from center of the map.

Code: Select all

(defrule
	(true)
=>
	(up-get-point position-self gl-self-x)
	(up-get-point position-center gl-center-x)
	(up-get-point-distance gl-self-x gl-center-x gl-distance)
)
Could I use up-find-remote to select such interesting targets/places_to_avoid the one after the other, get their distance and decide later what to do?

scripter64
Waheguru
Posts: 5891
Joined: Fri Jan 16, 2009 8:36 pm

Re: Cruzada

Post by scripter64 »

It's possible if you use find-remote in a jump-loop to search 1 object at a time. This can be a bit complex, though.

User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

After to test again I remember that one of the problems was here:

(defrule
(goal g-attack gv-duc)
(or (and (up-compare-goal g-math-1 c:== 0)
(up-compare-goal g-math-2 c:== 0)
)
(and (up-timer-status t-duc-into-tsa != timer-running)
(up-compare-goal g-math-3 >= g-threat-tower) ; Enough siege vs enemy towers/castles
)

)
(players-building-count every-enemy > 0) ; Targeted enemy has buildings
=>
(set-goal g-attack gv-tsa)
(up-modify-goal g-math-4 g:= g-distance-to-enemy)
(up-modify-goal g-math-4 c:+ 2)
(up-reset-search 1 1 1 1)
(up-reset-filters)
(chat-local-to-self "DUC into TSA")
)

And in the (and (up-timer-status t-duc-into-tsa != timer-running)
(up-compare-goal g-math-3 >= g-threat-tower) ; Enough siege vs enemy towers/castles
)
the problematic part is:
(up-timer-status t-duc-into-tsa != timer-running)

I know it because my DUC turned TSA again if not camps detected. And the condition (up-compare-goal g-math-3 >= g-threat-tower) works because a debug rule showed that when I attack in feudal enemy lacks towers, etc, g-math-3 is zero because i lack siege and g--threat-towers is zero because enemy idem.

So the problem is something related to the timer t-duc-into-tsa.


I'll have to think an alternative way to send grouped units and later disgroup them to attack.

Archon
Waheguru
Posts: 1905
Joined: Sat Nov 08, 2003 9:22 am

Re: Cruzada

Post by Archon »

I think an easy way (not necessarily the best) is:

Code: Select all

(defrule
	(goal tsa yes)
	(or
		(players-building-type-count target-player lumber-camp > 0)
		(players-building-type-count target-player mining-camp > 0)
	)
	(up-building-type-in-town c: mining-camp == 0)
	(up-building-type-in-town c: lumber-camp == 0)
=>
	(up-modify-sn sn-maximum-town-size c:+ 3)
	(set-strategic-number sn-disable-defend-groups 1); so your units won't walk off if there is something else in town. Just set it back to 0 at the start of each rule pass.
)
If you set the defense priorities accordingly, your units will go for the camps first and ignore other buildings.

If you have a tower/TC/castle in town, you can disable TSA and use DUC. Find a camp not next to defense and use waypoints to move around the defense.
Last edited by Archon on Sat Dec 13, 2014 2:38 am, edited 1 time in total.

Post Reply