Closed Thread
Results 1 to 5 of 5

Thread: How to write a Mastermind game without using array and pointer?

  1. #1
    wtxwt is offline Newbie
    Join Date
    Oct 2007
    Posts
    3
    Rep Power
    0

    How to use Pascal to write a minesweeper game?

    Write a program to input an H x W array of 0’s and 1’s where H and W are also user inputs.
    You may assume that both H and W are non-zero and at most 10. The array represents an H
    x W minefield so that a cell with a 1 (resp. 0) means the cell contains (does not contain) a
    bomb. Your program should print the minefield as follows:
    (1) If a cell contains a bomb, print a ‘#’.
    (2) If a cell does not contain a bomb and is not adjacent to any bomb, print a ‘.’
    (3) Otherwise, print the number of neighboring bombs.

    Sample input and output (user input in boldface):
    5 5
    1 0 0 1 0
    1 1 0 0 0
    0 0 0 0 0
    0 0 0 0 1
    0 0 0 0 0
    #32#1
    ##211
    22111
    ...1#
    ...11
    Last edited by wtxwt; 10-27-2007 at 07:15 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    You only need to store the latest guess and the code, which can be in strings. Then use some loops to work through the two strings using string functions.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    wtxwt is offline Newbie
    Join Date
    Oct 2007
    Posts
    3
    Rep Power
    0
    I don't quite understand what you mean, can you explain it further?
    Last edited by wtxwt; 10-24-2007 at 08:00 AM.

  5. #4
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    That little section of code appears after every single one of his posts. Its like his signature, so just ignore it. That confused me when I first started here too.

    As for the unique random numbers...the rand() function generates pseudorandom numbers. If you seed it with the same number you'll get the same outputs. You did the right thing by seeding it with the time, but to make it even more random, try:

    Code:
    srand(time(NULL));
    int i,seed;
    for(i = 0; i < rand() % 100; ++i)
    {
        seed = rand();
        srand(seed);
    }
    This will loop around a random number of times and keep reseeding the random number generator. Otherwise, your code looks great.

  6. #5
    wtxwt is offline Newbie
    Join Date
    Oct 2007
    Posts
    3
    Rep Power
    0
    I still don't know how to start, pls give a hand to me
    Last edited by wtxwt; 10-24-2007 at 08:01 AM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. pointer to two dimensional array
    By Amonijack in forum C and C++
    Replies: 4
    Last Post: 04-13-2011, 03:27 PM
  2. blueJ game project null.pointer.exception
    By boos in forum Java Help
    Replies: 5
    Last Post: 01-03-2011, 01:27 PM
  3. I'm try to write php array into smarty....?
    By arxh in forum PHP Development
    Replies: 1
    Last Post: 07-26-2010, 03:01 PM
  4. Replies: 9
    Last Post: 04-08-2010, 10:37 AM
  5. Replies: 3
    Last Post: 03-24-2010, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts