Thread: Shorter notation?

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Angry Shorter notation?

    Hi!

    Anyone knows if this piece of code can be shorter?

    Code:
    // from left to right, than go up
    	if ( ((ld->Char[Enemy->x+1][Enemy->y] == RIGHT_DOWN_LINE)      ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == RIGHT_UP_LINE)        ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == LEFT_DOWN_LINE)       ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == LEFT_UP_LINE)         ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == HORIZONTAL_LINE)      ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == HORIZONTAL_DOWN_LINE) ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == HORIZONTAL_UP_LINE)   ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == VERTICAL_LINE)        ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == VERTICAL_RIGHT_LINE)  ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == VERTICAL_LEFT_LINE)   ||
    		  (ld->Char[Enemy->x+1][Enemy->y] == ALL_DIRECTION_LINE)) &&
    		 ((ld->Char[Enemy->x][Enemy->y+1] != RIGHT_DOWN_LINE)      ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != RIGHT_UP_LINE)        ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != LEFT_DOWN_LINE)       ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != LEFT_UP_LINE)         ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != HORIZONTAL_LINE)      ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != HORIZONTAL_DOWN_LINE) ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != HORIZONTAL_UP_LINE)   ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != VERTICAL_LINE)        ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != VERTICAL_RIGHT_LINE)  ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != VERTICAL_LEFT_LINE)   ||
    		  (ld->Char[Enemy->x][Enemy->y+1] != ALL_DIRECTION_LINE)) &&
    		 ((ld->Char[Enemy->x][Enemy->y-1] != RIGHT_DOWN_LINE)      ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != RIGHT_UP_LINE)        ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != LEFT_DOWN_LINE)       ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != LEFT_UP_LINE)         ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != HORIZONTAL_LINE)      ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != HORIZONTAL_DOWN_LINE) ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != HORIZONTAL_UP_LINE)   ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != VERTICAL_LINE)        ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != VERTICAL_RIGHT_LINE)  ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != VERTICAL_LEFT_LINE)   ||
    		  (ld->Char[Enemy->x][Enemy->y-1] != ALL_DIRECTION_LINE)) && (Enemy->DIRECTION.GoRight) )
    	{
    		Enemy->DIRECTION.GoDown  = FALSE;
    		Enemy->DIRECTION.GoLeft  = FALSE;
    		Enemy->DIRECTION.GoRight = FALSE;
    		Enemy->DIRECTION.GoUp    = TRUE;
    	}
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Hmm. So I need to read the whole character map and mark the walls with the same value, right?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    >From that I take it that the Char array is read directly from a file, and it contains chars like RIGHT_DOWN_LINE
    Exactly.

    >Yeah, I'd do a one-time scan of the Char array to build the Map array, to make life much easier in the rest of the code.

    I just coded that.


    THANK YOU SALEM!!!
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM
  2. CamelCase VS Hungarian notation, which is better?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2007, 09:31 PM
  3. I need help with RPN notation!!!
    By schnoor22 in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 05:12 PM
  4. about big O notation
    By deepakkrmehta in forum C Programming
    Replies: 3
    Last Post: 08-27-2005, 02:31 PM
  5. Hungarian Notation POLL
    By maxhavoc in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 06-21-2004, 10:52 AM