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
User avatar
Campeador
Waheguru
Posts: 1340
Joined: Mon Nov 01, 2010 8:11 am
Location: Spain

Re: Cruzada

Post by Campeador »

Very thanks, my counter system works now. :D At least until my next "improvements". :P

Although as usual in the :head world I've got new problems, of course :rolleyes:.

a) Mining camps spammed like crazy in late game. Here you have my mining camp rules:

Code: Select all

(defrule
	(goal g-stone-mine 1)
=>
	(set-strategic-number sn-maximum-stone-drop-distance 255)
)
(defrule
	(goal g-gold-mine 1)
=>
	(set-strategic-number sn-maximum-gold-drop-distance 255)
)

(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)
)

(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)
)

; More camps if dead miner. Based in Echidna's rule for extra lumber camps
(defrule
	(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)
	)
	(building-type-count-total mining-camp < 4)
	(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)
)

Other problem is my TSA. It doesn't work because my goal g-distance-to-enemy is -1 when no enemy building detected (which is normal) but zero when they are detected, which is obviously a mistake.

Code: Select all

(defrule
	(players-building-count any-enemy > 0)
=>
	(up-find-player enemy find-closest g-enemy-targeted)
	(up-modify-sn sn-focus-player-number g:= g-enemy-targeted)
	(up-get-target-fact player-distance 0 g-distance-to-enemy)
)

_II2N_
Guru
Posts: 639
Joined: Thu Jul 14, 2011 8:44 am

Re: Cruzada

Post by _II2N_ »

Dropsite-min-distance is -1 for gold/stone if there are no piles visible; it's 255 if there are piles visible but they are on other island. Sometimes there are a few gold/stone piles left in late game but AIs fail to drop camps at them, which can lead to camp-spamming. Best solution is probably having a limit for normally built camps and attempting to place a camp with DUC if there are no nearby mining camps. A possibility is also that camp-max-distance doesn't reach the resources. Checking whether camp-max-distance reaches anything requires DUC too.

You set focus-player in TSA rule instead of target-player, so target-player is probably unset, and up-get-target-fact will get data from player 0.

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

Re: Cruzada

Post by Campeador »

Thanks again. It seems that once I finish this AI, instead to say that the scripter is Campeador he is the aiscripters community. :lol:

Uploaded version 23 NOV:
- Improved early game.
- Counter system works.
- TSA faster.
- Worse late game. The reason is that Cruzada builds too many barracks and archeries in castle age before to have enough villagers to make them run. I know too the solution: give a higher priority to the town centers and to the market to buy stone for it until I have those villies. I can do it using the info that Justinian linked me about gathering rates, training times, etc. But I won't have time for it until next weekends.

So meanwhile enjoy this weak version. B)

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

Re: Cruzada

Post by Campeador »

New weekend. New doubts. B)

I've added DUC, but as expected I have problems even with a really simple DUC code. This algorith tries to attack with groups of 20 infantry and archers:

Code: Select all

(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:>= 1)
=>
	(up-find-local c: infantry-class c: 20)
	(up-find-local c: archery-class c: 20)
	(up-find-remote c: lumber-camp c: 1)
	(up-target-objects 0 action-default -1 stance-aggressive)
	(set-goal g-tsa 0)
)
(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:== 0)
	(up-compare-goal g-math-2 c:>= 1)
=>
	(up-find-local c: infantry-class c: 20)
	(up-find-local c: archery-class c: 20)
	(up-find-remote c: mining-camp c: 1)
	(up-target-objects 0 action-patrol -1 -1)
	(set-goal g-tsa 0)
)
(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:== 0)
	(up-compare-goal g-math-2 c:== 0)
	(players-building-count any-enemy > 0)
=>
	TSA bla bla bla
)
I've cheated in a few testing games to be sure that I'll get enough military superiority to attack early, training some m@a. They attack if I comment the line:
;(up-find-local c: archery-class c: 20)

But those (up-find-local c: infantry-class c: 20) and (up-find-local c: archery-class c: 20) together seems to avoid m@a attack as wished.

What I want is to learn to attack with EVERY SOLDIER I have into enemy's target with DUC to have grouped attacks. My next step will be to add a condition to change into TSA a few seconds later if enemy haven't too many towers/castles for my siege units, but its a different story. How can I send EVERYTHING against enemy target?


Second doubt. I've used (up-find-remote c: lumber-camp c: 1) to avoid possible problems if I've found just one lumber camp. I'd prefer
(up-find-remote c: lumber-camp c: 4) because perhaps the first lumber camp is protected by a tower and one of the next ones are more vulnerable. But should happen if I do ths but my explorers find just 1-3 lumber camps? Should DUC work then?

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

Re: Cruzada

Post by scripter64 »

For the second doubt, it should still work as the 1 or 4 are just the maximum, so if you use 4 and there are only 2, it will just find those 2. The most important thing when using DUC stuff is to (up-reset-search -1 -1 -1 -1) and (up-reset-filters) before starting a new search to avoid weirdness/unintentional mixing of previous results, and to set sn-focus-player-number to the target before using (up-find-remote). You can use (up-get-search-state) to get the current number of local and remote search results into goals and chat them out to help find the issues.

_II2N_
Guru
Posts: 639
Joined: Thu Jul 14, 2011 8:44 am

Re: Cruzada

Post by _II2N_ »

Shouldn't it be (up-reset-search 1 1 1 1)?

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

Re: Cruzada

Post by Archon »

In addition to what scripter said, I think it is better to use up-find-remote plus up-get-search-state and then compare the goal with the remote search results instead of using (up-find-remote c: lumber-camp c: 1) as a fact.

If you want top go through all targets there is up-set-target-object search-remote c: 0 [yes, computer scientists start counting at zero, so this is the first object] and then increase until you a) found a camp with no towers or b) went through as many camps as found with find-remote.

Code: Select all

	(up-reset-filters)
	(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-target-objects 0 action-default -1 stance-aggressive)
will send all military except your active scout and warships. I think you need a way to detect if you're soldiers are under attack, or else they will keep attacking that camp and ignore your enemy.

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

Re: Cruzada

Post by Campeador »

Sorry, but it doesn't work yet. It's evident that I haven't understood yet DUC stuff. I've tried this:

Code: Select all

(defrule
	(goal g-attack 1)
	(population < 190)
	(up-compare-goal g-military-superiority c:<= gv-military-weaker)
=>
	(set-goal g-attack 0)
	(up-reset-search 1 1 1 1)
	(up-reset-filters)
	(set-goal g-tsa 0)
	(up-retreat-now)
)

(defrule
	(goal g-attack 0)
	(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 1)
	(chat-local-to-self "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)
)

(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:>= 1)
	(up-find-remote c: lumber-camp c: 0)
=>
	(up-reset-search 1 1 1 1)
	(up-reset-filters)
	(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)
	(set-goal g-tsa 0)
)
(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:== 0)
	(up-compare-goal g-math-2 c:>= 1)
	(up-find-remote c: mining-camp c: 0)
=>
	(up-reset-search 1 1 1 1)
	(up-reset-filters)
	(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)
	(set-goal g-tsa 0)
)


(defrule
	(goal g-attack 1)
	(up-compare-goal g-math-1 c:== 0)
	(up-compare-goal g-math-2 c:== 0)
	(players-building-count any-enemy > 0)
=>
	[b][u]TSA[/u][/b]
)
What I've thought is that:
- (up-reset-search 1 1 1 1) and (up-reset-filters) allow to select new units avoiding problems with previously selected ones
- (up-filter-exclude -1 actionid-explore -1 -1) avoids to send the scout to fight and (up-filter-exclude -1 -1 -1 warship-class) the same with was ships
- (up-filter-include cmdid-military -1 -1 -1) turns selectable the rest of units
- (up-find-local c: -1 c: 200) selects every selectable unit with the "mouse"
- the condition (up-find-remote c: lumber-camp c: 0) tries to make enemy lumber camps "selectable"
- the fact (up-set-target-object search-remote c: 0) tries to select with the "mouse" the selectable enemy targets with send over there our own "selected with mouse" units to move/attack/etc
- (up-target-objects 0 action-default -1 stance-aggressive) is the "mouse click" to send our "clicked" soldiers to attack the "mouse clicked" enemy targets.

I've used a debug rule, so I know that g-attack is really set to "1" when desired, so the problem is that even my AI wants to attack it doesn't do it because my wrong DUC commands. Enemy is really targeted because my debug rule tells me how many soldiers have my targeted enemy and my own civilization.

Not too much problem anyway. While you are helping me to resolve (or better said, resolving :rolleyes: ) my DUC doubts, I'll test with my improved TSA adding no military stuff to make my AI stronger. B)

_II2N_
Guru
Posts: 639
Joined: Thu Jul 14, 2011 8:44 am

Re: Cruzada

Post by _II2N_ »

(up-find-remote c: lumber-camp c: 0) is same as (up-find-remote c: lumber-camp c: 1), although using the latter is recommended to avoid confusion.

If you use (up-find-remote c: lumber-camp c: 1) as a fact and then reset search, the list of found remote objects is reset, and you can't target them any more without new search.

Code: Select all

(defrule
(goal g-attack 1)
=>
(up-reset-search 1 1 1 1)
(up-reset-filters)
)

(defrule
(goal g-attack 1)
[...]
(up-find-remote c: lumber-camp c: 1)
=>
;(up-reset-search 1 1 1 1) <-- not necessary IF search has been reset in a rule above. If search is reset here, lumber-camp must be searched again
(up-reset-filters)
(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)
(set-goal g-tsa 0)
)
Maybe you could join the IRC channel so that helping is easier: http://afk.aiscripters.net/chat.html

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

Re: Cruzada

Post by Campeador »

Ty, my DUC now works as desired. Next doubt which could mean a whole conversation I'll send it in the chat to make you easier to help me. If I've got an interesting idea with potential conversations I'll also add it. :ph34r:

Post Reply