Author Topic: Pig Game (Rosetta)  (Read 4129 times)

B+

  • Guest
Pig Game (Rosetta)
« on: October 17, 2018, 03:20:16 PM »
Last night I made a first draft for Rosetta "Pig" Game:
QB64:
Code: [Select]
RANDOMIZE TIMER
WHILE 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 IF
WEND
PRINT: PRINT "Player: "; player; "  AI: "; AI
IF 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?  ;D

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

Tomaaz

  • Guest
Re: Pig Game (Rosetta)
« Reply #1 on: October 17, 2018, 05:32:15 PM »
Ruby can do it in 1, right Tomaaz?  ;D

Wrong.  ;D

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #2 on: October 18, 2018, 03:10:25 PM »
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-17
RANDOMIZE TIMER
WHILE 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
    PRINT
WEND
PRINT "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! ;D

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #3 on: October 18, 2018, 03:28:23 PM »
That was easy:
Code: [Select]
_TITLE "Pig 2 (Rosetta task)" ' attempt to pare down (no :'s) first version B+ started 2018-10-17
RANDOMIZE TIMER
WHILE 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)
WEND
IF 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: October 18, 2018, 03:55:46 PM by B+ »

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #4 on: October 19, 2018, 02:01:11 AM »
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-17
RANDOMIZE TIMER
WHILE 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)
WEND
IF player > AI THEN PRINT "Player wins!" ELSE PRINT "AI wins!"

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #5 on: October 19, 2018, 03:31:10 AM »
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-18
WHILE 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)
WEND
IF 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: October 19, 2018, 03:33:28 AM by B+ »

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #6 on: October 19, 2018, 02:13:53 PM »
Whoa! Wait a minute... Steve not done:
Code: [Select]
_TITLE "Pig 5 (Rosetta task)" ' B+ started 2018-10-17 Steve McNeill finished 2018-10-19
WHILE 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)
WEND
PRINT Who$; " wins!"

17 lines! not one has a double-parked statement. Dang, cleared the 20 line hurdle with room to spare!
« Last Edit: October 19, 2018, 02:16:22 PM by B+ »

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #7 on: October 23, 2018, 07:34:12 PM »
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 TIMER
CONST wholeHog = 7
Sooie = 1
WHILE Sooie
    IF RND < .5 THEN
        GOSUB FarmerRound
        IF Sooie THEN GOSUB HALRound
    ELSE
        GOSUB HALRound
        IF Sooie THEN GOSUB FarmerRound
    END IF
WEND
END

FarmerRound:
COLOR 11
Who$ = "Farmer"
COLOR 14
cp "Farmer, Enter how many dice to roll."
LOCATE , 38: INPUT ; hogHerd
COLOR 11
GOSUB RollEmRollEM
RETURN

HALRound:
COLOR 9
Who$ = "HAL"
hogHerd = INT(wholeHog * (100 - HAL) / 100 + .5)
IF hogHerd = 0 THEN hogHerd = 1
GOSUB RollEmRollEM
RETURN

RollEmRollEM:
pigsEye = 0: bacon = 0
s$ = 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)
NEXT
cp 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 = 0
END SELECT
cp "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)
    PRINT
END IF
RETURN

SUB cp (s$)
    LOCATE , (80 - LEN(s$)) / 2: PRINT s$
END SUB

« Last Edit: October 23, 2018, 07:41:24 PM by B+ »

B+

  • Guest
Re: Pig Game (Rosetta)
« Reply #8 on: October 27, 2018, 07:32:07 AM »
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: