HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS programming survival Problem #2 (lv 2)

09-05-2006, 03:29 AM#1
Vexorian
Rules
* The winner will get 60 rep and a price icon for bellow his avatar.
* I post 1 programming problem.
* You send me the solution inside [jass] tags by a private message. (Do me a favor and first test it in game)
* Deadline ends then I post the winners. A solution to the problem and explanations on why some people didn't win.
* I post another problem
* The cycle is repeated.
* Once you beat a level 1 problem you can join level 2 problems, then level 3 and so and so (Difficulty grows exponentially ) There will be 3 problems per level.

* In case no one solves at least 1 problem of the last level the price will be distributed between the winners of the level before last level. Unless no one beats the first level, in that case I am gonna change this forum's name into "Triggers"

* The idea of the level based elimination is supposed to prevent people losing just because they were busy one week.

* I will release 1 problem per level with enabled contestants each week.

* You can use as much scripts made by someone else as you want, as long as those functions are general usage ones, and they do not solve the problem directly (none of my problems will have a solution of that kind though).

* If your code requres a system like CSCache or Kattana's things or Pipedream's or Karukef's just tell me about it.
* If your code requires global variables please include them inside a globals block:

Collapse JASS:
globals
    <type> [array] <name> [= initial value]
endglobals


* In no way should you spoil the fun to the other people and post solutions, avoid clues as well. If I find it necesary I will post hints myself.

Problem #2 (Level 2)
Simon just wants to make a minesweeper game. You all know what that game is about, there is a board with a lot of squares and when you click one square 3

things might happen:
- The square had a hidden land mine, you lose.
- At least one of the squares sorrounding the one you clicked had a hidden land mine, then the square should show a number from 1 to 8 telling you the number of mines in the sorrounding squares.
- There are no mines, not even around the square, then we call these squares "FREE SQUARES" the sorrounding squares also get revealed, each of them follows these rules as well (Some of them might even be free squares as well and reveal even more squares)

If you have trouble understanding this, well just go to the run dialog and type WINMINE , then press F1 that should be enough of an explanation.

But well the first step of the development of this game is to choose which square should have a land mine. And also have a table that reads the number of mines sorrounding each square. So the task of this problem is simply to generate the board.


MS' minesweeper generates the board after you click your first square. This prevents the game from exploding on the player's first step. But that is still kind of a lame solution cause the game might explode on you on the second step. Instead it would be better to automatically reveal the biggest group of close free squares. That would ensure a decent playability.

So when generating the board it would be cool if you show the square to reveal automatically when the game starts.

Anyways this is what we want:

A function with this prototype (case sensitive):

Collapse JASS:
function GenerateBoard takes integer n, integer mines returns nothing


Each time this function is called it should generate (and show) an n×n board with (mines) total mines (random positions) . n is a positive integer lower than 31, and mines is always less than 75% of n*n

Since text messages don't use a monospace font, it would be better to show the board in a multiboard. The contents of the multiboard should be like these:

GenerateBoard(6,4):
* * 1 - - -

3 4 2 2 1 1

* 2 * 1 * 1

2 1 1 1 1 1

* 1 # - - -

1 1 - - - -



Mines would use *
Free squares use -
Other squares with mines sorrounding them should show the number of mines sorrounding them.

A free square that is part of the biggest group of close free squares should use the # character.

Notice that if we release the # square in this case then the game would begin like this:



Code:
           

           

           

  1 1 1 1 1

  1 - - - -

  1 - - - -


We chose that group of free squares because the other group of free squares only has 3, as opposed to this one with 8 free squares.

If more that 1 group of free squares has the maximum number of free square you can choose whichever you want. Also the # can go to any of the free squares of the biggest group.

So,

GenerateBoard(6,4):
* * 1 - - -

3 2 1 1 1 1

* 1 1 1 * 1

2 1 1 1 1 1

* 1 - - - -

1 1 - - # -


Is correct as well.

Extra notes:
* If there are no free squares in the whole board then you should show the board as usual but display an error message "LUCK DEPENDANT!"

