HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS challenge, Problem #3 (Level 1)

09-05-2006, 03:59 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 #3 (Level 1)
There is an strange dice game that is similar to poker. A player rolls 5 dices, a group of 5 dice results is a hand.

Hands:
Hand typeDescription
NothingDoes not match any other case.
one pair2 duplicates, example : 1 - 2 - 4 - 1 - 3
one triple3 duplicates, example : 1 - 2 - 1 - 1 - 3
2 pairs2 different pairs, example : 1 - 2 - 4 - 1 - 2
Triple and pair3 have one result, the other 2 have another result, example: 1 - 2 - 2 - 1 - 1
4 of a kindExample : 1 - 2 - 1 - 1 - 1
FullEvery result is the same, example : 1 - 1 - 1 - 1 - 1
Low StairThis sequence: 1 - 2 - 3 - 4 - 5
High StairThis sequence: 2 - 3 - 4 - 5 - 6

"Nothing" is the least important hand and High Stair the best possible one. For example a "4 of a kind" beats a "2 pairs" and a "triple", but it can't beat a "Full".

In the case 2 hands are of the same type, then the one with the highest sum wins. For example: 2 2 3 3 3 beats 1 1 2 2 2 (13>8) . In the case the Sums are the same, it is a tie.

The "flip" rule
Some time ago someone added a very exploitable rule to the game, the flip rule. If a player yells "flip!" before rolling the dices he can then choose to invert one of the dices. For example 1 1 5 1 6 can be converted into 1 1 5 1 1 or 1 1 2 1 6 .

Thomas has figured out that if he always yells flip it increases the probability to get a good hand, cause it allows him to choose which dice to invert, and removing most of the influence of luck.

But Thomas is not smart enough to figure out the best result himself, so he asked the programmers to make him a program that could always choose the best dice to invert. Something like this:

Collapse JASS:
function ChooseBestFlip takes integer d1, integer d2, integer d3, integer d4, integer d5 returns integer

for example: ChooseBestFlip(1,1,6,1,1) should return 3, if we invert dice #3, then the hand would be a Full (1 1 1 1 1 1). If we flip any other dice the result would be a Triple and pair (1 1 1 6 6)

ChooseBestFlip(2,2,5,5,5) should return 1. Flipping dice #1 or #2 would result in the same hand, but that doesn't matter, 1 or 2 are both good solutions for this case.


ChooseBestFlip(1,1,1,1,1) should return 1,2,3,4 or 5 . Notice that the result hand will always be actually worse than the original one. But we are forced to invert one of them, choose the one that would do the less harm.

ChoseBestFlip(3,2,3,2,3) for example should return 1,3 or 5 , if you invert #2 then the result is a "Triple", If you instead invert #3 the result is a "2 pairs" which beats a Triple.

Anyone can join this problem, if you beat it you will be able to enter level 2 next week.


The deadline is next Monday.
09-05-2006, 04:46 AM#2
Rising_Dusk
Hrm...
I can actually visualize how this one should work.
Perhaps I stand a chance afterall.
We shall see.
09-05-2006, 05:04 AM#3
emjlr3
what if two or more are equal

say two different possible inverts both yeild the same type of hand and the same sum, and are better then the original hand, what should it return?

all the possibilities?

not real sure how you would return more then one integer
09-05-2006, 06:31 AM#4
Fireeye
Quote:
Originally posted by Vexorian
In the case 2 hands are of the same type, then the one with the highest sum wins. For example: 2 2 3 3 3 beats 1 1 2 2 2 (13>8) . In the case the Sums are the same, it is a tie.
09-05-2006, 07:07 AM#5
Daelin
Isn't this taken from Yacht?

And as I knew, full (or full house) was 1-1-1-2-2 for example, while yacht was 1-1-1-1-1 (all the same).

And I also have a question. What does "inverting" a dice mean? That the dice is changed as follows:

6<->1 2<->5 3<->4?

~Daelin
09-05-2006, 10:45 AM#6
SeasonsOfLove
Quote:
Originally Posted by Daelin
And I also have a question. What does "inverting" a dice mean? That the dice is changed as follows:

6<->1 2<->5 3<->4?

Yes.

And this definitely looks a lot like Yahtzee to me, as well
09-05-2006, 11:02 AM#7
SFilip
just to make sure i understood...we need to:
-pick 5 random numbers
-check which of the combinations the numbers match
-make the flip function

if this is true then i don't understand the point of this
Quote:
In the case 2 hands are of the same type, then the one with the highest sum wins. For example: 2 2 3 3 3 beats 1 1 2 2 2 (13>8) . In the case the Sums are the same, it is a tie.
are we supposed to dice the whole thing 2 times and then compare the results?
09-05-2006, 11:08 AM#8
blu_da_noob
Dice are created such that opposite sides add up to 7. Therefore, inverting a die changes its value to 7-x where x is its current value.

As far as I understand the rules, I don't have to do this one to carry on. I'll probably try it anyway (if I have time).

@SFilip: Read the explanation again. It is quite clear.
09-05-2006, 01:15 PM#9
Vexorian
SFilip, you only have to make the ChooseBestFlip function, so whoever tests te function will select the dice results.

Quote:
Isn't this taken from Yacht?

And as I knew, full (or full house) was 1-1-1-2-2 for example, while yacht was 1-1-1-1-1 (all the same).

And I also have a question. What does "inverting" a dice mean? That the dice is changed as follows:

6<->1 2<->5 3<->4?

~Daelin

It might be similar to Yacht but it is not necesarily Yacht, and yes inverting is that.

...
People that are already in level 2 may do a level 1 problem just for fun, but they don't have to.

Quote:
say two different possible inverts both yeild the same type of hand and the same sum, and are better then the original hand, what should it return?

all the possibilities?

You can return any of them. But probably if inverting #3 or #4 has the same maximum result you would return 3 cause it is the minimum but that is not mandatory, it may result 4 and it will still be a right answer.
09-05-2006, 01:22 PM#10
emjlr3
ok that answered my question Vex
09-05-2006, 01:30 PM#11
The)TideHunter(
I'v never been good with making priority based things, i tried to make a poker map once, but failed horribly.
09-05-2006, 01:44 PM#12
emjlr3
i actually understand this one, spent like 30 minutes last nite and got most of it done, the whole choosing best flip part, and inverting

also started the whole figuring out what hand you actually have part, got through the easy ones, just trying to figure out if there is another(or rather, the other way) way then brute force for the rest of the hands
09-12-2006, 10:01 AM#13
luth
A suggestion: Often when given problems such as "Create this function", its useful to create a driver program with a dummy function in place. Perhaps you could create a standardized map that would do everything, with the init and the function calls and the display, but simply have a dummy ChooseBestFlip that looks like:
Collapse JASS:
function ChooseBestFlip takes integer d1, integer d2, integer d3, integer d4, integer d5 returns integer
    return 1
endfunction

That way everyone can put in their own ChooseBestFlip implementations, and not have to worry about doing something silly, like screwing up the driver program. Just a thought.
09-12-2006, 09:45 PM#14
luth
I've attached a simple driver program. It was my hope that a standard driver program will lead to more standardized results, making things easier to test for Vex.

This driver is ready to run, and lacks only a working global "ChooseBestFlip" function. To run the driver:
Type "-roll" for a random five d6 dice rolls.
Type "-roll A B C D E" where A, B, C, D, E are numbers between 1 and 6 to create a specific dice roll.

The output will be the best choice to flip, 1 - 5. An output of 0 means the best course of action is to not flip anything.
Attached Files
File type: w3xChooseBestFlip - Driver Only.w3x (16.7 KB)
09-12-2006, 09:56 PM#15
Naakaloh
Err, sorry if I sound rude... but didn't he ask simply for a PM with your code in [jass] tags? I'm sure Vexorian is competent enough to use your code if it follows the instructions; it would not surprise me if he has already written a driver function of his own...