Click here to Skip to main content
15,890,845 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Shortes pass find + walls bypassing Pin
Luc Pattyn15-May-11 2:43
sitebuilderLuc Pattyn15-May-11 2:43 
AnswerRe: Shortes pass find + walls bypassing Pin
dasblinkenlight15-May-11 23:11
dasblinkenlight15-May-11 23:11 
NewsAckerman non-recursive function Pin
Raminnamiranian4-May-11 22:31
Raminnamiranian4-May-11 22:31 
GeneralRe: Ackerman non-recursive function Pin
Ravi Sant5-May-11 0:31
Ravi Sant5-May-11 0:31 
AnswerRe: Ackerman non-recursive function Pin
Luc Pattyn5-May-11 1:48
sitebuilderLuc Pattyn5-May-11 1:48 
GeneralRe: Ackerman non-recursive function Pin
Richard MacCutchan5-May-11 4:18
mveRichard MacCutchan5-May-11 4:18 
QuestionSearch Algorithm Pin
Cyclone_S16-Apr-11 8:22
Cyclone_S16-Apr-11 8:22 
QuestionRe: Search Algorithm Pin
bob1697216-Apr-11 9:28
bob1697216-Apr-11 9:28 
First off, there appears to be some redundant checks in the "else if" lines. Unless I'm missing something, the "if" portion of the "else if" will always be true since the "else" implies the converse of the "<=" operator from the original "if" block.

Now this won't effect the outcome of the snippet you posted but removing it and formatting it with some slightly different indentation and a few constant symbols might be easier to read in order to understand your implementation. If one took the liberty to do this, without impacting the logic, it might look like this...
const int LEFT = 1;
const int RIGHT	= -1;
const int UP = 2;
const int DOWN = -2;


void comp_direction()
{
	if (tick_comp == 0 && avoiding == false) {
		if (segments_comp[head_comp]->panel->Left <= Food->Left) {


			if (segments_comp[head_comp]->panel->Top >= Food->Top) {
				direction_comp = UP;
			} else {
				direction_comp = RIGHT;
			}


		} else {

			if (segments_comp[head_comp]->panel->Top >= Food->Top) {
				direction_comp = UP;
			} else {
				direction_comp = LEFT;
			}
		}

		/*
		This section will always run, effectively overwriting
		the direction_comp value from above. Is this by design?
		*/
		if (segments_comp[head_comp]->panel->Top <= Food->Top) {


			if (segments_comp[head_comp]->panel->Left <= Food->Left) {
				direction_comp = RIGHT;
			} else { 
				direction_comp = DOWN;
			}
			
		} else {

			if (segments_comp[head_comp]->panel->Left >= Food->Left) {
				direction_comp = LEFT;
			} else { 
				direction_comp = UP;
			}
		}
	}
}

You did not really provide much detail about your algorithm so I'm afraid I can't help much but I must ask, did you intend for the code to keep overwriting "direction_comp" even if it had been assigned earlier in the method?
AnswerRe: Search Algorithm Pin
Cyclone_S16-Apr-11 13:10
Cyclone_S16-Apr-11 13:10 
GeneralRe: Search Algorithm Pin
bob1697216-Apr-11 17:52
bob1697216-Apr-11 17:52 
GeneralRe: Search Algorithm Pin
Cyclone_S20-Apr-11 9:58
Cyclone_S20-Apr-11 9:58 
GeneralRe: Search Algorithm Pin
bob1697220-Apr-11 18:06
bob1697220-Apr-11 18:06 
GeneralRe: Search Algorithm Pin
Cyclone_S21-Apr-11 14:45
Cyclone_S21-Apr-11 14:45 
GeneralRe: Search Algorithm Pin
Cyclone_S22-Apr-11 9:57
Cyclone_S22-Apr-11 9:57 
GeneralRe: Search Algorithm Pin
bob1697224-Apr-11 4:59
bob1697224-Apr-11 4:59 
GeneralRe: Search Algorithm Pin
Cyclone_S27-Apr-11 13:43
Cyclone_S27-Apr-11 13:43 
AnswerRe: Search Algorithm Pin
Luc Pattyn20-Apr-11 12:39
sitebuilderLuc Pattyn20-Apr-11 12:39 
AnswerRe: Search Algorithm Pin
AspDotNetDev20-Apr-11 13:12
protectorAspDotNetDev20-Apr-11 13:12 
GeneralRe: Search Algorithm Pin
Cyclone_S20-Apr-11 13:40
Cyclone_S20-Apr-11 13:40 
AnswerRe: Search Algorithm Pin
Stefan_Lang26-Apr-11 4:32
Stefan_Lang26-Apr-11 4:32 
GeneralRe: Search Algorithm Pin
Cyclone_S27-Apr-11 13:50
Cyclone_S27-Apr-11 13:50 
Questionconverting MFC program into web based Pin
shiks11-Apr-11 17:06
shiks11-Apr-11 17:06 
AnswerRe: converting MFC program into web based Pin
Albert Holguin11-Apr-11 18:13
professionalAlbert Holguin11-Apr-11 18:13 
GeneralRe: converting MFC program into web based Pin
shiks12-Apr-11 5:15
shiks12-Apr-11 5:15 
GeneralRe: converting MFC program into web based Pin
Albert Holguin12-Apr-11 5:19
professionalAlbert Holguin12-Apr-11 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.