Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-18-2007, 09:47 AM
wtxwt wtxwt is offline
Newbie
 
Join Date: Oct 2007
Posts: 3
Rep Power: 0
wtxwt is on a distinguished road
Default 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 09:15 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-18-2007, 10:37 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,057
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-18-2007, 11:23 AM
wtxwt wtxwt is offline
Newbie
 
Join Date: Oct 2007
Posts: 3
Rep Power: 0
wtxwt is on a distinguished road
Default

I don't quite understand what you mean, can you explain it further?

Last edited by wtxwt; 10-24-2007 at 10:00 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-19-2007, 06:09 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 509
Last Blog:
Programs Under the Hoo...
Rep Power: 10
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-20-2007, 10:37 AM
wtxwt wtxwt is offline
Newbie
 
Join Date: Oct 2007
Posts: 3
Rep Power: 0
wtxwt is on a distinguished road
Default

I still don't know how to start, pls give a hand to me

Last edited by wtxwt; 10-24-2007 at 10:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 09:19 AM.

Contest Stats

Xav ........ 162.68
Sacback ........ 120.05
alearb8 ........ 120.05
tfusion ........ 120
amr2107 ........ 120
d3s!gn ........ 120
Qoolman21 ........ 120
Pillager ........ 108
antihero ........ 106
donfrench ........ 100.05

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads