dreiche2
Prince
- Joined
- Apr 9, 2003
- Messages
- 320
I expanded a little bit on the choke point algorithm I used once in my flavor scripts. This little module searches for choke points on the current map, evaluates their 'chokiness' using a custom algorithm, and then places forts on the better choke points.
Choke value:
The idea is that a choke point between two areas is the better the "longer you have to walk" around the blocking tiles until you get from on to the other side. Starting towards an free tile from the choke point, the algorithm counts the number of steps necessary to get back to the choke point while clinging to the blocking tiles at its right hand side. If the choke point hasn't been reached after CHOKE_FORT_MAX_WALK steps, it aborts and the latter value is taken as result.
Then it does the same with starting in the opposite direction. The choke point value is then the minimum of the two step counts.
Note: When the choke points sits on a land bridge that separates two areas of land, the step count obtained from the above algorithm will be an approximate measure for the size of the separated areas. Hence, also here it can be seen as an appropriate measure for the qualitiy of the choke point.
For further details, see selected comments from the script in the spoiler:
screens:
The icy spots mark the tiles the algorithm "walked". They are shown for debugging reasons only, of course, and will not be placed normally.
Installation:
To try it out, you'll have to replace one of the default FfH files with one provided.
download:
View attachment ChokeFortModule.zip
There are two files in the archive, ChokeFortModule.py and a modified CvEventManager.py, the latter for FfH 0.21
1. Go to Mods/<current FFH dir>/Assets/python/
2. Backup the file CvEventManager.py so that you can do undo the changes!
3. Extract the archive here. In the end, you should have the module file and the modified event manager file in this directory. Note that the modified file just has two additional lines: one imports the module, the other one calls the placeForts() function.
Note 1: For new FfH versions, the event manager file possibly has to be updated.
Note 2: I think sometimes forts still get placed at not so great spots, although not often. I'm currently out of time to search for the reason, but it's not that bad, anyway.
Choke value:
The idea is that a choke point between two areas is the better the "longer you have to walk" around the blocking tiles until you get from on to the other side. Starting towards an free tile from the choke point, the algorithm counts the number of steps necessary to get back to the choke point while clinging to the blocking tiles at its right hand side. If the choke point hasn't been reached after CHOKE_FORT_MAX_WALK steps, it aborts and the latter value is taken as result.
Then it does the same with starting in the opposite direction. The choke point value is then the minimum of the two step counts.
Note: When the choke points sits on a land bridge that separates two areas of land, the step count obtained from the above algorithm will be an approximate measure for the size of the separated areas. Hence, also here it can be seen as an appropriate measure for the qualitiy of the choke point.
For further details, see selected comments from the script in the spoiler:
Spoiler :
FILE: ChokeFortModule.py
VERSION: 1.00
AUTHOR: David Reichert (dreiche2)
PURPOSE: Find good choke points and place forts on them.
DESCRIPTION:
This module provides a function placeForts(), which will place forts on choke points, i.e. land bridges, mountain passes, etc. It could for example be called from within a map script or from within inititialization procedures of a mod. The script searches for the choke points and examines them for their 'choke value', see below. It will start with the best choke points, and the minimal valid choke value and the minimal distance between forts can be set via global parameters.
A plot is defined as choke point in 6 different situations:
(the central plot is the choke point, x is blocking, o is land, in u there must be at least one land per area)
1 2
uuu uxu
xox uou
uuu uxu
3 4 5 6
oxx xxo xuu uux
xou uox xou uox
xuu uux oxx xxo
Details of the algorithm:
When talking about "right" and "left", this is always meant relative to the direction the 'walker' is currently facing:
nortwest north northeast
west 0 east
southwest south southeast
left front left front
back left / front right
back back right right
Run I:
start:
-face east
-if not blocked:
*while front right is free, turn front right
-else:
*turn front left until front is free
(#front right is blocked now#)
-go front, save this initial direction
walk:
-while current position != starting point and steps <= max steps
*if last step was diagonal:
+face right
*else:
+face front right (#asymmetry comes from quadratic map grid#)
(#front right is blocked now#)
*while front is blocked, turn front left
*go front, steps=steps+1
Run II:
as Run I, but in beginning face in opposite direction from Run I initial direction
Proof that this algorithm works: Proven by example
VERSION: 1.00
AUTHOR: David Reichert (dreiche2)
PURPOSE: Find good choke points and place forts on them.
DESCRIPTION:
This module provides a function placeForts(), which will place forts on choke points, i.e. land bridges, mountain passes, etc. It could for example be called from within a map script or from within inititialization procedures of a mod. The script searches for the choke points and examines them for their 'choke value', see below. It will start with the best choke points, and the minimal valid choke value and the minimal distance between forts can be set via global parameters.
A plot is defined as choke point in 6 different situations:
(the central plot is the choke point, x is blocking, o is land, in u there must be at least one land per area)
1 2
uuu uxu
xox uou
uuu uxu
3 4 5 6
oxx xxo xuu uux
xou uox xou uox
xuu uux oxx xxo
Details of the algorithm:
When talking about "right" and "left", this is always meant relative to the direction the 'walker' is currently facing:
nortwest north northeast
west 0 east
southwest south southeast
left front left front
back left / front right
back back right right
Run I:
start:
-face east
-if not blocked:
*while front right is free, turn front right
-else:
*turn front left until front is free
(#front right is blocked now#)
-go front, save this initial direction
walk:
-while current position != starting point and steps <= max steps
*if last step was diagonal:
+face right
*else:
+face front right (#asymmetry comes from quadratic map grid#)
(#front right is blocked now#)
*while front is blocked, turn front left
*go front, steps=steps+1
Run II:
as Run I, but in beginning face in opposite direction from Run I initial direction
Proof that this algorithm works: Proven by example
screens:
The icy spots mark the tiles the algorithm "walked". They are shown for debugging reasons only, of course, and will not be placed normally.
Installation:
To try it out, you'll have to replace one of the default FfH files with one provided.
download:
View attachment ChokeFortModule.zip
There are two files in the archive, ChokeFortModule.py and a modified CvEventManager.py, the latter for FfH 0.21
1. Go to Mods/<current FFH dir>/Assets/python/
2. Backup the file CvEventManager.py so that you can do undo the changes!
3. Extract the archive here. In the end, you should have the module file and the modified event manager file in this directory. Note that the modified file just has two additional lines: one imports the module, the other one calls the placeForts() function.
Note 1: For new FfH versions, the event manager file possibly has to be updated.
Note 2: I think sometimes forts still get placed at not so great spots, although not often. I'm currently out of time to search for the reason, but it's not that bad, anyway.