Merge pull request #2621 from xexyl/burley04-fix

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2024-08-07 08:24:06 -07:00
commit 7bcd21ec78
5 files changed
+121 -62

No files matched your search

+52 -26
View File
@@ -4,7 +4,7 @@
make make
``` ```
NOTE: We FORCE the use of -O0 even if someone overrides it because this entry **NOTE**: We FORCE the use of `-O0` even if someone overrides it because this entry
will not work with it enabled. will not work with it enabled.
@@ -14,7 +14,7 @@ will not work with it enabled.
./burley ./burley
``` ```
NOTE: you need to input a number first. See judges' remarks below for **NOTE**: you need to input a number first. See judges' remarks below for
information on how to play. information on how to play.
@@ -22,32 +22,57 @@ information on how to play.
This is a [draw poker](https://en.wikipedia.org/wiki/Draw_poker) program. You This is a [draw poker](https://en.wikipedia.org/wiki/Draw_poker) program. You
start with $100. Input alternates between your bet and which cards to keep. start with $100. Input alternates between your bet and which cards to keep.
Example:
``` ### Example:
5 <== you enter a bet of $5 (defaults to $1)
J Q J 9 5 <== your hand is Jack of Clubs, Queen of Hearts, Here is an example.
C H D S C Jack of Diamonds, 9 of Spades, 5 of Clubs
123 <== you enter which cards you want to keep First, enter your bet (say `5`) (for $5, defaults to $1). You might then see
(enter 0 to 5 digits between 1 and 5) something like:
J Q J J Q <== your new hand is Jack of Clubs, Queen of Hearts,
C H D S C Jack of Diamonds, Jack of Spaces, Queen of clubs > J Q J 9 5<br>
$145 (45) <== Your new balance is now $145. You had a Full House > C H D S C
so your payoff is 9 times your bet == 45
``` That indicates your hand is Jack of Clubs, Queen of Hearts, Jack of Diamonds, 9
of Spades and 5 of Clubs.
Now enter what cards you want to keep (enter 0 to 5 digits between 1 and 5).
Let's say you want to keep 1, 2 and 3 so you enter `123`. You should see
something like the following after you hit enter:
> J Q J J Q<br>
> C H D S C
which tells you that your new hand is Jack of Clubs, Queen of Hearts, Jack of
Diamonds, Jack of Spaces and Queen of clubs. You might now see something like:
> $145 (45)
which tells you that your new balance is now $145. You had a Full House so your
payoff is 9 times your bet == 45.
#### Payout:
The payout is according to "Vegas rules": The payout is according to "Vegas rules":
``` - **Straight Flush**
Straight Flush 50 times your bet * 50 times your bet
Four of a Kind 25 times your bet - **Four of a Kind**
Full House 9 times your bet * 25 times your bet
Flush 6 times your bet - **Full House**
Straight 4 times your bet * 9 times your bet
3 of a Kind 3 times your bet - **Flush**
2 Pair 2 times your bet * 6 times your bet
Jacks or Better 1 times your bet - **Straight**
``` * 4 times your bet
- **3 of a Kind**
* 3 times your bet)
- **2 Pair**
* 2 times your bet
- **Jacks or Better**
* 1 times your bet
### Other things:
The program allows you to go into debt. However I'm sure you would never The program allows you to go into debt. However I'm sure you would never
control-C to kill the program just because you got behind, right? On the other control-C to kill the program just because you got behind, right? On the other
@@ -60,9 +85,10 @@ the program so this "strategy" no longer works?
Notice the clever use of `setjmp(3)` and `longjmp(3)` calls. Can you keep track Notice the clever use of `setjmp(3)` and `longjmp(3)` calls. Can you keep track
of what state is being saved and restored? of what state is being saved and restored?
NOTE: the author talks about how it is a single statement. This might not be **NOTE**: the author talks about how it is a single statement. This might not be
strictly true in 2023 for the fixes for it to work so you can look at the strictly true in 2023 for the fixes for it to work so you can look at the
original file [burley.orig.c](%%REPO_URL%%/2004/burley/burley.orig.c) to see what is meant. original file [burley.orig.c](%%REPO_URL%%/2004/burley/burley.orig.c) to see
what is meant.
## Author's remarks: ## Author's remarks:
+3 -4
View File
@@ -1,8 +1,9 @@
char a[80]; char a[80];
int e[4],g[5],c=100,h,i,j,k,b,f,s,t; int e[4],g[5],c=100,h,i,j,k,b,f,s,t;
jmp_buf p[4]; jmp_buf p[4];
int pain(char *d){ int main(int argc,char**D){
return pain((char*)((srand(time((time_t*)&h)), char*d=(char*)D;
return main(argc,(char*)((srand(time((time_t*)&h)),
setjmp(p[2]), setjmp(p[2]),
(k=atoi((fgets(a,sizeof a, stdin), (k=atoi((fgets(a,sizeof a, stdin),
a+strspn(a," -")))) a+strspn(a," -"))))
@@ -89,5 +90,3 @@ i+=i+1,
longjmp(p[0],0)),0), longjmp(p[0],0)),0),
longjmp(p[2],3)),0)); longjmp(p[2],3)),0));
} }
int main(int argc,char**d){
return pain((char*)d);}
+66 -23
View File
@@ -409,34 +409,76 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
<!-- BEFORE: 1st line of markdown file: 2004/burley/README.md --> <!-- BEFORE: 1st line of markdown file: 2004/burley/README.md -->
<h2 id="to-build">To build:</h2> <h2 id="to-build">To build:</h2>
<pre><code> make</code></pre> <pre><code> make</code></pre>
<p>NOTE: We FORCE the use of -O0 even if someone overrides it because this entry <p><strong>NOTE</strong>: We FORCE the use of <code>-O0</code> even if someone overrides it because this entry
will not work with it enabled.</p> will not work with it enabled.</p>
<h2 id="to-use">To use:</h2> <h2 id="to-use">To use:</h2>
<pre><code> ./burley</code></pre> <pre><code> ./burley</code></pre>
<p>NOTE: you need to input a number first. See judges’ remarks below for <p><strong>NOTE</strong>: you need to input a number first. See judges’ remarks below for
information on how to play.</p> information on how to play.</p>
<h2 id="judges-remarks">Judges’ remarks:</h2> <h2 id="judges-remarks">Judges’ remarks:</h2>
<p>This is a <a href="https://en.wikipedia.org/wiki/Draw_poker">draw poker</a> program. You <p>This is a <a href="https://en.wikipedia.org/wiki/Draw_poker">draw poker</a> program. You
start with $100. Input alternates between your bet and which cards to keep. start with $100. Input alternates between your bet and which cards to keep.</p>
Example:</p> <h3 id="example">Example:</h3>
<pre><code> 5 &lt;== you enter a bet of $5 (defaults to $1) <p>Here is an example.</p>
J Q J 9 5 &lt;== your hand is Jack of Clubs, Queen of Hearts, <p>First, enter your bet (say <code>5</code>) (for $5, defaults to $1). You might then see
C H D S C Jack of Diamonds, 9 of Spades, 5 of Clubs something like:</p>
123 &lt;== you enter which cards you want to keep <blockquote>
(enter 0 to 5 digits between 1 and 5) <p>J Q J 9 5<br>
J Q J J Q &lt;== your new hand is Jack of Clubs, Queen of Hearts, C H D S C</p>
C H D S C Jack of Diamonds, Jack of Spaces, Queen of clubs </blockquote>
$145 (45) &lt;== Your new balance is now $145. You had a Full House <p>That indicates your hand is Jack of Clubs, Queen of Hearts, Jack of Diamonds, 9
so your payoff is 9 times your bet == 45</code></pre> of Spades and 5 of Clubs.</p>
<p>Now enter what cards you want to keep (enter 0 to 5 digits between 1 and 5).
Let’s say you want to keep 1, 2 and 3 so you enter <code>123</code>. You should see
something like the following after you hit enter:</p>
<blockquote>
<p>J Q J J Q<br>
C H D S C</p>
</blockquote>
<p>which tells you that your new hand is Jack of Clubs, Queen of Hearts, Jack of
Diamonds, Jack of Spaces and Queen of clubs. You might now see something like:</p>
<blockquote>
<p>$145 (45)</p>
</blockquote>
<p>which tells you that your new balance is now $145. You had a Full House so your
payoff is 9 times your bet == 45.</p>
<h4 id="payout">Payout:</h4>
<p>The payout is according to “Vegas rules”:</p> <p>The payout is according to “Vegas rules”:</p>
<pre><code> Straight Flush 50 times your bet <ul>
Four of a Kind 25 times your bet <li><strong>Straight Flush</strong>
Full House 9 times your bet <ul>
Flush 6 times your bet <li>50 times your bet</li>
Straight 4 times your bet </ul></li>
3 of a Kind 3 times your bet <li><strong>Four of a Kind</strong>
2 Pair 2 times your bet <ul>
Jacks or Better 1 times your bet</code></pre> <li>25 times your bet</li>
</ul></li>
<li><strong>Full House</strong>
<ul>
<li>9 times your bet</li>
</ul></li>
<li><strong>Flush</strong>
<ul>
<li>6 times your bet</li>
</ul></li>
<li><strong>Straight</strong>
<ul>
<li>4 times your bet</li>
</ul></li>
<li><strong>3 of a Kind</strong>
<ul>
<li>3 times your bet)</li>
</ul></li>
<li><strong>2 Pair</strong>
<ul>
<li>2 times your bet</li>
</ul></li>
<li><strong>Jacks or Better</strong>
<ul>
<li>1 times your bet</li>
</ul></li>
</ul>
<h3 id="other-things">Other things:</h3>
<p>The program allows you to go into debt. However I’m sure you would never <p>The program allows you to go into debt. However I’m sure you would never
control-C to kill the program just because you got behind, right? On the other control-C to kill the program just because you got behind, right? On the other
hand the program never willingly exits, so you have to leave even when you are hand the program never willingly exits, so you have to leave even when you are
@@ -445,9 +487,10 @@ ahead. :-)</p>
the program so this “strategy” no longer works?</p> the program so this “strategy” no longer works?</p>
<p>Notice the clever use of <code>setjmp(3)</code> and <code>longjmp(3)</code> calls. Can you keep track <p>Notice the clever use of <code>setjmp(3)</code> and <code>longjmp(3)</code> calls. Can you keep track
of what state is being saved and restored?</p> of what state is being saved and restored?</p>
<p>NOTE: the author talks about how it is a single statement. This might not be <p><strong>NOTE</strong>: the author talks about how it is a single statement. This might not be
strictly true in 2023 for the fixes for it to work so you can look at the strictly true in 2023 for the fixes for it to work so you can look at the
original file <a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2004/burley/burley.orig.c">burley.orig.c</a> to see what is meant.</p> original file <a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2004/burley/burley.orig.c">burley.orig.c</a> to see
what is meant.</p>
<h2 id="authors-remarks">Author’s remarks:</h2> <h2 id="authors-remarks">Author’s remarks:</h2>
<p>This program plays draw poker. What is unusual about it is that it <p>This program plays draw poker. What is unusual about it is that it
is written as a single statement – count the semicolons! (OK, there is written as a single statement – count the semicolons! (OK, there
-4
View File
@@ -3005,10 +3005,6 @@ expression with <code>void</code> or if it is for some other reason).</p>
<p><code>longjmp(3)</code> was being called with one arg which was an element <p><code>longjmp(3)</code> was being called with one arg which was an element
of an <code>int[4][1000]</code> which had to be changed to a <code>jmp_buf p[4]</code> (this due to of an <code>int[4][1000]</code> which had to be changed to a <code>jmp_buf p[4]</code> (this due to
the prototype being included).</p> the prototype being included).</p>
<p><code>main()</code> also called itself but this was a problem so it now calls another
function <code>poke()</code> which calls itself instead (this is sometimes necessary
nowadays and other entries had to have this same kind of change,
<a href="2001/anonymous/index.html">2001/anonymous</a> being a good example).</p>
<p>Finally the optimiser cannot be enabled so the compiler flags were changed for <p>Finally the optimiser cannot be enabled so the compiler flags were changed for
this, forcing <code>-O0</code>.</p> this, forcing <code>-O0</code>.</p>
<div id="2004_gavare"> <div id="2004_gavare">
-5
View File
@@ -3710,11 +3710,6 @@ expression with `void` or if it is for some other reason).
of an `int[4][1000]` which had to be changed to a `jmp_buf p[4]` (this due to of an `int[4][1000]` which had to be changed to a `jmp_buf p[4]` (this due to
the prototype being included). the prototype being included).
`main()` also called itself but this was a problem so it now calls another
function `poke()` which calls itself instead (this is sometimes necessary
nowadays and other entries had to have this same kind of change,
[2001/anonymous](2001/anonymous/index.html) being a good example).
Finally the optimiser cannot be enabled so the compiler flags were changed for Finally the optimiser cannot be enabled so the compiler flags were changed for
this, forcing `-O0`. this, forcing `-O0`.