* Because of the rules of the game then all the free squares in this board belong to the same group:
Code:
1 * 1 - -

1 1 1 - -

1 1 - 1 1

* 1 - 1 *

* Avoid extremely slow solutions. I won't like to wait much more than 2 minutes for the solution.

The deadline is next Monday.

Can join:
Quote:
BertTheJasser
CaptainGriffen
UnMi
phyrex1an
DotA_DR
Daelin
Pipedream
Naakaloh
Acehart
Guesst
BDSM
MeanMachine
blu_da_noob

The rest should go to problem #3
09-05-2006, 03:45 AM#2
Guesst
Is that function the only thing we have to make, or do we have to make the whole game functional? I am leaning towards just the function, but then I don't see why you would explain the whole game.

Code:
* 1 - -

1 - 1 1

- - 1 *
Why isn't the square one down and one to the right of that first mine a 1?


Quote:
Empty squares would use the - character.
Mines would use *
Free squares use -
Other squares with mines sorrounding them should show the number of mines sorrounding them.
Is there a difference between free and empty?
09-05-2006, 04:06 AM#3
Vexorian
No, no only show the board, I explained the game cause otherwise you wouldn't know how to fill the board (well not you but somebody that have never seen minesweeper before), the other things are a mistake, fixed them
09-05-2006, 05:58 AM#4
PipeDream
So all the state of the board is to be displayed, along with the usual minesweeper numbers and a different character to represent the largest free group? Does it matter whether only one of the free group squares is "#" or can they all be "#"?
09-05-2006, 06:42 AM#5
Anitarf
Vex, you suck at minesweeper. :P The numbers on that 6x4 board are incorrect.
09-05-2006, 06:52 AM#6
Daelin
Quote:
Originally Posted by PipeDream
So all the state of the board is to be displayed, along with the usual minesweeper numbers and a different character to represent the largest free group? Does it matter whether only one of the free group squares is "#" or can they all be "#"?

Quote:
Originally Posted by Vexorian
Also the # can go to any of the free squares of the biggest group.

~Daelin
09-05-2006, 06:59 AM#7
PipeDream
I could break down exactly why that is ambiguous, but it doesn't matter. A yes or no answer please =)
09-05-2006, 07:03 AM#8
Daelin
Oooh... the ANY stuff as in one or more? Well, since Vex's example places it into only one, I guess we should follow his pattern.

~Daelin
09-05-2006, 08:00 AM#9
MeanMachine
Can we use bj functions for setting values in the multiboard?
09-05-2006, 11:19 AM#10
blu_da_noob
Should be quite doable (and the numbers are small enough for thread limit to not really play a role :D).
09-05-2006, 12:34 PM#11
Daelin
Quote:
Originally Posted by blu_da_noob
(and the numbers are small enough for thread limit to not really play a role :D).

You think? 900 fields... sound enough to me. To first get the mines, then the numbers, and then find the field with the most empty spaces... Trust me, it's more than enough.

~Daelin
09-05-2006, 01:12 PM#12
Vexorian
hmnn if you want to mark all of the Free squares of the biggest group do so, although I think that only marking one of them is enough. Cause it would automatically release the rest.
09-05-2006, 01:37 PM#13
UnMi
Um..I didn't quite understand the levels of Problems thing...but hell, this one sounds more fun.
09-05-2006, 01:55 PM#14
blu_da_noob
Quote:
Originally Posted by Daelin
You think? 900 fields... sound enough to me. To first get the mines, then the numbers, and then find the field with the most empty spaces... Trust me, it's more than enough.

~Daelin

You might get to the thread limit if you do everything in one thread (not sure yet, I have to get all the steps out), but even if you do, each step should only require a single thread. Having to use multiple threads for each step is a pain (like I had to do for my maze generator, this requires some of the same basic principles in parts).
09-05-2006, 02:10 PM#15
Naakaloh
I'm assuming there's some reasonable limit on the size of n, since it was suggested that a multiboard be used.