And ANOTHER crossword problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

And ANOTHER crossword problem

some dudesome dude Posts: 4Member
Guys please please PLEASE do help me with this project as it counts towards 20% of my exam score and I can't afford to flunk it.

I need to write a crossword program in Pascal, the crossword should be read from an external file THAT HAS NOT BEEN FORMATTED as the program should be designed so that it throws in the correct letters to the correct spaces. The program then asks a user to choose the word he's like to solve and displays the corresponding hint.

To start off, I don't know how you can even draw the grids of the crossword puzzle, let alone how to make the correct hints (which are all kept in an external file) show up upon entering the choice. Then I can't seem to find crossword puzzles small enough to fit my teacher's requirement---no more than 12x12.

*Sigh* The project is due on 20 December and I can't seem to think of anything! Please enlighten me!

All and any help is highly appreciated!

Comments

  • zibadianzibadian Posts: 6,349Member
    : Guys please please PLEASE do help me with this project as it counts towards 20% of my exam score and I can't afford to flunk it.
    :
    : I need to write a crossword program in Pascal, the crossword should be read from an external file THAT HAS NOT BEEN FORMATTED as the program should be designed so that it throws in the correct letters to the correct spaces. The program then asks a user to choose the word he's like to solve and displays the corresponding hint.
    :
    : To start off, I don't know how you can even draw the grids of the crossword puzzle, let alone how to make the correct hints (which are all kept in an external file) show up upon entering the choice. Then I can't seem to find crossword puzzles small enough to fit my teacher's requirement---no more than 12x12.
    :
    : *Sigh* The project is due on 20 December and I can't seem to think of anything! Please enlighten me!
    :
    : All and any help is highly appreciated!
    :
    :
    The best way to create the screen output is to use GotoXY() and write() inside a for-do loop.
    The hints should be stored inside an array. This makes the user choice quite simple, because he can directly enter the number of the array-element (=hint).
    As for finding the puzzle itself, why not create one yourself.
    This board contains a lot of crossword puzzle code. Try reading several of the previous threads, some of these questions have been answered before.
  • some dudesome dude Posts: 4Member
    : The best way to create the screen output is to use GotoXY() and write() inside a for-do loop.
    : The hints should be stored inside an array. This makes the user choice quite simple, because he can directly enter the number of the array-element (=hint).
    : As for finding the puzzle itself, why not create one yourself.
    : This board contains a lot of crossword puzzle code. Try reading several of the previous threads, some of these questions have been answered before.
    :

    Yeah well I know this may sound crazy, but we are forbidden from using the GotoXY command...

    And I JUST CAN'T seem to figure out this problem.

    Let's use the crossword "Fruits" at http://iteslj.org/cw/ as an example.
    Say I have put the following things in a text file named puzzle1.txt
    blah
    blah
    blah
    hint1
    hint2
    hint3
    and so on.

    Now, without using the GotoXY command, is there anyway of placing the words in the right place in the puzzle so it looks something like this (just an example)

    XX1XXX
    XX XXX
    XX3
    XXXXXX
    XXXXXX

    Note that the actual words are replaced by blank spaces and that the number indicates the start of a word (that's why I have to edit some of the puzzles to rid of the shared numbers, I don't know how to do that and unless you enlighten me I think it would be a better idea to give up)

    Now is there a universal algorithm that automatically 'tosses' the correct blank spaces into the puzzle to give it the shape, or do I have to make a separate procedure for each puzzle?

    And there's another problem. Let's say I have 12 puzzles for the user to choose. Now is it possible to assign a file without using if-then-else statements or case statements? For example if the user enters 2 the program will automatically assign the file variable to puzzle2.txt. (There is only one file variable)

    Thank you very very much for helping me out here.



  • zibadianzibadian Posts: 6,349Member
    : : The best way to create the screen output is to use GotoXY() and write() inside a for-do loop.
    : : The hints should be stored inside an array. This makes the user choice quite simple, because he can directly enter the number of the array-element (=hint).
    : : As for finding the puzzle itself, why not create one yourself.
    : : This board contains a lot of crossword puzzle code. Try reading several of the previous threads, some of these questions have been answered before.
    : :
    :
    : Yeah well I know this may sound crazy, but we are forbidden from using the GotoXY command...
    :
    : And I JUST CAN'T seem to figure out this problem.
    :
    : Let's use the crossword "Fruits" at http://iteslj.org/cw/ as an example.
    : Say I have put the following things in a text file named puzzle1.txt
    : blah
    : blah
    : blah
    : hint1
    : hint2
    : hint3
    : and so on.
    :
    : Now, without using the GotoXY command, is there anyway of placing the words in the right place in the puzzle so it looks something like this (just an example)
    :
    : XX1XXX
    : XX XXX
    : XX3
    : XXXXXX
    : XXXXXX
    :
    : Note that the actual words are replaced by blank spaces and that the number indicates the start of a word (that's why I have to edit some of the puzzles to rid of the shared numbers, I don't know how to do that and unless you enlighten me I think it would be a better idea to give up)
    :
    : Now is there a universal algorithm that automatically 'tosses' the correct blank spaces into the puzzle to give it the shape, or do I have to make a separate procedure for each puzzle?
    :
    : And there's another problem. Let's say I have 12 puzzles for the user to choose. Now is it possible to assign a file without using if-then-else statements or case statements? For example if the user enters 2 the program will automatically assign the file variable to puzzle2.txt. (There is only one file variable)
    :
    : Thank you very very much for helping me out here.
    :
    :
    :
    :
    You can make an array of strings, which represents the playing field in the memory. Then you can use a for-do loop and writeln() to draw that. If you add a word to the field, just add it to the array, and then draw it again. Using this method you can draw the field based on the 1st-letter location, the direction of the word, and the length of the word. This can be a generalized to a single procedure, which has the word, location and direction as parameters and updates the global field-array.

    As for the filename, that's quite easy to code:
    1) convert the number to a string (Str() procedure)
    2) add the text around the number to form the filename (i.e. 'puzzle'+numberstr+'.txt')

  • some dudesome dude Posts: 4Member
    Ok now here's an even tougher problem...

    * * 1 O F 2 E 3
    3 E A * * I * G
    * * K * * S * G
    * 4 E 6 C H * *
    * O * P * * * *
    7 R A P E * * *
    * K * L * * * *
    * * 8 E M O N *
    Many people drink it in the morning with milk or cream
    British people drink it at 5 o'clock
    Juicy, round, reddish, sweet fruit with a furry skin
    You make wine from this fruit
    You make lemonade from this fruit
    You serve it at birthday parties
    You can find them in the sea
    Chickens lay these
    This is what meat from a pig is called
    An _____ a day keeps the doctor away

    Now that is what my text file which contains the crossword looks like.

    The first 5 hints are the 5 horizontal words and the latter 5 the vertical words respectively.

    3 questions:
    1. I need to draw the puzzle in the Pascal program, but how do I make it so that the letters are replaced with a blank space but the numbers are still left? I know that to 'erase' the letters I can use a if-then-else statement, but what about the numbers?

    2. Now this is a real tough nut to crack. How should I store the hints in two different one dimensional arrays (one for horizontal and one for vertical) so that the correct hint can be recalled when the user enters a choice? For example if the user enters '4' (which is the word 'tea' and is in the second horizontal row) the program will then recall the 2nd hint.

    3. For words that share the same first letter (so the word can go across or down), is it correct to use a if-then-else statement to determine which word to fill in?
  • zibadianzibadian Posts: 6,349Member
    : Ok now here's an even tougher problem...
    :
    : * * 1 O F 2 E 3
    : 3 E A * * I * G
    : * * K * * S * G
    : * 4 E 6 C H * *
    : * O * P * * * *
    : 7 R A P E * * *
    : * K * L * * * *
    : * * 8 E M O N *
    : Many people drink it in the morning with milk or cream
    : British people drink it at 5 o'clock
    : Juicy, round, reddish, sweet fruit with a furry skin
    : You make wine from this fruit
    : You make lemonade from this fruit
    : You serve it at birthday parties
    : You can find them in the sea
    : Chickens lay these
    : This is what meat from a pig is called
    : An _____ a day keeps the doctor away
    :
    : Now that is what my text file which contains the crossword looks like.
    :
    : The first 5 hints are the 5 horizontal words and the latter 5 the vertical words respectively.
    :
    : 3 questions:
    : 1. I need to draw the puzzle in the Pascal program, but how do I make it so that the letters are replaced with a blank space but the numbers are still left? I know that to 'erase' the letters I can use a if-then-else statement, but what about the numbers?
    :
    Don't include the numbers in the if-then statement. This way they will remain "not spaced".
    If you want the numbers to be spaced, add them to the if-then statement.

    : 2. Now this is a real tough nut to crack. How should I store the hints in two different one dimensional arrays (one for horizontal and one for vertical) so that the correct hint can be recalled when the user enters a choice? For example if the user enters '4' (which is the word 'tea' and is in the second horizontal row) the program will then recall the 2nd hint.

    I would include a number before the hints. This way the computer can locate the hints, based on the numbers. I've written a simple function to split a string in parts, based on a delimiter. This function can be found here: http://www.codepedia.com/1/StringSplit. This way you have a 1D-array, and you can quickly determine if the word is horizontal or vertical.
    :
    : 3. For words that share the same first letter (so the word can go across or down), is it correct to use a if-then-else statement to determine which word to fill in?
    :
    There are 2 ways of handling this:
    - Ask the player if he wants to enter the horizontal or vertical word.
    - Add the words also to the 1D-array. Especially with StringSplit() you can check if the word is horizontal or vertical based on the location in the array.
  • some dudesome dude Posts: 4Member
    : I would include a number before the hints. This way the computer can locate the hints, based on the numbers. I've written a simple function to split a string in parts, based on a delimiter. This function can be found here: http://www.codepedia.com/1/StringSplit. This way you have a 1D-array, and you can quickly determine if the word is horizontal or vertical.

    Eh, seems that the link doesn't work. ^^;

    Also I must say how graceful I am to you for keeping your patience with me. Well I don't know what struck me tonight but I just figured out 2 tough algorithms and now I have completed 80% of the program. I will send the program to you after I finish it to see if there are any hidden logic errors and whether the program can be polished (made simpler, look better etc) if you don't mind.

    Ok, I will follow up if I have further problems. :)
  • zibadianzibadian Posts: 6,349Member
    : : I would include a number before the hints. This way the computer can locate the hints, based on the numbers. I've written a simple function to split a string in parts, based on a delimiter. This function can be found here: http://www.codepedia.com/1/StringSplit. This way you have a 1D-array, and you can quickly determine if the word is horizontal or vertical.
    :
    : Eh, seems that the link doesn't work. ^^;
    :
    : Also I must say how graceful I am to you for keeping your patience with me. Well I don't know what struck me tonight but I just figured out 2 tough algorithms and now I have completed 80% of the program. I will send the program to you after I finish it to see if there are any hidden logic errors and whether the program can be polished (made simpler, look better etc) if you don't mind.
    :
    : Ok, I will follow up if I have further problems. :)
    :
    http://www.codepedia.com/1/StringSplit
    It took the end-of-sentence dot as part of the link.
Sign In or Register to comment.