Worklog for Pakz

Civilization 3 automation

Return to Worklogs

Working again on the project(Posted 2014-04-30)
I have retyped the civ project without the units code a number of times. I keep finding better ways of doing things when I retype it.

I now use the dim command to clear arrays. I bet this is faster then looping through the entire array and setting each value to 0. It seems to work alright.

I have been thinking of how to move units in groups. Not for the workers but for other units. I was looking at a lets play of civilization 1 and noticed that millitary units were close to each other and seemed to move together.
I have a few ideas on how to do the same thing. This wil probably take me a while to make though.

I stil have not found a better way of prioritizing which tiles need to be improved first. Terrain analysis or common sense code. It is pretty hard to get good behaviour. Workers in the last versions would just select tiles anywhere on the map and travel there. I was experimenting with staying close to home cities and was planning on counting the units in a area so that the units nearby would be able to work the tiles. Units can be traveling a while and other units in the area would travel elsewhere if the tile nearby was in the far away unit queue. Bad behaviour.

I can not find anything on the Internet on how to do the ai for this kind of thing. So I wil probably keep typing away until I get something that behaves right.

I am a bit shaken this day. The cat of my parents got driven over by a car. I saw it happen. The cat follows me when I walk the dog of my parents and today me and my stephfather were letting the dog out. The cat followed and crossed the street when a car was just passing by and got under the wheel. The cat is now at a vets clinic. Tomorow we will hear if she survived the night and if she needs a operation.
The cats name is moesie. She is 6 years old.
I feel terrible when I think about it.


improved the a*(Posted 2014-04-25)
I spend a while thinking of what to do with the project. I happened to think of a way to speed up the a* algorithm that I made.
I now check the new open nodes directly for presence in a array. Also the closed nodes are checked directly now.
This should make it a lot faster.

Here is the a* code.



I will retype this code for a number of times to get to know it more. I will be using this for the next worker automation experiment.


Found something new(Posted 2014-04-12)
I was sitting down and browsing the blitz basic website with the tablet and check the b+ manual. I saw a command that I never used before. It was Insert. I looked at the code and I thought I might be able to use it to build the list of coordinates that the pathfinding routine makes. These get build in reverse becourse it builds the path from the end to the beginning.

Now I simply do :

this Insert before first path

In the findpathback function and the path is now from start to end in stead of end to start.
In the last few retypes of the program I had a lot of extra lines for reversing the path and I should of fixed it before by reversing the list in the pathfinding functions.

I am getting better at it :)

I hope to get more work done today. Though I am not sure what I wil do. Maybe retype the map generator and pathfinding again or work on the last retype where I had that finished. There I could start on the unit automation parts.


Improving the code(Posted 2014-04-11)
I have been thinking how I could make the code better. I have a long select case part in the sourcecode and it would-be become huge if I added more features.
I have a State for each thing that the unit does. I tried using substates but this was not the way. I am now thinking that I should use more functions that get called from in the cases.

I have also been thinking of adding an nextstate field for the units. I was using a job field so I wil rename that to nextstate. I think I am using a finite State method for the automation part. Though I am not sure.

I am also planning of ordening the path type when the path is found and created. It is in reverse and I was reversing it in the select case part of the game. This should schorten it Some more.

I am retyping the entire thing to see if I can find a better way of coding it. It does not take so long since I have typed most of the code multiple times and type it in almost bug free every time. I have typed the a star part more then 25 times already in 3 years time. I started retyping my work to memorize it. I am sure this is useful for something.

I have already been figuring out how to Handle the automation with other ai players. The war units wil follow later on.

I stil have problems with the priority of the tile improvments. What needs to be done first and which unit should do it. This is difficult.

I hope to get Some work done in the next hours.


Starting over again(Posted 2014-04-09)
I have gotten to the point where I can get no further. The code was about a thousand lines long and all I was doing was adding the same type of things to it. I also saw that I could improve the code. I wil start over again and see if I can get farther next time.

here is a video of the last version.
http://youtu.be/rhvmi7yr8Uw

anyway here is the current code : no external media required. b3d or b+ code.



Another version done(Posted 2014-04-08)
The last version is done up to a point where the units move one after another and build road on a map where cities are preplaced. It took me longer then I had thought to get this far.

Here is a video of the latest attempt.
http://youtu.be/90XCUQvJ_Ms

I had to buy a screen recorder for after I installed windows 8.1 the camstudio software did not work as before. The screen was not in the set region and the video got messed up.
I bought a screen recorder from steam. It records correctly and uses the mpeg codec.

Windows 8.1 needed to instal a driver when I first ran the blitz plus sourcodecode. But after it was installed then blitzplus worked.

I hope to continue on this project. I am going to look at the sourcode and see what I can do next.


Another go at it.(Posted 2014-04-08)
It has been a while since I did Some programming. I think About programming more then I do the actualiteit programming.
I am staying up this night and plan to retype the automation thing from the start. I wil make Some improvments.
I did Some thinking in the automation order. Cities connected with roads get the highest priority. Then roads around cities. Then irrigation and mining and clearingbank forrest around cities. Then every tile wil be done and units wil travel with ship to Islands to do work there.

I wil Need to plan the transport part and boats Need to be automatically created.

I have also been learning and reading About types. The blitz manual is not that greatly written with al the features of types. I did find the tutorial in the b3d forum and I read through it every now and then. I am learning to use the undocumented features more in the code. I do think that I Need more experience with types so I wil be trying to experiment in the code. Handle and object is something that I Need to look at.

The astar is pretty slow. At least the one that I made. I Need to keep the map small until I get further with the program.


Long failed session(Posted 2014-04-03)
I spend hours on making another version. I changed the way the worker function worked. I also increased the resolution.
I could not get it to work. The workers first did not move and then I spend a long time trying to get 2 workers working. I was not sucessful.
The road was not being build completely. Parts were not being build. I think I spend a few hours trying to get it to work. I retyped the functions a number of times.

The last 2 days I programmed a lot and I hope that I stay in the spirit of programming.

Programming these workers is not easy. I never really programmed complex artificial intelligence so this is a learning experience.

I hope to fix the problems and get the current version working.

edit :

I was thinking of what I could do to fix the problems. I decided I wil use a couple of improvment types that I wil fill with al the imrpovments of the map. The worker wil then be able to select the closest improvement. I wil create one for the roads that connect cities and one with left over improvments.
Before that I was using a multidimensional array that I needed to read through. I think a type with only the x and y values and improvment kind wil be easier. I hope this wil solve the problems that I had.
I wil retype the entire program and make the changes.
I think I wil also make data graphics this time. I wil keep it so that I wil be able to run it without any external files.


Another improved version(Posted 2014-04-03)
I created a new version. This time first roads are build. Then forrest is cleared. and then irrigation is build.
Now the units stay close to their home cities.

There is stil a problem with islands. Units construct nothing sometimes. I think I need to do checking if a unit is on a island.

Below is the current code : it runs at full speed up to 200 turns and then begins over again. There are 3 workers per city and a random amount of cities. Every run a new map is generated.




Grinding(Posted 2014-04-02)
I am in the proces of memorizing the new map generator and the pathfinding code. I have retyped it a couple of times this night. The base program is between 200 and 300 lines each version.

I was also thinking the last days on how to do the transportation of units between land masses. I have the new map generator and this can create islands. I think I wil need to figure out how to move the units on the entire world. I could floodfil each location and check if it has been filled before. Then I could add a array with the island-land mass number on it. Then I could see what kind of pathfinding I need to do.

I was thinking of creating a path on the entire map including the water and then find the start and end land cel in the path. I would need to send a boat transport to the first water cel and then the ship and cargo could be send to the next location.

I wil spend more time thinking about this.

Also. I was thinking of letting cities create a new unit every 5 turns. Coastal cities should then create a fleet that can be used for transporting the worker units.

I stil need to think if I want to create settler units.

Here is the base program that I have at the moment.



Planning stage(Posted 2014-03-26)
I spend a couple of hours laying on my bed thinking of what and how to program new features for the civ game.
I think I wil add naval units that can transport the workers to different islands that have no improvements.

Currently I check the entire map if improvments can be added. If they are on a island then I wil need to move a worker or more workers to the shore and they need to get into a ship that wil take them to the other land masses.

I was also thinking of adding settler units that create cities. I have also been thinking of adding more then one computer player.

