00001
00005 #include "object.h"
00006
00007
00008
00009
00010 unsigned short int weight(char cellId)
00011 {
00012 D5(printf("\nOBJECT.weight() - START - input %c (int %i)\n",
00013 cellId,(int)cellId ));
00014
00015 unsigned short int cellWeight = 1;
00016
00017 if( ! isaccessible( cellId ) )
00018 {
00019 if(cellId == FREE) cellWeight=1;
00020 else
00021 if(cellId == START) cellWeight=1;
00022 else
00023 if(cellId == DOOR) cellWeight=1;
00024 else
00025 if(cellId == CLOSE) cellWeight=0;
00026 }
00027
00028 D5(printf("\nOBJECT.weight() - 'returns' %u- END\n",cellWeight));
00029
00030 return cellWeight;
00031 }
00032
00033
00034 bool isaccessible(char cellId )
00035 {
00036 D5(printf("\nOBJECT.isaccessible() - START - input %c (int %i)\n",
00037 cellId,(int)cellId ));
00038
00039 bool accessAllow = false;
00040 if(cellId == FREE) accessAllow=true;
00041 else
00042 if(cellId == START) accessAllow=true;
00043 else
00044 if(cellId == DOOR) accessAllow=true;
00045 else
00046 if(cellId == CLOSE) accessAllow=false;
00047
00048 D5(printf("\nOBJECT.isaccessible() - 'returns' %s- END\n",
00049 (accessAllow?"TRUE":"FALSE") ));
00050
00051 return accessAllow;
00052 }
00053
00054
00055 char *color( char cellId )
00056 {
00057 D5(printf("\nOBJECT.color() - START - input %c (int %i)\n",
00058 cellId,(int)cellId ));
00059 const char BLACK[] = "#000000";
00060 const char WHITE[] = "#FFFFFF";
00061 const char RED[] = "#FF0000";
00062 const char GREEN[] = "#00FF00";
00063
00064 const unsigned short int NUM_CHAR = 8;
00065
00066 char *colorValue = (char *)malloc( sizeof(char) * NUM_CHAR );
00067
00068 strcpy(colorValue,BLACK);
00069
00070 if(cellId == FREE) strcpy(colorValue, WHITE);
00071 else
00072 if(cellId == START) strcpy(colorValue, RED);
00073 else
00074 if(cellId == DOOR) strcpy(colorValue, GREEN);
00075 else
00076 if(cellId == CLOSE) strcpy(colorValue, BLACK);
00077
00078 D5(printf("\nOBJECT.color() - 'returns' %s- END\n",colorValue));
00079
00080 return colorValue;
00081 }
00082
00083 char *colorVisited( unsigned short int cellId )
00084 {
00085 D5(printf("\nOBJECT.colorVisited() - START - input %c (int %i)\n",
00086 cellId,(int)cellId ));
00087
00088 const char LIGHT_BLUE[] = "#8BD0F8";
00089 const char BLUE[] = "#4438D8";
00090 const char OPAQUE_BLUE[] = "#4371A0";
00091
00092 const unsigned short int NUM_CHAR = 8;
00093
00094 char *colorValue = (char *)malloc( sizeof(char) * NUM_CHAR );
00095
00096 if( cellId == UNVISITED ) strcpy( colorValue, color(FREE) );
00097 else
00098 if( cellId == VISIT1 ) strcpy(colorValue, LIGHT_BLUE);
00099 else
00100 if( cellId == VISIT2 ) strcpy(colorValue, BLUE);
00101 else
00102 strcpy(colorValue, OPAQUE_BLUE);
00103
00104 D5(printf("\nOBJECT.colorVisited() - 'returns' %s- END\n",colorValue));
00105
00106 return colorValue;
00107 }
00108
00109 void visitCell( unsigned int row,
00110 unsigned int col
00111 )
00112 {
00113 D5(printf("\nOBJECT.visitCell() - START - input row=%u col=%u\n",row,col));
00114
00115
00116 if( (row>=schemaData.numRow) || (col>=schemaData.numCol) )
00117 {
00118 D1(printf("\nError: number of rows or columns out of data\n"));
00119 D5(printf("\nOBJECT.visitCell() - error & END\n"));
00120 return;
00121 }
00122
00123 if ( schemaData.visitedCellInfo[ row ][ col ] == UNVISITED )
00124 schemaData.visitedCellInfo[ row ][ col ] = VISIT1;
00125 else
00126 if ( schemaData.visitedCellInfo[ row ][ col ] == VISIT1 )
00127 schemaData.visitedCellInfo[ row ][ col ] = VISIT2;
00128 else
00129 if ( schemaData.visitedCellInfo[ row ][ col ] == VISIT2 )
00130 schemaData.visitedCellInfo[ row ][ col ] = VISIT1;
00131 else
00132
00133 schemaData.visitedCellInfo[ row ][ col ] = UNVISITED;
00134
00135 D5(printf("\nOBJECT.visitCell() - END\n"));
00136 }
00137
00138