void Holder::AutoHold(){ switch(state){ case FIND_ZERO: FindZero(); break; case WAIT_FOR_BALL_TO_ENTER: WaitForBallToEnter(); break; case GO_TO_FORWARD_LIMIT: SetGateToForwardLimit(); break; case WAIT_FOR_PUSH_REQUEST: WaitForPushRequest(); break; case WAIT_FOR_BALL_TO_LEAVE: WaitForBallToLeave(); break; case GO_TO_REVERSE_LIMIT: SetGateToReverseLimit(); break; case BALL_PUSH_ERR: RemoveBall(); break; } }
// strip decorations from the string CTString CTString::Undecorated(void) const { // make a copy of the string to hold the result - we will rewrite it without the codes CTString strResult = *this; // start at the beginning of both strings const char *pchSrc = str_String; char *pchDst = strResult.str_String; // while the source is not finished while(pchSrc[0]!=0) { // if the source char is not escape char if (pchSrc[0]!='^') { // copy it over *pchDst++ = *pchSrc++; // go to next char continue; } // check the next char switch(pchSrc[1]) { // if one of the control codes, skip corresponding number of characters case 'c': pchSrc += 2+FindZero((UBYTE*)pchSrc+2,6); break; case 'a': pchSrc += 2+FindZero((UBYTE*)pchSrc+2,2); break; case 'f': pchSrc += 2+FindZero((UBYTE*)pchSrc+2,2); break; case 'b': case 'i': case 'r': case 'o': case 'C': case 'A': case 'F': case 'B': case 'I': pchSrc+=2; break; // if it is the escape char again, skip the first escape and copy the char case '^': pchSrc++; *pchDst++ = *pchSrc++; break; // if it is something else default: // just copy over the control char *pchDst++ = *pchSrc++; break; } } *pchDst++ = 0; ASSERT(strResult.Length()<=Length()); return strResult; }
//Beware - FindSolution works only for 4x4 game!!! void Fifteen::FindSolution() { CopyTGameArray(GameArray, GameStartArray); points = 0; Set* nothing; Set* closedSet = new Set(); Set* openSet = new Set(); Set* best = NULL; openSet->add(openSet, 0, GameArray, openSet, nothing); while (!openSet->empty()) { openSet->best(openSet, best); closedSet->add(closedSet, best->G, best->move, best->prev, best); openSet->remove(openSet, best->move); CopyTGameArray(GameArray, best->move); if(best->H < 1) { SetSolution(best); ShowSolution(); closedSet->DeleteAll(closedSet); openSet->DeleteAll(openSet); return; } int zeroX; int zeroY; FindZero(zeroX, zeroY, best->move); for (int i = 0; i < 4; i++) { int dx = (-1) * ((zeroX > 0) && (i == 0)) + ((zeroX < SIZE - 1) && (i == 1)); int dy = (-1) * ((zeroY > 0) && (i == 2)) + ((zeroY < SIZE - 1) && (i == 3)); TGameArray newArray; CopyTGameArray(newArray, best->move); newArray[zeroX][zeroY] = best->move[zeroX+dx][zeroY+dy]; newArray[zeroX+dx][zeroY+dy] = 0; if(!closedSet->isAlready(closedSet, newArray)) { openSet->add(openSet, best->G + 1, newArray, best, nothing); } } } }
bool ValidateGameParams(const GameParams& params) { bool fFound = false; for (int i = 0; i < ARRAYSIZE(gatGameSpeeds); i++) { if (params.tGameSpeed == gatGameSpeeds[i]) { fFound = true; break; } } if (!fFound) { return false; } if (!FindZero(params.szLvlFilename, sizeof(params.szLvlFilename))) { return false; } return true; }
void PrintImageInfo(const char* file_name) { printf("IM Info\n"); printf(" File Name:\n %s\n", file_name); int error; imFile* ifile = imFileOpen(file_name, &error); if (!ifile) { PrintError(error); return; } double file_size = FileSize(file_name); printf(" File Size: %.2f %s\n", file_size, GetSizeDesc(&file_size)); char format[10]; char compression[20]; int image_count; imFileGetInfo(ifile, format, compression, &image_count); char format_desc[50]; imFormatInfo(format, format_desc, NULL, NULL); printf(" Format: %s - %s\n", format, format_desc); printf(" Compression: %s\n", compression); printf(" Image Count: %d\n", image_count); for (int i = 0; i < image_count; i++) { int width, height, color_mode, data_type; error = imFileReadImageInfo(ifile, i, &width, &height, &color_mode, &data_type); if (error != IM_ERR_NONE) { PrintError(error); imFileClose(ifile); return; } printf(" Image #%d\n", i); printf(" Width: %d\n", width); printf(" Height: %d\n", height); printf(" Color Space: %s\n", imColorModeSpaceName(color_mode)); printf(" Has Alpha: %s\n", imColorModeHasAlpha(color_mode)? "Yes": "No"); printf(" Is Packed: %s\n", imColorModeIsPacked(color_mode)? "Yes": "No"); printf(" Is Top Down: %s\n", imColorModeIsTopDown(color_mode)? "Yes": "No"); printf(" Data Type: %s\n", imDataTypeName(data_type)); double image_size = imImageDataSize(width, height, color_mode, data_type); printf(" Data Size: %.2f %s\n", image_size, GetSizeDesc(&image_size)); char* attrib_list[50]; // should be dynamic allocated int attrib_list_count; imFileGetAttributeList(ifile, attrib_list, &attrib_list_count); for (int a = 0; a < attrib_list_count; a++) { if (a == 0) printf(" Attributes:\n"); int attrib_data_type, attrib_count; const void* attrib_data = imFileGetAttribute(ifile, attrib_list[a], &attrib_data_type, &attrib_count); if (attrib_count == 1) printf(" %s: %s\n", attrib_list[a], AttribData2Str(attrib_data, attrib_data_type)); else if (attrib_data_type == IM_BYTE && FindZero((imbyte*)attrib_data, attrib_count)) printf(" %s: %s\n", attrib_list[a], attrib_data); else printf(" %s: %s %s ...\n", attrib_list[a], AttribData2Str(attrib_data, attrib_data_type), AttribData2Str((imbyte*)attrib_data + imDataTypeSize(attrib_data_type), attrib_data_type)); } } imFileClose(ifile); }
//Function count H value for A-star algorithm int Fifteen::Set::CountH(TGameArray newArray, TGameArray oldArray) { int result = MAX / DIVISOR; int zX; int zY; FindZero(zX, zY, newArray); //Defining lot of bools for choosing GameArray state bool oneIsSet = onPlace(1, oldArray); bool twoIsSet = (onPlace(2, oldArray) && oneIsSet); bool fiveIsSet = (onPlace(5, oldArray) && twoIsSet); bool threeIsSet = (inSecondPart(3, 'x', oldArray) && fiveIsSet); bool fourIsSet = ( threeIsSet && ((inSecondPart(4, 'x', oldArray) && inSecondPart(0, 'x', oldArray)) || (onPlace(3, oldArray) && onPlace(4, oldArray))) ); bool topIsSet = (onPlace(3, oldArray) && onPlace(4, oldArray) && fourIsSet); bool nineIsSet = (inSecondPart(9, 'y', oldArray) && topIsSet); bool thirteenIsSet = ( nineIsSet && ((inSecondPart(13, 'y', oldArray) && inSecondPart(0, 'y', oldArray)) || (onPlace(9, oldArray) && onPlace(13, oldArray))) ); bool leftIsSet = (onPlace(9, oldArray) && onPlace(13, oldArray) && thirteenIsSet); bool more = (leftIsSet && onPlace(6, oldArray) && onPlace(7, oldArray) && onPlace(8, oldArray)); bool helper = false; //Count H for each tile for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { int x = abs((newArray[i][j] - 1)%SIZE - i); int y = abs((newArray[i][j] - 1)/SIZE - j); int kx = 0; int ky = 0; if (!oneIsSet) { int arr[0]; result = oneTile(1, 2, x, y, zX, zY, i, j, newArray, arr, 0); } else if (!twoIsSet) { int arr[1] = {1}; result = oneTile(2, 3, x, y, zX, zY, i, j, newArray, arr, 1); } else if (!fiveIsSet) { int arr[2] = {1, 2}; result = oneTile(5, 4, x, y, zX, zY, i, j, newArray, arr, 2); } else if (!threeIsSet) { int arr[3] = {1, 2, 5}; result = oneTile(3, 5, x, y, zX, zY, i, j, newArray, arr, 3); } else if (!fourIsSet) { int arr[3] = {1, 2, 5}; result = oneTile(4, 6, x, y, zX, zY, i, j, newArray, arr, 3); } else if (!topIsSet) { int resultVar = 50; int resultCur; if (!helper) { helper = true; result = 0; } int arr[3] = {1, 2, 5}; int arr2[3] = {3, 4, 0}; result = result + doubleTile(3, resultVar, x, y, zX, zY, i, j, newArray, arr, 3, arr2, 3, 'x'); result = result + doubleTile(4, resultVar, x, y, zX, zY, i, j, newArray, arr, 3, arr2, 3, 'x'); } else if (!nineIsSet) { int arr[5] = {1, 2, 5, 3, 4}; result = oneTile(9, 51, x, y, zX, zY, i, j, newArray, arr, 5); } else if (!thirteenIsSet) { int arr[5] = {1, 2, 5, 3, 4}; result = oneTile(13, 52, x, y, zX, zY, i, j, newArray, arr, 5); } else if (!leftIsSet) { int resultVar = 1500; int resultCur; if (!helper) { helper = true; result = 0; } int arr[5] = {1, 2, 5, 3, 4}; int arr2[3] = {9, 13, 0}; result = result + doubleTile(9, resultVar, x, y, zX, zY, i, j, newArray, arr, 5, arr2, 3, 'y'); result = result + doubleTile(13, resultVar, x, y, zX, zY, i, j, newArray, arr, 5, arr2, 3, 'y'); } else { int length = 7; int arr[7] = {1, 2, 5, 3, 4, 9, 13}; if(onPlaceArray(arr, length, newArray)) { if(!helper) { result = 0; helper = true; } if(newArray[i][j] != 0) { result = result + abs((newArray[i][j]-1)/SIZE-j) + abs((newArray[i][j]-1)%SIZE-i); } if (more) { if(!(onPlace(6, newArray) && onPlace(7, newArray) && onPlace(8, newArray))) { result = MAX; } } } else { result = MAX; } } } } return result; }
void Holder::Test(){ FindZero(); }