help with generating a search puzzle

need a bit of help with a portion of this

Page 1 of 1

2 Replies - 1097 Views - Last Post: 13 April 2007 - 08:52 AM Rate Topic: -----

#1 Soraji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-April 07

help with generating a search puzzle

Posted 12 April 2007 - 02:31 PM

Edit: I've solved my problem. I can't delete my topic, so I'm just leaving my original message in.




Hello everyone! I am a first year student studying computer science and I am having a little trouble figuring out how to implement this part of a program.

I am writing a word search puzzle generator that takes in a list of words and dimensions (such as "cat", "animal", "fish", etc...) and then populates the board in random directions with the words on the list, such as up, down, left, right, diagonal up, diagonal left, etc.

One of the things I'm having trouble with is having words that are too long to fit in the random spot they are assigned to. For example, if I had a 5x5 and had the word 'bear' and wanted to fit it as such below and wanted the word to wrap around the board, how would I calculate the way to do so?

A x x x x
x R x x x
x x x x x
x x x B x
x x x x E

I can't think of a way to do it accurately without having a switch statement that repeats tons of code over and over. I've heard a good way to do it would be to mod the value to wrap it around, but I am not too sure how to do this correctly. >_<

Could anyone please give me some insight as to a useful algorithm I could use to do this properly? The rest of my program works just fine; just the wrapping is giving me headaches.

Mucho thanks. ^^

This post has been edited by Soraji: 12 April 2007 - 10:47 PM


Is This A Good Question/Topic? 0
  • +

Replies To: help with generating a search puzzle

#2 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: help with generating a search puzzle

Posted 13 April 2007 - 08:47 AM

It would be nice if you posted your solution. Think of this forum's archived posts as a database of knowledge. Not that anyone actually searches before they post...but anyway... :P
Was This Post Helpful? 0
  • +
  • -

#3 Soraji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-April 07

Re: help with generating a search puzzle

Posted 13 April 2007 - 08:52 AM

View Postalcdotcom, on 13 Apr, 2007 - 08:47 AM, said:

It would be nice if you posted your solution. Think of this forum's archived posts as a database of knowledge. Not that anyone actually searches before they post...but anyway... :P


Haha, yeah that would've been a good idea. To give a basic idea, my friend helped me figure out how to do certain directions on the board.

x = (x + 1)%sizeOfGrid; // For up to down changes
y = (y + 1)%sizeOfGrid;

Going backwards is x = (x-1)%sizeOfGrid with error checks to make sure the number isn't going out of bounds.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1