• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

help for a Function for the game "minesweeper"

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I have a group project (the project is the game the "minesweeper" but we encounter a difficulty, we have a function that must return a boolean, it must return true if one of the squares adjacent to the coordinate box (i,j) is revealed and has no adjacent mine (a mine corresponds to a "-1" on the game, the little game being the project), for example we have :

  |A|B|C|D|E|F|G|H|I|J|
00| | |1|0|0|0|0|2| | |
01| | |1|0|0|0|1|3| | |
02| | |1|0|0|0|1|X| | |
03| | |1|0|0|1|2| | | |
04| | |1|1|1|2|X| | | |
05| | | | | | | |3| | |
06| | | | | | | | | | |
07|1|1| | | | | | |2| |
08|0|1| | | | | | | | |
09|0|1| | | | | | | | |
10|0|1| | | | | | | | |


The for (7,1) the function will return "true" , because it has an adjacent cell revealed and has no adjacent mine.

I had thought of making a "revealed" function and if the cell is revealed and has no adjacent mine, we return true;

I'm sorry if it's not clear ,I'm new! Let me know if you want more precision

Translated with www.DeepL.com/Translator (free version)
 
Marshal
Posts: 26135
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ewen, welcome to the Ranch!

ewen lmj wrote:I had thought of making a "revealed" function and if the cell is revealed and has no adjacent mine, we return true;



Well, yes, that's exactly what the requirements say. In Java those things are called "methods", not "functions", but apart from that yes, that's what you should do.
 
Marshal
Posts: 71098
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What do you think the algorithm would be? How would you do that task without a computer?
 
Marshal
Posts: 7877
547
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ewen lmj wrote:The for (7,1) the function will return "true" , because it has an adjacent cell revealed and has no adjacent mine.


Could be, but what's then?

ewen lmj wrote:I had thought of making a "revealed" function


Word function on its own suggest, that it does somehting. For example, sums something, in which case Sum would be a good function name, draws something, in which case Draw would be a great function name.

And now you suggest Revealed (something what seems happened already in the past). What that supposed to mean/do? Maybe Reveal would be something what would make more sense... Anyway, that seem to be too early.


I suggest you stop thinking about particular function(s) and what they'd return.

Think about the game first. Do you understand the mechanics behind the game? For instance.. Simplest case is probably you guessed correctly, open (or reveal as discussed) the tile, and it is a bomb - game is over. Clear outcome? I'd think so.

Now, you click on the tile, and it isn't a bomb. How many kind of different conceptual scenarios could be in such case?

I guess what I'm trying to say - write down the game first, so you and everybody else understands what's happening behind the hood. Or algorithm so to speak. Once you understand actually how the game works - then would be much easier to start. Somewhere.
 
Liutauras Vilda
Marshal
Posts: 7877
547
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And.. welcome to the Ranch
 
Erwan Jumel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

ewen lmj wrote:The for (7,1) the function will return "true" , because it has an adjacent cell revealed and has no adjacent mine.


Could be, but what's then?

ewen lmj wrote:I had thought of making a "revealed" function


Word function on its own suggest, that it does somehting. For example, sums something, in which case Sum would be a good function name, draws something, in which case Draw would be a great function name.

And now you suggest Revealed (something what seems happened already in the past). What that supposed to mean/do? Maybe Reveal would be something what would make more sense... Anyway, that seem to be too early.


I suggest you stop thinking about particular function(s) and what they'd return.

Think about the game first. Do you understand the mechanics behind the game? For instance.. Simplest case is probably you guessed correctly, open (or reveal as discussed) the tile, and it is a bomb - game is over. Clear outcome? I'd think so.

Now, you click on the tile, and it isn't a bomb. How many kind of different conceptual scenarios could be in such case?

I guess what I'm trying to say - write down the game first, so you and everybody else understands what's happening behind the hood. Or algorithm so to speak. Once you understand actually how the game works - then would be much easier to start. Somewhere.



First of all thank you very much for your welcome! I'm French, and in France on the forums the welcome doesn't happen like that, you are all very kind.

Yes I understand what you mean, with a good understanding of the game it's easier to program, but from what I understand, the method must return true if the adjacent square is revealed and if it has no adjacent mine (the mine is the "-1" so the bomb!).
 
Paul Clapham
Marshal
Posts: 26135
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Erwan Jumel wrote:from what I understand, the method must return true if the adjacent square is revealed and if it has no adjacent mine (the mine is the "-1" so the bomb!).



Not "the" adjacent square -- there's always more than one adjacent square. But other than that, do you have another question to ask?
 
Erwan Jumel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Erwan Jumel wrote:from what I understand, the method must return true if the adjacent square is revealed and if it has no adjacent mine (the mine is the "-1" so the bomb!).



Not "the" adjacent square -- there's always more than one adjacent square. But other than that, do you have another question to ask?


Thank you for your answers, but I still don't see how to do it, thank you anyway!
 
Paul Clapham
Marshal
Posts: 26135
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that your group has written some code which describes your array of cells? And a way of determining whether a cell is revealed or not? If not, that needs to be done BEFORE you can start writing code which works with the cells.
 
Liutauras Vilda
Marshal
Posts: 7877
547
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Erwan Jumel wrote:Yes I understand what you mean, with a good understanding of the game it's easier to program, but from what I understand, the method must return true if the adjacent square is revealed and if it has no adjacent mine (the mine is the "-1" so the bomb!).


Well, it isn't very clear what kind of functionality you'd be trying to satisfy with such method.

So we have this, what you wrote earlier:

Erwan Jumel wrote:...we have a function that must return a boolean, it must return true if one of the squares adjacent to the coordinate box (i,j) is revealed and has no adjacent mine


Do you have some class which holds information whether it was revealed or not?  Do you have some method which tells how many bombs you have in adjacent tiles? Without having that information, obviously you couldn't return true or false, simply because you couldn't make a decision without such information.

You mentioned it is a group project, so I still don't fully understand what is your task. Just that one method to implement? If that's the case, you need to wait until somebody else done their job. Or you need to implement full game?
 
Erwan Jumel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Erwan Jumel wrote:Yes I understand what you mean, with a good understanding of the game it's easier to program, but from what I understand, the method must return true if the adjacent square is revealed and if it has no adjacent mine (the mine is the "-1" so the bomb!).


Well, it isn't very clear what kind of functionality you'd be trying to satisfy with such method.

So we have this, what you wrote earlier:

Erwan Jumel wrote:...we have a function that must return a boolean, it must return true if one of the squares adjacent to the coordinate box (i,j) is revealed and has no adjacent mine


Do you have some class which holds information whether it was revealed or not?  Do you have some method which tells how many bombs you have in adjacent tiles? Without having that information, obviously you couldn't return true or false, simply because you couldn't make a decision without such information.

You mentioned it is a group project, so I still don't fully understand what is your task. Just that one method to implement? If that's the case, you need to wait until somebody else done their job. Or you need to implement full game?


Hey! To answer you, no we are only 2 in our group and I have already done other functions of the project it's just that we are stuck on this one in particular!

And yes, we have a method that counts the number of adjacent mines, and also one that allows us to know if it is revealed.
 
Saloon Keeper
Posts: 4168
160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a "Cell" class? If so, how does it look?

Erwan Jumel wrote:And yes, we have a method that counts the number of adjacent mines, and also one that allows us to know if it is revealed.


Is your problem solved then?
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic