Author Topic: Pig  (Read 15133 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #30 on: October 19, 2018, 10:54:03 pm »
Hi Johnno,

I am wondering if the two dice game is working as expected for 2 dice ie following the rules of play correctly.
The code you posted did not work properly (It would jump suddenly from player rolling to AI without player seeing what they rolled probably had a 1 in it which caused the switch of play??? need a pause right there so player can see what is going on.) so I could not tell from that.

Where my Pig 2 Dice game code says:
PRINT CHR$(10) + "The dice are:"; d1; "and"; d2
Here is where you would call the sub to do whatever thing you want, to show off dice.

And at least everywhere there is an INPUT, there, you would call a sub to display a pretty score board and wait for a keypress to exit sub and continue play.

I would say those 2 things are main difference of my Pig 2 dice game and the spaghetti western one. :)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #31 on: October 20, 2018, 12:02:22 am »
I cannot attest to the accuracy of the game-play, as I did not write the program. All I did was to copy the book listing into the QB64 IDE and modify the graphics where needed. But I did say, from the beginning, that they (Pig and Groan) were similar.

The switching of players is pretty much automatic as soon as a one or double one is rolled. There should be a brief delay, so as to see either a single or double groan message, before the next roller has a turn... in theory that is... lol

I have transposed this game, on more than one occasion, into several types of basic and have not experienced any 'game flow' difficulties. But, that being said, the basics I used were quite old and slow. The poor things probably couldn't switch players fast enough, even if they could... lol

If you need to check the program, https://www.dropbox.com/s/wtumork8p6otiq2/TRS-80%20Programs%20%281980%29%28Tom%20Rugg%29%28pdf%29.pdf?dl=0, from page 119 onwards
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #32 on: October 20, 2018, 09:16:07 am »
Hmm,,,, Johnno, I am getting impression this not a game you want to pursue development wise. You were just offering as example of 2 Dice Game like Pig and unfortunately I could not learn anything useful from that version because in my view it doesn't work well enough to learn how the play of the game goes. And the spaghetti code would be hell to try and fix! So, so much for that, ha! ;-))

I am interested in developing a version as mentioned before of each player choosing how many dice for a one roll turn, where again one 1 will gain no points, two 1's will loose your score and three 1's and game over.

New: FOUR 1's and you are automatic winner! So high risk offers high reward!

This game, since it is a QB64 forum variation, I would like to develop with sound and graphics, perhaps an Oink! for every dice chosen above one or 2 and of course we have to work in some appropriate pig images for winners and losers and AI's pig and human's pig avatar... Dice rolling sound, dice images rolling, I bet people have versions of that?

Anybody feel free to offer ideas, sounds and or pig images, I or we could be free to use.

Potential names:
Hog Heaven
Bringing Home the Bacon
Porkers

Also since there seems an advantage to who rolls first, who rolls first will be decided randomly by a farmer referee possibly?
(Come to think of it, I got that idea partially form Johnno's code but also from Rosetta Challenge that offers bragging rights bonus for analyzing different AI strategies and then they mentioned an advantage to the first roller also.)

Oh opening screen sound: the farmer calling his pigs home. ;-))
« Last Edit: October 20, 2018, 10:13:26 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #33 on: October 22, 2018, 09:41:23 am »
Reading over this thread, I see I forgot to handle the condition of rolling 2 ones in the 2 Dice version of Pig, what Johnno is calling Groan.

Here I added that and also splendidly colorized game. :D

Code: QB64: [Select]
  1. _TITLE "Pig with 2 Dice" 'get Johnno setup with 2 di version of Pig B+ started 2018-10-19
  2. '2018-10-22 fixed handling of rolling two 1's when score should be reset to 0 and colorized
  3.  
  4. WHILE player < 100 AND AI < 100
  5.     IF Who$ <> "Player" THEN Who$ = "Player": COLOR 11: ELSE Who$ = "AI": COLOR 9
  6.     accum = 0
  7.     FOR i = 1 TO 100
  8.         d1 = INT(RND * 6) + 1: d2 = INT(RND * 6) + 1
  9.         PRINT CHR$(10) + Who$; " dice are:"; d1; "and"; d2
  10.         IF d1 = 1 AND d2 = 1 THEN
  11.             INPUT "Two 1's rolled, so that score is reset to 0, press enter...", wate$
  12.             IF Who$ = "AI" THEN AI = 0 ELSE player = 0
  13.             EXIT FOR
  14.         ELSEIF d1 = 1 OR d2 = 1 THEN
  15.             INPUT "A 1 was rolled, the turn is over, press enter..."; wate$
  16.             EXIT FOR
  17.         ELSE
  18.             accum = accum + d1 + d2
  19.             PRINT Who$ + " accumulated total is" + STR$(accum)
  20.             IF Who$ = "Player" THEN
  21.                 COLOR 14
  22.                 INPUT "Do you want to (r)oll again or hold? Enter r or just enter to hold"; choice$
  23.                 COLOR 11
  24.                 IF choice$ <> "r" THEN player = player + accum
  25.                 IF choice$ <> "r" THEN EXIT FOR
  26.             ELSE
  27.                 IF i < 3 AND accum + AI < 100 THEN
  28.                     INPUT "AI is rolling again, press enter... ", wate$
  29.                 ELSE
  30.                     AI = AI + accum
  31.                     INPUT "AI is holding so accumulated amount is added to it's score, press enter...", wate$
  32.                     EXIT FOR
  33.                 END IF
  34.             END IF
  35.         END IF
  36.     NEXT
  37.     COLOR 2
  38.     PRINT CHR$(10) + "Player =" + STR$(player) + "  AI =" + STR$(AI)
  39. PRINT Who$; " wins!"
  40.  
  41.  
« Last Edit: October 22, 2018, 10:00:00 am by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #34 on: October 22, 2018, 04:46:27 pm »
Cool... and I even like the colours...

Side note. A potential name for the game... 'Rashers' staring: Chris P. Bacon  lol
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #35 on: October 23, 2018, 08:57:00 am »
I had never heard of Rashers, Albert Einswine advises Hamlet.

Boink works for me.
« Last Edit: October 23, 2018, 09:00:11 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #36 on: October 23, 2018, 01:58:14 pm »
Prize Pig (so far) fattest code yet!

Code: QB64: [Select]
  1. _TITLE "Boink" ' for QB64 B+ started a version of Pig when/where the number of di is declared and rolled
  2.  
  3.  
  4. ' Boink rules:
  5. ' Start round by flipping coin who goes first
  6. ' Each player chooses number of dice to roll to start their round
  7. ' Dice rolled
  8. ' If 1 di is 1 then no points that turn,
  9. ' If 2 di are 1 then no points and the score is reset to 0,
  10. ' If 3 di are 1 then gameover that player lost,
  11. ' If 4 di are 1 then player wins game automatically,
  12. ' Otherwise the player gets the total of di added to their score.
  13.  
  14.  
  15. CONST wholeHog = 7
  16. Sooie = 1
  17. WHILE Sooie
  18.     IF RND < .5 THEN
  19.         GOSUB FarmerRound
  20.         IF Sooie THEN GOSUB HALRound
  21.     ELSE
  22.         GOSUB HALRound
  23.         IF Sooie THEN GOSUB FarmerRound
  24.     END IF
  25.  
  26. FarmerRound:
  27. Who$ = "Farmer"
  28. cp "Farmer, Enter how many dice to roll."
  29. LOCATE , 38: INPUT ; hogHerd
  30. GOSUB RollEmRollEM
  31.  
  32. HALRound:
  33. Who$ = "HAL"
  34. hogHerd = INT(wholeHog * (100 - HAL) / 100 + .5)
  35. IF hogHerd = 0 THEN hogHerd = 1
  36. GOSUB RollEmRollEM
  37.  
  38. RollEmRollEM:
  39. pigsEye = 0: bacon = 0
  40. s$ = Who$ + "'s, dice roll is:"
  41. FOR pigglet = 1 TO hogHerd
  42.     Babe = INT(RND * 6) + 1
  43.     IF Babe = 1 THEN pigsEye = pigsEye + 1
  44.     bacon = bacon + Babe
  45.     s$ = s$ + " " + STR$(Babe)
  46. cp s$
  47. SELECT CASE pigsEye
  48.     CASE 0
  49.         IF Who$ = "Farmer" THEN Farmer = Farmer + bacon ELSE HAL = HAL + bacon
  50.         cp Who$ + "," + STR$(bacon) + " has been added to your score."
  51.         IF Farmer >= 100 OR HAL >= 100 THEN Sooie = 0: cp Who$ + " wins!"
  52.     CASE 1
  53.         cp Who$ + " rolled a 1, so your score remains the same."
  54.     CASE 2
  55.         IF Who$ = "Farmer" THEN Farmer = 0 ELSE HAL = 0
  56.         cp Who$ + " rolled two 1's, so your score is reset to 0."
  57.     CASE 3
  58.         cp Who$ + ", sorry three 1's means you lost the game."
  59.         Sooie = 0
  60.     CASE ELSE
  61.         cp Who$ + " more than three 1's makes you the winner!"
  62.         Sooie = 0
  63. cp "Press any..."
  64. IF Sooie THEN
  65.     k$ = INKEY$
  66.     WHILE LEN(k$) = 0: k$ = INKEY$: _LIMIT 100: WEND
  67.     COLOR _RGB(255, 150, 170)
  68.     PRINT
  69.     cp "Boink Score Board:  Farmer =" + STR$(Farmer) + "  HAL =" + STR$(HAL)
  70.     PRINT
  71.  
  72. SUB cp (s$)
  73.     LOCATE , (80 - LEN(s$)) / 2: PRINT s$
  74.  
  75.  
« Last Edit: October 23, 2018, 02:28:26 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #37 on: October 23, 2018, 03:27:46 pm »
Nice variation... Cool.  I see you have located, and used, some of the original 1945 options... (I looked up 'Pig'...) - However, and I am in no way asking you to make changes, one of the options of selecting the number of dice (die) is that the number 6 is treated like a number 1. But only when choosing the number of dice greater than two...

By the way... Playing your last version (with double ones) seemed to take forever. The number of times a double one came up was almost frustrating... Got to 86 points and Pow! Double one... Not just my rolls either... Played several times, but the 'loosing streak', did not occur again... Whew!

If ever you want to use graphics I have made two sets of dice. Red and White. The number one 'dot' now has a pig's face.
* pig-assets.zip (Filesize: 211.47 KB, Downloads: 254)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #38 on: October 23, 2018, 04:19:25 pm »
Hi Johnno,

Great! Thanks, there goes Screen 0, sorry Pete. ;(

Now these sounds do work on your Linux, correct?

Also, wasn't it you that had some dice rolling code? Maybe SdlBasic style or even Naalaa? That would be easily converted to QB64.

PS RE: 6 too?
I am awaiting codeguy's analysis of 1 frequency for n amount of di, in meantime one is enough. :D
« Last Edit: October 23, 2018, 04:26:26 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #39 on: October 23, 2018, 05:09:01 pm »
In regards to the sounds... Yes they do. If this is not the case for you, I can convert them to whichever format you desire.

Screen 0? Oh. you were going for 'Text Only'? Not a problem. Will not be offended if you decide not to use them. Hang on to them for another project.

Dice rolling code? I will check but I have my doubts. I personally use the method int(rnd*6)+1 (rnd(6)).  I mentioned that 'Groan' had an animation sequence for the dice roll, but for your program, a better one is needed. The TRS80 version is too 'chunky'. I will research some code. Question: Do you want the dice to roll at the same time or one after the other (the latter can slightly add to the 'suspense'... lol)

« Last Edit: October 23, 2018, 05:21:41 pm by johnno56 »
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #40 on: October 23, 2018, 05:19:34 pm »
Update: Dice.

Back in August of 2014, I posted an image of a 'dice' spinner, from the 1943 UK version of Monopoly. It is only for two dice. Other than that, I am still looking...

J
8443.jpg
* 8443.jpg (Filesize: 14.96 KB, Dimensions: 180x265, Views: 290)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #41 on: October 23, 2018, 05:26:07 pm »
Hey Johnno,

(You posted while I was composing this reply, Oh I remember that! like a Roulette Wheel!)

Screen 0  is like tinkering around on the piano until you find a nice little melody, then writing the score for the full orchestra. Isn't that how Flappy Bird started?

I ask about sound because with Battleship you provided great stuff but after mods the sound did not work as I recall. I find such very disappointing because it was you who provided the sound.

Don't worry about what kind of code for the dice rolling you find, it will probably be modified anyway...

Just want to get this pig to fly! ;-))

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pig
« Reply #42 on: October 23, 2018, 05:31:31 pm »
Try these for dice: https://notendur.hi.is/~ade3/Backgammon/images/dice2.png

That's a nice enough sheet, you could animate a good rolling animation.
« Last Edit: October 23, 2018, 05:32:48 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #43 on: October 23, 2018, 05:37:26 pm »
Oh that sheet looks good!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pig
« Reply #44 on: October 23, 2018, 05:49:33 pm »
Oh that sheet looks good!

You know, I'd even change my randomization routine to fit it.  Instead of just Dice = RND * 6 + 1, I'd set up a method to randomly choose up/down/left/right and then loop it until the user hits a key.  The random would choose which part of the sheet to show, making it the number we end up with.

At a decent display speed, it'd be hard for the user to "cheat" and force a value, but it'd look dang nice while rolling.   Add a little rattle, rattle, and you've got a work of art there.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!