### Author Topic: Pig Game (Rosetta)  (Read 1762 times)

#### B+

• Hero Member
• Posts: 802
##### Pig Game (Rosetta)
« on: 17. October 2018, 17:20:16 »
Last night I made a first draft for Rosetta "Pig" Game:
QB64:
Code: [Select]
`RANDOMIZE TIMERWHILE player < 100 AND AI < 100 'pig from Rosetta  B+ started 2018-10-16    turn = (turn + 1) MOD 2    di = INT(RND * 6) + 1    PRINT: PRINT "Player:"; player; "  AI:"; AI    accum = 0 '<<<<<<<<<<<<<<<<< EDIT  one line instead of two    IF turn THEN 'player        DO            IF di = 1 THEN                INPUT "Player you rolled a 1, your turn is over, press enter..."; wate\$                EXIT DO            ELSE                accum = accum + di                PRINT "Player you rolled a "; di; "your accumulated total is now "; accum                INPUT "Do you want to (r)oll again or (h)old, Enter r or h > "; choice\$                IF choice\$ = "r" THEN                    di = INT(RND * 6) + 1                ELSE                    player = player + accum                    EXIT DO                END IF            END IF        LOOP    ELSE        FOR i = 1 TO 5            IF di = 1 THEN                INPUT "AI rolled a 1, it's turn is over, press enter..."; wate\$                EXIT FOR            ELSE                accum = accum + di                PRINT "AI rolled a "; di; "it's total accumulated now is"; accum                IF i < 4 AND accum + AI < 100 THEN                    PRINT "AI is rolling again."                    INPUT "press enter..."; wate\$                    di = INT(RND * 6) + 1                ELSE                    PRINT "AI is holding with"; accum; "added to it's score."                    INPUT "press enter..."; wate\$                    AI = AI + accum                    EXIT FOR                END IF            END IF        NEXT    END IFWENDPRINT: PRINT "Player: "; player; "  AI: "; AIIF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"END`
I think this might be pared down to around 20 lines?

Ruby can do it in 1, right Tomaaz?

After playing for awhile, begin to understand it's name.

#### Tomaaz

• Sr. Member
• Posts: 340
##### Re: Pig Game (Rosetta)
« Reply #1 on: 17. October 2018, 19:32:15 »
Ruby can do it in 1, right Tomaaz?

Wrong.

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #2 on: 18. October 2018, 17:10:25 »
38 lines aboslutely no :'s used
Code: [Select]
`_TITLE "Pig 1 (Rosetta task)" ' attempt to pare down (no :'s) first version B+ started 2018-10-17RANDOMIZE TIMERWHILE player < 100 AND AI < 100 'pig from Rosetta  B+ started 2018-10-16    turn = (turn + 1) MOD 2    IF turn THEN Who\$ = "Player" ELSE Who\$ = "AI"    PRINT "Player =" + STR\$(player) + "  AI =" + STR\$(AI) + CHR\$(10)    accum = 0    FOR i = 1 TO 100        di = INT(RND * 6) + 1        IF di = 1 THEN            PRINT Who\$ + " rolled a 1, the turn is over, press enter...";            INPUT "", wate\$            EXIT FOR        ELSE            accum = accum + di            PRINT Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + ", the accumulated total is" + STR\$(accum)            IF turn THEN                INPUT "Do you want to (r)oll again or (h)old, Enter r or h"; choice\$                IF choice\$ <> "r" THEN player = player + accum                IF choice\$ <> "r" THEN EXIT FOR            ELSE                IF i < 3 AND accum + AI < 100 THEN                    PRINT "AI is rolling again,";                    INPUT " press enter...", wate\$                ELSE                    PRINT "AI is holding with"; accum; "added to it's score,";                    INPUT " press enter...", wate\$                    AI = AI + accum                    EXIT FOR                END IF            END IF        END IF        PRINT    NEXT    PRINTWENDPRINT "Player =" + STR\$(player) + "  AI =" + STR\$(AI)IF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"`
I think next, attack the 2 prints at the end of blocks OR use Python and eliminate all the end code block lines!

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #3 on: 18. October 2018, 17:28:23 »
That was easy:
Code: [Select]
`_TITLE "Pig 2 (Rosetta task)" ' attempt to pare down (no :'s) first version B+ started 2018-10-17RANDOMIZE TIMERWHILE player < 100 AND AI < 100 'pig from Rosetta  B+ started 2018-10-16    turn = (turn + 1) MOD 2    IF turn THEN Who\$ = "Player" ELSE Who\$ = "AI"    accum = 0    FOR i = 1 TO 100        di = INT(RND * 6) + 1        IF di = 1 THEN            PRINT CHR\$(10) + Who\$ + " rolled a 1, the turn is over, press enter...";            INPUT "", wate\$            EXIT FOR        ELSE            accum = accum + di            PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + ", the accumulated total is" + STR\$(accum)            IF turn THEN                INPUT "Do you want to (r)oll again or (h)old, Enter r or h"; choice\$                IF choice\$ <> "r" THEN player = player + accum                IF choice\$ <> "r" THEN EXIT FOR            ELSE                IF i < 3 AND accum + AI < 100 THEN                    PRINT "AI is rolling again,";                    INPUT " press enter... ", wate\$                ELSE                    AI = AI + accum                    PRINT "AI is holding with"; accum; "added to it's score,";                    INPUT " press enter...", wate\$                    EXIT FOR                END IF            END IF        END IF    NEXT    PRINT CHR\$(10) + "Player =" + STR\$(player) + "  AI =" + STR\$(AI)WENDIF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"`36 lines only 16 more to go. ;-))
EDIT: moved score update line so don't need again at end of game, 35 lines!
« Last Edit: 18. October 2018, 17:55:46 by B+ »

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #4 on: 19. October 2018, 04:01:11 »
32 lines with help from Steve at QB64 who pointed out something I overlooked about 100 times!
Code: [Select]
`_TITLE "Pig 3 (Rosetta task)" ' attempt to pare down (no :'s) first version B+ started 2018-10-17RANDOMIZE TIMERWHILE player < 100 AND AI < 100 'pig from Rosetta  B+ started 2018-10-16    IF Who\$ <> "Player" THEN Who\$ = "Player" ELSE Who\$ = "AI"    accum = 0    FOR i = 1 TO 100        di = INT(RND * 6) + 1        IF di = 1 THEN            PRINT CHR\$(10) + Who\$ + " rolled a 1, the turn is over, press enter...";            INPUT "", wate\$            EXIT FOR        ELSE            accum = accum + di            PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + ", the accumulated total is" + STR\$(accum)            IF Who\$ = "Player" THEN                INPUT "Do you want to (r)oll again or (h)old, Enter r or h"; choice\$                IF choice\$ <> "r" THEN player = player + accum                IF choice\$ <> "r" THEN EXIT FOR            ELSE                IF i < 3 AND accum + AI < 100 THEN                    INPUT "AI is rolling again, press enter... ", wate\$                ELSE                    AI = AI + accum                    INPUT "AI is holding so accumulated amount added it's score, press enter", wate\$                    EXIT FOR                END IF            END IF        END IF    NEXT    PRINT CHR\$(10) + "Player =" + STR\$(player) + "  AI =" + STR\$(AI)WENDIF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"`

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #5 on: 19. October 2018, 05:31:10 »
Ha! Steve found some more tricks. Check this out!
Code: [Select]
`RANDOMIZE TIMER 'pig from Rosetta v4  B+ started 2018-10-16, Steve McNeill finished 2018-10-18WHILE player < 100 AND AI < 100    IF Who\$ <> "Player" THEN Who\$ = "Player" ELSE Who\$ = "AI"    accum = 0    FOR i = 1 TO 100        di = INT(RND * 6) + 1        IF di = 1 THEN accum = 0 ELSE accum = accum + di        IF di = 1 THEN PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + CHR\$(10) ELSE PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + ", the accumulated total is" + STR\$(accum) + CHR\$(10);        IF di = 1 THEN INPUT "The turn is over, press enter...", wate\$        IF di = 1 THEN EXIT FOR        IF Who\$ = "Player" THEN INPUT "Do you want to (r)oll again or (h)old, Enter r or h"; choice\$        IF Who\$ = "Player" AND choice\$ <> "r" THEN player = player + accum        IF Who\$ = "Player" AND choice\$ <> "r" THEN EXIT FOR        IF Who\$ <> "Player" AND (i < 3 AND accum + AI < 100) THEN INPUT "AI is rolling again, press enter... ", wate\$        IF Who\$ <> "Player" AND (i >= 3 OR accum + AI >= 100) THEN AI = AI + accum        IF Who\$ <> "Player" AND (i >= 3 OR accum + AI >= 100) THEN INPUT "AI is holding so accumulated amount added it's score, press enter", wate\$        IF Who\$ <> "Player" AND (i >= 3 OR accum + AI >= 100) THEN EXIT FOR    NEXT    PRINT CHR\$(10) + "Player =" + STR\$(player) + "  AI =" + STR\$(AI)WENDIF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"`
21 lines! No statement is double parked on a line.

Next up, I am going to try new AI strategies, this one is a little too easy to beat.
« Last Edit: 19. October 2018, 05:33:28 by B+ »

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #6 on: 19. October 2018, 16:13:53 »
Whoa! Wait a minute... Steve not done:
Code: [Select]
`_TITLE "Pig 5 (Rosetta task)" ' B+ started 2018-10-17 Steve McNeill finished 2018-10-19WHILE player < 100 AND AI < 100    IF Who\$ <> "   Player" THEN Who\$ = "   Player" ELSE Who\$ = "   AI"    FOR i = 1 TO 100        di = INT(RND * 6) + 1        IF i = 1 AND di = 1 THEN accum = 0 ELSE IF i = 1 THEN accum = di ELSE IF di = 1 THEN accum = 0 ELSE accum = accum + di        IF di = 1 THEN PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + CHR\$(10) ELSE PRINT CHR\$(10) + Who\$ + " rolled a" + RTRIM\$(STR\$(di)) + ", the accumulated total is" + STR\$(accum) + CHR\$(10);        IF di = 1 THEN INPUT " The turn is over, press enter...", wate\$ ELSE RANDOMIZE TIMER        IF di > 1 AND Who\$ = "   Player" THEN INPUT "   Do you want to (r)oll again or (h)old, Enter r or h"; choice\$ ELSE IF di > 1 AND (i < 3 AND accum + AI < 100) THEN INPUT "   AI is rolling again, press enter... ", wate\$        IF di > 1 AND Who\$ = "   Player" AND choice\$ <> "r" THEN player = player + accum        IF di > 1 AND Who\$ <> "   Player" AND (i >= 3 OR accum + AI >= 100) THEN AI = AI + accum        IF di > 1 AND Who\$ <> "   Player" AND (i >= 3 OR accum + AI >= 100) THEN INPUT " AI is holding so accumulated amount is scored, press enter", wate\$        IF (Who\$ <> "   Player" AND (i >= 3 OR accum + AI >= 100)) OR (Who\$ = "   Player" AND choice\$ <> "r") OR di = 1 THEN EXIT FOR    NEXT    PRINT CHR\$(10) + "   Player =" + STR\$(player) + "  AI =" + STR\$(AI)WENDPRINT Who\$; " wins!"`
17 lines! not one has a double-parked statement. Dang, cleared the 20 line hurdle with room to spare!
« Last Edit: 19. October 2018, 16:16:22 by B+ »

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #7 on: 23. October 2018, 21:34:12 »
BPlus variation on Pig, called Boink ( B+ oink ;-))  )

This pig is a prize look how fat it is!

Code: [Select]
`_TITLE "Boink" ' for QB64 B+ started a version of Pig when/where the number of di is declared and rolled' Boink rules:' Start round by flipping coin who goes first' Each player chooses number of dice to roll to start their round' Dice rolled' If 1 di is 1 then no points that turn,' If 2 di are 1 then no points and the score is reset to 0,' If 3 di are 1 then gameover that player lost,' If 4 di are 1 then player wins game automatically,' Otherwise the player gets the total of di added to their score.RANDOMIZE TIMERCONST wholeHog = 7Sooie = 1WHILE Sooie    IF RND < .5 THEN        GOSUB FarmerRound        IF Sooie THEN GOSUB HALRound    ELSE        GOSUB HALRound        IF Sooie THEN GOSUB FarmerRound    END IFWENDENDFarmerRound:COLOR 11Who\$ = "Farmer"COLOR 14cp "Farmer, Enter how many dice to roll."LOCATE , 38: INPUT ; hogHerdCOLOR 11GOSUB RollEmRollEMRETURNHALRound:COLOR 9Who\$ = "HAL"hogHerd = INT(wholeHog * (100 - HAL) / 100 + .5)IF hogHerd = 0 THEN hogHerd = 1GOSUB RollEmRollEMRETURNRollEmRollEM:pigsEye = 0: bacon = 0s\$ = Who\$ + "'s, dice roll is:"FOR pigglet = 1 TO hogHerd    Babe = INT(RND * 6) + 1    IF Babe = 1 THEN pigsEye = pigsEye + 1    bacon = bacon + Babe    s\$ = s\$ + " " + STR\$(Babe)NEXTcp s\$SELECT CASE pigsEye    CASE 0        IF Who\$ = "Farmer" THEN Farmer = Farmer + bacon ELSE HAL = HAL + bacon        cp Who\$ + "," + STR\$(bacon) + " has been added to your score."        IF Farmer >= 100 OR HAL >= 100 THEN Sooie = 0: cp Who\$ + " wins!"    CASE 1        cp Who\$ + " rolled a 1, so your score remains the same."    CASE 2        IF Who\$ = "Farmer" THEN Farmer = 0 ELSE HAL = 0        cp Who\$ + " rolled two 1's, so your score is reset to 0."    CASE 3        cp Who\$ + ", sorry three 1's means you lost the game."        Sooie = 0    CASE ELSE        cp Who\$ + " more than three 1's makes you the winner!"        Sooie = 0END SELECTcp "Press any..."IF Sooie THEN    k\$ = INKEY\$    WHILE LEN(k\$) = 0: k\$ = INKEY\$: _LIMIT 100: WEND    COLOR _RGB(255, 150, 170)    PRINT    cp "Boink Score Board:  Farmer =" + STR\$(Farmer) + "  HAL =" + STR\$(HAL)    PRINTEND IFRETURNSUB cp (s\$)    LOCATE , (80 - LEN(s\$)) / 2: PRINT s\$END SUB`
« Last Edit: 23. October 2018, 21:41:24 by B+ »

#### B+

• Hero Member
• Posts: 802
##### Re: Pig Game (Rosetta)
« Reply #8 on: 27. October 2018, 09:32:07 »
Graphic Boink, my own version of Pig where you throw all the dice at once:

A di showing a 1 is a Pig's Eye:
1 Pig's Eye and get no pointsd for that turn
2 Pig's Eyes and you not only get no points but you loose all you have accumulated so far in game
3 Pig's Eyes and you loose the game.
4 or more Pig's Eyes and you win the game!
Otherwise the di roll is added to your score playing to 100.

Here is a snap: