Topic: LUA AI development preview :)

einstein13
Avatar
Joined: 2013-07-29, 00:01 UTC+2.0
Posts: 1116
Ranking
One Elder of Players
Location: Poland
Posted at: 2014-02-13, 11:48 UTC+1.0

Hi!

I know that the AI code will be very complex and has lots of lines (more than 1000), so my idea is to stick to the conventions with programming. My roommate (who is a programmer) told me about some of them:

The same is for functions: one function is doing only one thing. The best is to build only very simple functions, probably lots of them, because when you will need to change something it's much more easier to change simple function than change complicated one. I've built one project with ~40 functions and now It is very easy to add new one. Only one problem are the names:

  • Don't use short names or abbreviations.

The computer can handle long names as good as short ones. If you use short names, it would be very hard to understand what is inside the code after some time (few months).

  • Add some comments.

Comments of code are necessary. But not everything has to have them. From my small experience, the best is to add a comments in the beginning of each function: what is the function doing? what is it returning? Is the algorithm somewhere described (www site/ PDF/ whatever)? Then using existing function will be easier (you don't have to think about the math inside).

  • Multiple files

You already have them face-smile.png That's good! Every file has own task.

You can disagree with me- that's normal face-smile.png But please think about it and probably you can try to use some info. You did very well already, but probably in the future the code will be more complex and harder to write.

I know that my ideas of math model with woodcutters and foresters will need lots of math stuff, the best is to create completely new functions used by them and (probably) by other tasks (farms? vineyards?).

Have fun!

einstein13

Edited: 2014-02-13, 11:50 UTC+1.0

einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24 UTC+1.0
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-02-13, 22:21 UTC+1.0

Well these are more-less my thoughts face-smile.png

Just take into account it is too soon for comments and so on, because I very frequently reworks what I have now... So everything must settle a bit first...


Top Quote