• Create Account

### #ActualServant of the Lord

Posted 02 September 2012 - 04:53 PM

Several tips and one criticism:
1) Don't be afraid to use whitespace. It makes the code easier to read. Easier to read is better than not easy to read.
2) Don't cram multiple things onto one line 'just because'.

For example, this:
int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;

Should be:
int topLeft = 0, topCenter = 0, topRight = 0;
int middleLeft = 0, middleCenter = 0, middleRight = 0;
int bottomLeft = 0, bottomCenter = 0, bottomRight = 0;
int turn = 0;
int restart = 1; //What is restart? It either isn't named very descriptively, or else should be a boolean.
int playerMove = 0, compMove = 0; //Maybe these should be bools also?
int playerMoveAccept = 0, compMoveAccept = 0;
int win = 0; //Bool?
int fourCorners=0;
int care = 0; //Needs more discriptive name, and also should be a bool.
int chance = 0, difficulty = 0, placement = 0;

Use constants or enums wherever applicable. Avoid as many magic numbers as you can.

Declare any variables as close to the first use as reasonable. Definitely declare them in the proper scope. Don't make them all globals. Some globals are okay though.

Learn if else() and else and use them where appropriate.

You're doing good, so keep at it! All of the above is just tips to improve and get better. There's still a ways to go, but you're just starting out so that's to be expected.

Now for the one real criticism:

What in the world is this?
if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0)
{
//...
}

'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it!

(*tongue-in-cheek anger*)

### #1Servant of the Lord

Posted 02 September 2012 - 04:52 PM

Several tips and one criticism:
1) Don't be afraid to use whitespace. It makes the code easier to read. Easier to read is better than not easy to read.
2) Don't cram multiple things onto one line 'just because'.

For example, this:
int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;

Should be:
int topLeft = 0, topCenter = 0, topRight = 0;
int middleLeft = 0, middleCenter = 0, middleRight = 0;
int bottomLeft = 0, bottomCenter = 0, bottomRight = 0;
int turn = 0;
int restart = 1; //What is restart? It either isn't named very descriptively, or else should be a boolean.
int playerMove = 0, compMove = 0; //Maybe these should be bools also?
int playerMoveAccept = 0, compMoveAccept = 0;
int win = 0; //Bool?
int fourCorners=0;
int care = 0; //Needs more discriptive name, and also should be a bool.
int chance = 0, difficulty = 0, placement = 0;

Use constants or enums wherever applicable. Avoid as many magic numbers as you can.

Declare any variables as close to the first use as reasonable. Definitely declare them in the proper scope. Don't make them all globals. Some globals are okay though.

Learn if else() and else and use them where appropriate.

You're doing good, so keep at it! All of the above is just tips to improve and get better. There's still a ways to go, but you're just starting out so that's to be expected.

Now for the one real criticism:

What in the world is this?
if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0)
{
//...
}

'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it!

PARTNERS