How to program a chess: a forum based tutorial
Some background:
Throughout high school I spent a lot of time on this site, learning as much as I could from the tutorials and the community. I used quite a few of the skills I acquired from the site in my school projects. Three projects come to mind. The first large project I did was for a project development class I took in high school. In this class you choose a group of 4 people, choose a project, and develop it until the semester is over. At the end of the semester you are evaluated on your project. We choose to do a game...and although our 3d engine worked, it was unstable. This is where I learnt about issues of design ect, simply because I made a ton of mistakes. The second project that comes to mind is a demo I did for OAC English, which used a water simulation effect. The third project used flash to create a 3d map of the school you could walk through (learnt a lot about data structures).
Last year I got accepted into the University of Waterloo for both computer science and systems design engineering. I choose systems. Systems teaches about all the engineering disciplines in general and focus on design. We are the guys who decompose the project and send contracts off to specialists to finish...
Anyway, back to the story. I think my acceptance depended a lot on my extra curricular activities. Since this program is coop based, both my previous employers choose me because of my OGL/design skills. On my first work term I went to Sudbury to program visualization software for a company called Bedrock Research Corp. Since this company was a research company, I was essentially their development department. After 4 months of 12 hour days (7 days a week) spent designing and coding we produced VectorChrome. You can download VectorChrome from here:
http://members.rogers.com/ramrajb/RishiRamraj.html
Its the first project in the projects section. Post if you need instructions on how to use it...its kinda non intuitive. DeBeers is currently field testing the project because the visualizations it produces save them a ton of money. My latest work term was with Alias (www.alias.com). I was one of the programmers on ImageStudio (I'm sure I wouldn't have gotten the job without my ogl/design experience). I'm returning to Alias next year...err I suppose this year depending on where you live :) Its been an interesting first year of university. Another interesting development in my career, which I owe directly to the support of this community is my first published paper. Last term I took a look at the water simulation I wrote for my OAC project and expanded upon it. The result: a paper on general natural effect simulation which is going to be published in the next issue of game programming gems; game programming gems 5:
http://www.charlesriver.com/titles/gamegems5.html
My paper is called "Dynamic Grass Simulation and Other Natural Effects". Hope you check it out ;)
So I guess, this project is my way of saying thank you...speaking of which, I owe you guys a few more specs on sub-systems. Yesterday I kinda got side tracked, but I have a ton of time today.
Here's what I have lined up:
- our library environment
- the game clock
- the entire level below the resource manager (I've got a ton of stuff I can reuse)
- the input subsystem
I'll try to post them as I finish them...so sit back and get ready for what will hopefully be a very productive day...
Will post later,
- llvllatrix
Are we using opengl to code this game.. How to link the coding with the design object..? I really like the design... lol.... :)
OK, time for me to rip into your latest design-oriented post [wink]. Before I do though I think it's important to state that I have a great respect for what your doing here and any criticism levelled is intended to be constructive. I also want to point out that I claim no expertise in general software design. Any expertise I may possess is strictly limited to the realm of C++ specific design considerations. So take some of the following with a pinch of salt. Apologies for trimming out part of your post and ignoring the others - it was a long post! - I hope I haven't misrepresented any of your comments by quoting only one section of a larger comment.
I'm not quite sure what you're saying here. A good design should minimise coupling between independent modules so that it becomes trivial to move a module out to a dll, or a server on another machine, or integrate an external module directly into the application etc. if it makes sense to do so.
Beware programmer instinct - it is often wrong. Every* programmer believes they write good code, but in actuality not that many do. Every* programmer believes they are good at design, but in reality not that many are. If you're not well skilled at a task then odds are you're not skilled enough to realise you're not well skilled at that task. See Unskilled and Unaware of It (disclaimer: I'm not suggesting you or anyone else is unskilled and unaware of it, just that the phenomonon exists). Trust me, I speak from personal experience [wink]. (* and yes, "every" is a gross generalisation).
In my opinion naming is important because of what I hold source code to be. Source code is a communication medium, but unlike most media, source code is intended for two audiences - the compiler and the coder. Compilers care nothing for names, indeed in C++ they mangle whatever names you give them at the earliest opportunity. Names therefore are for one thing and one thing only: communicating with the coder. Use your names to tell other coders what you're doing - and to tell yourself when you return to the code two years later and need to try and figure out what on Earth you were doing.
Indeed. Consistency cannot be overemphasised. It should not just be the naming that is consistent but the entire set of coding conventions including indentation, placement of braces etc.
I'm not sure it's the size of the team that should affect the naming convention but more the type of project. Single coders and small teams often develop small projects with known limited scope and intent. Conventions can be relaxed in this case since it is known that there will be little or no maintenance or code reuse. Larger teams tend to work on projects with longer lifetimes or in situations where code reuse is desireable. Single coders and small teams working in environments where maintenance and code reuse are priorities would be best off using stricter conventions. So it is the type of project that determines the coding convention, it's just that different sized teams tend to work on different sized projects.
This is essentially Camel Case naming. This is the native Java convention (although in Java class names begin with a capital letter). There is nothing inherently "large team" about Camel Case.
Disclaimer: I'm not trying to dismiss your coding conventions (well, not all of them [wink]), just offer an alternative point of view.
Your naming convention is almost the standard C++ naming convention (e.g. C++ keywords like const_cast and library functions like set_symmetric_difference). As such there is nothing inherently "small team" about it (C++ standard library implementations are almost certainly "large team" efforts). I would advise against using acronyms prefixes to identify subsystems in C++ because C++ provides a superior alternative: namespaces.
Namespaces effectively partition subsystems but avoid litering the code with redundant information. For example if you are writing a function within a particular subsystem you will likely need to call several other functions from within the same subsystem. You know that the function you are reading is part of a particular subsystem, so the prefixes on function names add no useful information and instead merely serve to distract from the main purpose of the code. Prefixes are only required where subsystems interact and indeed that's exactly how namespaces work. Additionally if all functions require a prefix then there is a tendency to abbreviate them to the point of uselessness.
*cough* That would of course be int main(void). void main() is not a valid C++ entry point and, though allowed by some compilers, is not portable.
Your design is a little more detailed than I would start with. Just as a matter of interest, here's a (very quick) top level design I put together:
My intention here is to simply show the very minimum for an extensible computer chess game.
I would suggest that a top level design should have names attached to all modules. You may not know exactly how "The Great Unknown" will do what it does, but you must have some idea of what it should do.
Just one question/suggestion. Should the system manipulate contexts or should the contexts manipulate themselves?
What exactly does this have to do with confidence tricksters? (Sorry, bad joke [wink]).
Enigma
Quote: Original post by llvllatrix
How does code grow? As far as I can tell there are two main ways code can grow. It grows on a macro scale and a micro scale. Your design should consider the macro scale of code before you begin implementing, but it’s not unusual for your initial considerations to change throughout the development. Here is a list of different macro scales for different complexities of solutions:
1. single function program (hello world)
2. multi function/class program (school projects)
3. multi subsystem program compiled into a single app (this project)
4. single app that uses dlls or plugins
5. user/client apps (usually networked games)
6. multi apps on one cpu (Microsoft Office/Windows)
7. multi apps on multi cpus (think mmorpg servers)
8. Protocols (the internet)
The scale you select depends on the solution you are targeting, so you usually have an idea of what you will need before you start the project. You divide your project into more and more pieces to make it maintainable, and as a result feasible. At each division you can test and grow your code independent of the other levels.
I'm not quite sure what you're saying here. A good design should minimise coupling between independent modules so that it becomes trivial to move a module out to a dll, or a server on another machine, or integrate an external module directly into the application etc. if it makes sense to do so.
Quote: Programmer growth:
A bit of a side track: It seems as though a few of my friends have had similar experiences when it comes to our growth as programmers. In general, we all seem to be developing an instinct for what I think is good design. This instinct tends to be directly related to the level you can program/engineer. I encourage you to share your experiences on this thread as it seems the development of this instinct is different from programmer to programmer.
Beware programmer instinct - it is often wrong. Every* programmer believes they write good code, but in actuality not that many do. Every* programmer believes they are good at design, but in reality not that many are. If you're not well skilled at a task then odds are you're not skilled enough to realise you're not well skilled at that task. See Unskilled and Unaware of It (disclaimer: I'm not suggesting you or anyone else is unskilled and unaware of it, just that the phenomonon exists). Trust me, I speak from personal experience [wink]. (* and yes, "every" is a gross generalisation).
Quote: Naming:
Why is naming important and what is it used for? From my experience naming can be used for a variety of things. It's simply another programming tool and its importance depends on what you are using it for. In this section I'll discuss two naming conventions I've run into.
In my opinion naming is important because of what I hold source code to be. Source code is a communication medium, but unlike most media, source code is intended for two audiences - the compiler and the coder. Compilers care nothing for names, indeed in C++ they mangle whatever names you give them at the earliest opportunity. Names therefore are for one thing and one thing only: communicating with the coder. Use your names to tell other coders what you're doing - and to tell yourself when you return to the code two years later and need to try and figure out what on Earth you were doing.
Quote: When designing a naming convention the most important element is consistency.
Indeed. Consistency cannot be overemphasised. It should not just be the naming that is consistent but the entire set of coding conventions including indentation, placement of braces etc.
Quote: Naming conventions tend to be affected by the size of the team working on the project. The size of the team is important because as the team grows larger it becomes harder to enforce the convention. Successful conventions make it easy to be consistent because there are fewer special cases.
I'm not sure it's the size of the team that should affect the naming convention but more the type of project. Single coders and small teams often develop small projects with known limited scope and intent. Conventions can be relaxed in this case since it is known that there will be little or no maintenance or code reuse. Larger teams tend to work on projects with longer lifetimes or in situations where code reuse is desireable. Single coders and small teams working in environments where maintenance and code reuse are priorities would be best off using stricter conventions. So it is the type of project that determines the coding convention, it's just that different sized teams tend to work on different sized projects.
Quote: Large team:
Naming conventions have to be more flexible as the size of the team grows. Here are the rules of a large scale convention I've used:
- All names must begin with a lower case.
- Any successive words in the name must start with upper case. For example the name "Chess Programming Tutorial" would look like "chessProgrammingTutorial".
You can determine easily where a name starts. You can also easily read the name since the beginning of each successive word is obvious. The following rules are optional:
- All function names should begin with a verb
- All class names should begin with a noun
You'll notice that there is nothing that specifies which subsystem a function or class belongs to. This is because large companies usually invest a lot of time developing coding tools. A tool to help a programmer parse code would make subsystem naming obsolete.
This is essentially Camel Case naming. This is the native Java convention (although in Java class names begin with a capital letter). There is nothing inherently "large team" about Camel Case.
Quote: Small team:
When the team size is relatively small (1-10 programmers) then maintaining a strict naming convention is easier. Moreover, since we don’t have time to develop coding tools we can use the naming convention to solve some of our problems. Here are the rules of my personal naming/formatting system:
- All files need to be preformatted using a macro (will provide mine in the tools section of this post).
- Names for functions/classes are all lower case.
- Successive words in the name are separated by underscores. For example the name "Chess Programming Tutorial" would look like "chess_programming_tutorial".
- Your code needs to be organized into subsystems (also called slices or units).
- Each subsystem is assigned a three to four letter acronym that precedes any global names used in that subsystem. For example a window creation function might look like "wnd_create_window();".
- If there are further divisions in your subsystem repeat the same pattern of assigning an acronym. For example a gl creation function might look like "wnd_gl_create_gl_window()".
There are two reasons for the acronyms. The first is visual sorting; you can easily tell which area of the code the function/class came from. You also know where to look to find similar members of the same subsystem as well as documentation on how to use them (via comments). The second reason is that it lets you determine the scope of a function/class. You can easily tell which parts of your code are local (i.e. declared right then and there) or global because local names don’t have a prefix and tend to be shorter. Just remember that the programmer you are trying to stop from wrecking your code is yourself :)
Disclaimer: I'm not trying to dismiss your coding conventions (well, not all of them [wink]), just offer an alternative point of view.
Your naming convention is almost the standard C++ naming convention (e.g. C++ keywords like const_cast and library functions like set_symmetric_difference). As such there is nothing inherently "small team" about it (C++ standard library implementations are almost certainly "large team" efforts). I would advise against using acronyms prefixes to identify subsystems in C++ because C++ provides a superior alternative: namespaces.
Namespaces effectively partition subsystems but avoid litering the code with redundant information. For example if you are writing a function within a particular subsystem you will likely need to call several other functions from within the same subsystem. You know that the function you are reading is part of a particular subsystem, so the prefixes on function names add no useful information and instead merely serve to distract from the main purpose of the code. Prefixes are only required where subsystems interact and indeed that's exactly how namespaces work. Additionally if all functions require a prefix then there is a tendency to abbreviate them to the point of uselessness.
Quote: The second and third tools I mentioned earlier are essentially the same type of thing. The dos prompt basecode is essentially a console app with the following code:#include <iostream>using namespace std;void main(void){ //test code here}
*cough* That would of course be int main(void). void main() is not a valid C++ entry point and, though allowed by some compilers, is not portable.
Quote: Now that all of the preamble stuff is out of the way we can finally move on to the game...Here’s a pictorial representation of our project so far...at least my interpretation :) :
Your design is a little more detailed than I would start with. Just as a matter of interest, here's a (very quick) top level design I put together:
Chess | 1 | | 1..n Scene ^ | derives | Game | 1 +---------------+------------+ | 0..2 | 0..2 | 1 Human Artificial BoardOpponent Intelligence | 1 +----+----+ | 0..32 | 1 Piece Model | 1 | 1 +---------+
My intention here is to simply show the very minimum for an extensible computer chess game.
Quote: You'll notice that there is a big node called "The Great Unknown". The nice thing about design is that you don’t necessarily have to plan the entire project beforehand. We can design, implement, and test in small units.
I would suggest that a top level design should have names attached to all modules. You may not know exactly how "The Great Unknown" will do what it does, but you must have some idea of what it should do.
Quote: The context management subsystem:
Just one question/suggestion. Should the system manipulate contexts or should the contexts manipulate themselves?
Quote:bool game_is_game_in_focus(void){ return con_man_is_con_in_focus(con_index);}
What exactly does this have to do with confidence tricksters? (Sorry, bad joke [wink]).
Enigma
Sry this took so long...
http://www.eng.uwaterloo.ca/~rramraj/Gamedev/chess_tutorial/assets/assets.zip
Will post later,
- llvllatrix
Do we need to add the above design... The room design really looks nice... :)
I think the coding part will be difficult..
I believe everything will be done step by step..
Wow Great....
I think the coding part will be difficult..
I believe everything will be done step by step..
Wow Great....
Has anyone written any code yet????
btw Nice picture of a library, did you render it yourself or get it from some where???
btw Nice picture of a library, did you render it yourself or get it from some where???
you know llvllatrix, You could just write the entire design in a design document then post it for download in one post, instead of writing a whole bunch of posts.
I thought it would make it easier on you if u did it that way, but its up to you what you would rather do. Plus I thought it would make it easier on the team as a whole so they would have the design all in one file insted of going through the entire thread looking for the posts about the design.
Just a suggestion.
[wink]
I thought it would make it easier on you if u did it that way, but its up to you what you would rather do. Plus I thought it would make it easier on the team as a whole so they would have the design all in one file insted of going through the entire thread looking for the posts about the design.
Just a suggestion.
[wink]
Sry for the lack of posts...kinda been side tracked by the holidays; relatives want me over.
Actually I was thinking of implementing my own version of the game for everyone else. Do u guys think this would be helpful? So far, those of you reading should have already implemented the context manager.
Will get to that when we do the resource manager. I've already got the code written :)
This is kinda hard because the design actually evolves as we code. Its also interesting to compare Enigma's design with mine. We both took different approaches. I started from the bottom up and he started from the top down. What does my top level look like? Well it ultimately boils down to this:
How does the game start/end? At each stage in the processing loop every update function is aware of the state of the game. So the menu will draw itself if is in focus, ect. If you dont understand any of this dont worry. Right now I'm being very abstract. Things should clarify when we begin to build on the resource manager.
Actually, this raises a good point. The game I'm planning may or may not have features you want. My goal for this project is to try to show to those who follow this post how a scalable game engine is put together. As such, the game will probably look polished but the chess engine itself will not be a big focus; ie just another subsystem. If what your looking for is a good chess game that looks ok then I can change the focus of the project :)
Replying with the clock in a tic ;),
- llvllatrix
Quote:
Has anyone written any code yet????
Actually I was thinking of implementing my own version of the game for everyone else. Do u guys think this would be helpful? So far, those of you reading should have already implemented the context manager.
Quote:
but how to link the coding with the picture....
Will get to that when we do the resource manager. I've already got the code written :)
Quote:
You could just write the entire design in a design document then post it for download in one post, instead of writing a whole bunch of posts.
This is kinda hard because the design actually evolves as we code. Its also interesting to compare Enigma's design with mine. We both took different approaches. I started from the bottom up and he started from the top down. What does my top level look like? Well it ultimately boils down to this:
while(con_man_game_in_progress()){ // Update our utility subsystems util_update(); // Update our Main screen context main_con_update(); // Update our Game screen context game_con_update(); // Update our Menu screen context menu_con_update(); // Update our Console screen context cnsl_con_update();}
How does the game start/end? At each stage in the processing loop every update function is aware of the state of the game. So the menu will draw itself if is in focus, ect. If you dont understand any of this dont worry. Right now I'm being very abstract. Things should clarify when we begin to build on the resource manager.
Quote:
Do we need to add the above design...
Actually, this raises a good point. The game I'm planning may or may not have features you want. My goal for this project is to try to show to those who follow this post how a scalable game engine is put together. As such, the game will probably look polished but the chess engine itself will not be a big focus; ie just another subsystem. If what your looking for is a good chess game that looks ok then I can change the focus of the project :)
Replying with the clock in a tic ;),
- llvllatrix
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement