BT_Moderator :: BT_Moderator(){ BT_Player players[2]; for (int i = 0; i < 2; i++) { players[i].start_new_game(); // call each of the 'place' methods in turn record_treasure_placements(players[i], i); } int result1, result2 = 0; int turn = 0; int sel_row = 0; int sel_col = 0; bool game_over = false; if(check_invalid(players[0], players[1]) == 0){ game_over = true; cout << "Player 1 has to due Player 2 invalid placement."; result1 = 1; result2 = -1; }else if(check_invalid(players[0], players[1]) == 1){ game_over = true; cout << "Player 2 has to due Player 1 invalid placement."; result2 = 1; result1 = -1; }else if(check_invalid(players[0], players[1]) == 2){ game_over = true; cout << "The game is a draw as both teams has invalid placements."; result1 = 0; result2 = 0; } while ( !game_over ) { /* initialize random seed: */ srand ( time(NULL) ); /* generate secret number: */ sel_row = rand() % 9 + 0; sel_col = rand() % 9 + 0; if(players[turn].dig(sel_row, sel_col) == true){ game_over = true; if(turn == 0){ cout << "Player 1 has won the game brah!"; result1 = 1; result2 = -1; }else{ cout << "Player 2 has won the game brah!"; result2 = 1; result1 = -1; } } turn = !turn; } players[0].record_game_result(result1); players[1].record_game_result(result2); }
int main () { ucs4_t uc; /* Test ISO 646 unit input. */ { ucs4_t c; uint16_t buf[1]; for (c = 0; c < 0x80; c++) { buf[0] = c; uc = 0xBADFACE; ASSERT (check (buf, 1, &uc) == 0); ASSERT (uc == c); } } /* Test BMP unit input. */ { static const uint16_t input[] = { 0x20AC }; uc = 0xBADFACE; ASSERT (check (input, SIZEOF (input), &uc) == 0); ASSERT (uc == 0x20AC); } /* Test 2-units character input. */ { static const uint16_t input[] = { 0xD835, 0xDD1F }; uc = 0xBADFACE; ASSERT (check (input, SIZEOF (input), &uc) == 0); ASSERT (uc == 0x1D51F); } /* Test incomplete/invalid 1-unit input. */ { static const uint16_t input[] = { 0xD835 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint16_t input[] = { 0xDD1F }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } return 0; }
/** * Function converting cstring to unicode name * @param uname unicode name to be converted * @param cstring resulting cstring * @param nls Linux NLS object pointer for future enchancement * @param check flag indicating wether check invalid characters or not * @return the length of uname on success, negative error code on failure */ static int convert_cstring_to_uname(u16 *uname, const char *cstring, struct nls_table *nls, unsigned int check) { #ifndef CONFIG_RFS_NLS /* if not support nls */ int i = 0; while (cstring[i] != 0x00) { if (cstring[i] & 0x80) { /* cannot convert to unicode without codepage */ DEBUG(DL3, "NLS not support"); return -EINVAL; } uname[i] = (u16) (cstring[i] & 0x00ff); i++; } /* add the null */ uname[i] = 0x0000; return i; #else /* support nls codepage to convert character */ int clen = 0, uni_len = 0, len; int i = 0; len = strlen(cstring); for (i = 0; (cstring[i] != '\0') && (uni_len < MAX_NAME_LENGTH); uni_len++) { clen = char2uni(nls, (unsigned char *)&cstring[i], len - i, &uname[uni_len]); i += clen; if (uname[uni_len] == 0x00) break; if (check && check_invalid(uname[uni_len])) { DEBUG(DL3, "Invalid character"); return -EINVAL; } } /* the length of unicode name is never over the limitation */ { uname[uni_len] = 0x0000; /* return the length of name */ return uni_len; } #endif /* CONFIG_RFS_NLS */ }
int main () { ucs4_t uc; /* Test ISO 646 unit input. */ { ucs4_t c; uint8_t buf[1]; for (c = 0; c < 0x80; c++) { buf[0] = c; uc = 0xBADFACE; ASSERT (check (buf, 1, &uc) == 0); ASSERT (uc == c); } } /* Test 2-byte character input. */ { static const uint8_t input[] = { 0xC3, 0x97 }; uc = 0xBADFACE; ASSERT (check (input, SIZEOF (input), &uc) == 0); ASSERT (uc == 0x00D7); } /* Test 3-byte character input. */ { static const uint8_t input[] = { 0xE2, 0x82, 0xAC }; uc = 0xBADFACE; ASSERT (check (input, SIZEOF (input), &uc) == 0); ASSERT (uc == 0x20AC); } /* Test 4-byte character input. */ { static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD }; uc = 0xBADFACE; ASSERT (check (input, SIZEOF (input), &uc) == 0); ASSERT (uc == 0x10FFFD); } /* Test incomplete/invalid 1-byte input. */ { static const uint8_t input[] = { 0xC1 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xC3 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xE2 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF4 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xFE }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } /* Test incomplete/invalid 2-byte input. */ { static const uint8_t input[] = { 0xE0, 0x9F }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xE2, 0x82 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xE2, 0xD0 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF0, 0x8F }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF3, 0x8F }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF3, 0xD0 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } /* Test incomplete/invalid 3-byte input. */ { static const uint8_t input[] = { 0xF3, 0x8F, 0xBF }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF3, 0xE4, 0xBF }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } { static const uint8_t input[] = { 0xF3, 0x8F, 0xD0 }; ASSERT (check_invalid (input, SIZEOF (input)) == 0); } return 0; }
/*! \brief Initialize the iterator * * \param g Grid information * \param start starting point * \param stop stop point * \param bc boundary conditions * */ template<typename T> void Initialize(const grid_sm<dim,T> & g, const grid_key_dx<dim> & start , const grid_key_dx<dim> & stop, const size_t (& bc)[dim]) { // copy the boundary conditions for (size_t i = 0 ; i < dim ; i++) this->bc[i] = bc[i]; // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...} typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero; typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo; typedef typename generate_array<size_t,dim, Fill_three>::result NNthree; // Generate the sub-grid iterator grid_sm<dim,void> nn(NNthree::data); grid_key_dx_iterator_sub<dim> it(nn,NNzero::data,NNtwo::data); // Box base Box<dim,long int> base_b(start,stop); // intersect with all the boxes while (it.isNext()) { auto key = it.get(); if (check_invalid(key,bc) == true) { ++it; continue; } bool intersect; // intersection box Box<dim,long int> b_int; Box<dim,long int> b_out; for (size_t i = 0 ; i < dim ; i++) { b_int.setLow(i,(key.get(i)-1)*g.getSize()[i]); b_int.setHigh(i,key.get(i)*g.getSize()[i]-1); } intersect = base_b.Intersect(b_int,b_out); // Bring to 0 and size[i] for (size_t i = 0 ; i < dim ; i++) { if (bc[i] == PERIODIC) { b_out.setLow(i,openfpm::math::positive_modulo(b_out.getLow(i),g.size(i))); b_out.setHigh(i,openfpm::math::positive_modulo(b_out.getHigh(i),g.size(i))); } } // if intersect add in the box list if (intersect == true) boxes.push_back(b_out); ++it; } // initialize the first iterator if (boxes.size() > 0) grid_key_dx_iterator_sub<dim,warn>::reinitialize(grid_key_dx_iterator_sub<dim,warn>(g,boxes[0].getKP1(),boxes[0].getKP2())); }
/** * Function converting cstring to dosname * @param dosname resulting dosname * @param cstring cstring to be converted * @param status flag indicating the capital combination and whether resulting dosname fits the 8.3 dosname or not * @param check flag indicating whether check invalid characters or not * @return zero on sucess, negative error code on failure. */ int convert_cstring_to_dosname(u8 *dosname, const char* cstring, unsigned int *status, unsigned int check) { const char *end_of_name, *last_period; int i, len, lossy = FALSE; char mixed = 0; /* strip all leading spaces and periods */ while ((*cstring == SPACE) || (*cstring == PERIOD)) { lossy = TRUE; cstring++; } len = strlen(cstring); if (!len) return -EINVAL; end_of_name = cstring + len - 1; /* check the trailing period & space */ if (!check && (*end_of_name == PERIOD || *end_of_name == SPACE)) return -EINVAL; /* search for the last embedded period */ last_period = strrchr(cstring, PERIOD); if (last_period == NULL) last_period = end_of_name + 1; memset(dosname, SPACE, DOS_NAME_LENGTH); i = 0; for (;(i < DOS_NAME_LENGTH) && (cstring <= end_of_name); cstring++) { if (check && check_invalid((u16)(*cstring & 0x00ff))) { DEBUG(DL3, "Invalid character"); return -EINVAL; } if (*cstring == SPACE) { lossy = TRUE; continue; } if (*cstring == PERIOD) { if (cstring < last_period) lossy = TRUE; else i = SHORT_NAME_LENGTH; continue; } #if !defined(CONFIG_RFS_NLS) && defined(CONFIG_RFS_VFAT) /* not support non-ASCII */ if (check && (*cstring & 0x80)) { DEBUG(DL3, "NLS not support"); return -EINVAL; } #endif /* fill dosname */ if (check_invalid_short(*cstring)) { dosname[i++] = UNDERSCORE; lossy = TRUE; } else if (isascii(*cstring) && islower(*cstring)) { if (i < SHORT_NAME_LENGTH) mixed |= PRIMARY_LOWER; else mixed |= EXTENSION_LOWER; dosname[i++] = toupper(*cstring); } else if (isascii(*cstring) && isupper(*cstring)) { if (i < SHORT_NAME_LENGTH) mixed |= PRIMARY_UPPER; else mixed |= EXTENSION_UPPER; dosname[i++] = *cstring; } else { dosname[i++] = *cstring; } if ((i == SHORT_NAME_LENGTH) && ((cstring + 1) < last_period)) { lossy = TRUE; #ifdef CONFIG_RFS_VFAT if (check) { while(++cstring < last_period) { if (check_invalid((u16)(*cstring & 0x0ff))) return -EINVAL; } } #endif cstring = last_period; } } /* end of loop */ if (cstring <= end_of_name) { lossy = TRUE; #ifdef CONFIG_RFS_VFAT if (check) { while(cstring <= end_of_name) { if (check_invalid((u16)(*cstring++ & 0x0ff))) return -EINVAL; } } #endif } /* post check */ if (dosname[0] == KANJI_LEAD) dosname[0] = REPLACE_KANJI; if (status != NULL) { *status = 0; if ((primary_masked(mixed) == (PRIMARY_UPPER | PRIMARY_LOWER)) || (extension_masked(mixed) == (EXTENSION_UPPER | EXTENSION_LOWER))) { put_mix(*status, UPPER_N_LOWER); } else { if (primary_masked(mixed) == PRIMARY_LOWER) put_mix(*status, PRIMARY_LOWER); if (extension_masked(mixed) == EXTENSION_LOWER) put_mix(*status, EXTENSION_LOWER); } put_lossy(*status, lossy); } return 0; }