I am already at a 1000 lines of code so adding more things can get the code to become really big. My last civ clone thing was almost 15000 lines long.

I wil continue to think about what to do next.


I Optimized the code(Posted 2014-03-21)
I created buffer images that I draw every frame instead of drawing the map tile by tile. Now the example is a whole lot faster and I can barely follow what is happening.

I think the a* that I made is fast enough for rts style games. I have a random amount of units every run of 200 turns and there can be up to 100 workers on the map working. It runs pretty fast with the a* in action. I was not sure of this since it is unoptimized and checks each list every step. The example looks a little bit like a rts game so I think creating a rts for me will now be easier. I never done one before.

I had about 14 views on youtube on the current example. Not much but most of my videos have little views. My most viewed video that has been on youtube for a year or so and has had about 60 views.
I will need something more impressive and more populair to get more views I guess.

I wil see what I will do next with this example. I thought that improvements once city improvements are done could be selected closer to a city. But there are more then one cities so this wil not be that easy to program I think. I wil see.

Here is the program that I made so far. It is b3d of b+ code. It uses no external media and works right away.




Second attempt finished(Posted 2014-03-20)
Here is a link to a video of my second attempt that I just finished.

http://www.youtube.com/watch?v=6LNGoTIixJs

I got a random number of workers working on the map. They build roads between cities and then improvments around cities and then improve every tile. For the video I recorded 200 turns before a new map is started.

I am learning a lot with this automation. This can also be converted to be used by the computer players. They will be able to build their country this way.

I have not added mine improvments yet and there are no railroads or rivers either. The mountains and forrests are randomly placed on each map. I Need to modify the code to draw them in groups.

My laptop on which I recorded the video is 2 or 3 times raster then the desktop on which I programmed it. I was surprises at the speed it ran. Thing is though that the dog of my parents chased the cat. and jumped on the keyboard. Two keys broke of. The insert and home key. I plugged in a external keyboard and now use that. I am working more on the desktop lately but it is a i3 with non dedicated video card. The laptop is a gaming laptop.

I wil have to think About what to do next with this example. There is a lot of difference with civ. My code is simple. Maybe i wil start over and make it with different ai players. I wil see.


Different aproach(Posted 2014-03-18)
I remembered that in civ that you could be blocked when building roads between cities. Maybe it is better to plan a new path between cities each time a tile has been turned into a road tile.

I deleted al the code from the last attempt and now wil code a simple editor for getting better paths. I wil test the a* code and the worker code before making the code for improving the tiles around the cities.

It is not as easy as I first thought. I keep thinking of things that Need to be done. No wonder that civ clones are almost never made.

The code on the last try was at more than 700 lines. I have no idea how many lines I wil get when I am done with it.


First try(Posted 2014-03-17)
I created the first version of the program. It is still buggy and I need to find those bugs.

The map generator from me that is on the code archives is in it and creates a island. On it are currently 3 cities and 3 workers. I made it so that there are build phases. Currently the first fase is implemented. Building roads between cities. This sort of works but I am not happy on it yet.

I made a short video of it that is on my google plus account. See my account link.

edit :

here is the direct link to the video.

http://www.youtube.com/watch?v=eW-y8H85thk


Design stage first few days(Posted 2014-03-11)
I wanted to create a part of civilization 3 that I really used when playing the game. Workers that improve the terrain by themselfs. I am using the tablet to design and plan the entire thing.

I have been writing a lot of things down in onenote for the iPad.

I was planning on using scripts for the units and then create and run these. But now I got the idea to use 3 finished versions of the maps of the different stages of the improvments.

Map 1 with cities connected with roads.
Map 2 with improvments around cities.
Map 3 with every tile improved.

There Will be a random amount of workers and cities and the game Will run automatically from start to end. I wil use a random map generator using the random walk methode. There wil be roads, water, graslands, forrest, and fortresses. The workers Will travel to the nearest tile to improve. When the roads between cities are finished then improvments around cities are next then every tile on the map Will be improved.

I Need to go think About it more to be sure this is the easiest and best way to do it.

The game Will not be playable. It wil run from zero improvments to the entire map improved. It wil be 2D and have no drawn graphics. The map is the size of the screen.

I wil be using the a* algorithm to create connections between the cities and to send the workers around the map from job to job.