Advertisement

Word Search

Started by February 09, 2003 07:34 PM
19 comments, last by lanchfn21 21 years, 9 months ago
This is how I would test a word:


    bool check_word(const std::vector<std::vector<char> > &grid, int width, int height, int x, int y, int direction, const char *word) {  // direction is 0-7, 0 being right, and 0+ turning in a clockwise direction.  static const int dirx[8] = {1, 1, 0, -1, -1, -1,  0,  1};  static const int diry[8] = {0, 1, 1,  1,  0, -1, -1, -1};  int len = std::strlen(word);    if(x < 0 || y < 0 || x >= width || y >= height || // check if starting point is outside of grid     x+dirx[direction]*len < 0 || y+diry[direction]*len < 0 || // check if ending point is outside of grid     x+dirx[direction]*len >= width || y+diry[direction]*len >= height)   return false;     // Check if the letters in the grid match the word.  for(int p = 0; p < len; ++p)   if(grid[x+dirx[direction]*p][y+diry[direction]*p] != word[p])    return false;  // Everything is okay.  return true; }    


[edited by - smart_idiot on February 10, 2003 4:15:31 AM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement