Author: Uri Blass
Date: 02:47:22 06/04/01
I will explain what I mean by heavily commented.
I mean that people who look at one file do not need to look at other files to
understand things like the definition of variables.
I will give an example for a possible part of heavily commented chess program.
In this case the idea of the program is to do it possible to change the
dimension of the board
You can see that most of the code is comments(every line that begins with // is
a comment)
#include "defs.h"
#include "data.h"
#include "protos.h"
#include "stdio.h"
void init(int numfils,int numranks)
{
int rank,fil;
//rank,fil are the rank and the file
//of a square in the board
//index is an array that gives a square number
//for every rank and file
//fil0 and rank0 are arrays in order to know by the
//number of the quare it's rank and file
//data.c includes the following defintions that are used
//int numranks;
//int numfils;
//int fil0[100];
//int rank0[100];
//int index[10][10];
//numranks and numfils are defined to be 8 in main.c
//if we want to change the dimension of the board we
//need to change numranks=8; and numfils=8 in main.c
for (fil=0;fil<numfils;fil++)
for (rank=0;rank<numranks;rank++)
{
index[fil][rank]=rank*numfils+fil;
fil0[index[fil][rank]]=fil;
rank0[index[fil][rank]]=rank;
}
//ranks 0,1,numranks-1,numranks-2(the first 2 ranks
// and the last 2 ranks) are empty
//we first put the constant EMPTY in the arrays
//color and piece
//of the board
//the constant EMPTY is defined in defs.h
//#define EMPTY 6 is included in this file
//The arrays color and piece are defined in data.c
//it includes int color[100];int piece[100];
for (fil=0;fil<numfils;fil++)
for (rank=1;rank<numranks-1;rank++)
if ((rank>1)&&(rank<numranks-2))
{
color[index[fil][rank]]=EMPTY;
piece[index[fil][rank]]=EMPTY;
}
Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.