Z-ZEE (Awfully Similar to Yahtzee)

General games-related topics
User avatar
XavSnap
Posts: 1950
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by XavSnap »

HI,
:lol:

Not a bug, but i forgot to erase a debug line how displayed the S value... the selected score type...

Code: Select all

1502 PRINT AT 0,0;S
The most of wasted time is due to the line jump, locate next line...
The IF function need to be use in case of lines jump to avoid to read unneeded values...
in your case:
5000 LET P=1+(N-1)*6
5050 RETURN

Code: Select all

  5000 IF N=1 THEN LET P=1 >P=(1-1)*6+1=0+1
  5010 IF N=2 THEN LET P=7 >P=(2-1)*6+1=6+1
  5020 IF N=3 THEN LET P=13 >P=(3-1)*6+1=12+1
  5030 IF N=4 THEN LET P=19 >P=(4-1)*6+1=18+1
  5040 IF N=5 THEN LET P=25 >P=(5-1)*6+1=24+1
  5050 RETURN
5 lines and a RETURN send time.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3312
Joined: Wed Jun 18, 2008 2:00 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by Moggy »

Deleting that line just stops the printing at the top left of screen however the scoring is still bugged as I describe in my original post.

Choosing 3 of a kind gives a 0 in 4 of a kind.
Choosing 4 of a kind gives a 0 in full house.
Choosing full house gives a 0 in small straight etc etc.

Also I just get syntax errors for your lines 5000 onwards.

Can you see what I'm getting at?
User avatar
XavSnap
Posts: 1950
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by XavSnap »

Hi,
This is my optimisation suggestion:
All other codes are functional and it was a great job!

Thanks sanello.

Have fun.

Code: Select all

     5 GOSUB 9000
     8 LET ZZ=0
    10 DIM D(5)
    20 DIM K(5)
    25 DIM S(15)
    26 FOR I=1 TO 15
    27 LET S(I)=-1
    28 NEXT I
   980 GOSUB 8000
   981 DIM K(5)
   982 FOR O=1 TO 5
   983 PRINT AT 20,1+(O-1)*6;"¸¸¸¶"
   984 NEXT O
   985 LET C=0
   986 GOSUB 3000
   987 RAND
   989 FOR G=1 TO 3
   990 FOR J=1 TO 3
  1000 FOR I=1 TO 5
  1005 IF K(I)=1 THEN GOTO 1020
  1010 LET D(I)=INT (RND*6)+1
  1020 NEXT I
  1030 GOSUB 2000
  1040 NEXT J
  1041 DIM K(5)
  1044 GOSUB 8000
  1045 IF G=3 THEN GOTO 1290
  1050 PRINT AT 21,0;"CHOOSE KEEPERS THEN PRESS ENTER."
  1060 IF INKEY$="" THEN GOTO 1060

  1070 LET A$=INKEY$
  1080 IF A$=CHR$ 118 THEN GOTO 1200

  1090 IF A$="6" THEN GOTO 5000
  1100 IF A$<"1" OR A$>"5" THEN GOTO 1060
  1110 LET A=CODE A$-28
  1120 IF VAL A$=A THEN LET K(A)=NOT K(A)

  1190 PRINT AT 20,1+(A-1)*6;("¸¸¸¶" AND NOT K(A));("¿¿¿¶" AND K(A))
  1195 GOTO 1060
  1200 PRINT AT 21,0;"LOCK IN THAT CHOICE? Y/N        "
  1210 IF INKEY$<>"" THEN GOTO 1210
  1215 IF INKEY$="" THEN GOTO 1215
  1220 LET A$=INKEY$
  1225 PRINT AT 21,0;"                                "
  1230 IF A$="Y" OR A$=CHR$ 118 THEN GOTO 1286
  1240 IF A$="N" THEN GOTO 1260
  1250 GOTO 1200
  1260 DIM K(5)
  1280 GOSUB 8000
  1282 GOTO 1050
  1286 IF K(1)+K(2)+K(3)+K(4)+K(5)<>5 THEN NEXT G
  1292 IF D(1)=D(2) AND D(2)=D(3) AND D(3)=D(4) AND D(4)=D(5) THEN GOSUB 4000
  1300 IF ZZ=1 THEN LET S(14)=0
  1301 IF ZZ=1 THEN PRINT AT 12,29;0
  1302 IF ZZ=1 THEN GOTO 981
  1305 PRINT AT 21,0;"ARROWS AND ENTER TO CHOOSE SCORE"
  1310 PRINT AT 6,9;"Š"
  
  1314 LET P1=0
  1316 LET P2=0
  1320 IF INKEY$="" THEN GOTO 1320
  1330 LET A$=INKEY$
  1340 IF (A$>"4" AND A$<"9") THEN GOTO 1349
  1342 IF A$=CHR$ 118 THEN GOTO 1500
  1345 GOTO 1320
  1349 LET A=VAL A$
  1350 PRINT AT 6+P1,9+(19 AND P2);":"
  1360 LET P1=P1-(1*(A$="7") AND P1>0)+(1*(A$="6") AND P1<6)
  1370 LET P2=P2-(1*(A$="5") AND P2>0)+(1*(A$="8") AND P2<1)
  1380 PRINT AT 6+P1,9+(19 AND P2);"Š"
  1390 GOTO 1320

   1500 LET S=(P1+1)+P2*7
   1502 PRINT AT P1+6,9+(19 AND P2);">?"
   1506 IF S(S)>-1 THEN PRINT AT P1+6,9+(19 AND P2);"Š";S(S)
   1508 IF S(S)>-1 THEN GOTO 1320
   1510 IF S=14 THEN GOTO 7400

  1520 DIM C(6)
  1525 DIM F(6)
  1530 FOR I=1 TO 6
  1540 FOR N=1 TO 5
  1550 IF D(N)=I THEN LET C(I)=C(I)+1
  1555 IF D(N)=I THEN LET F(I)=F(I)+1
  1560 NEXT N
  1570 NEXT I
  1575 LET X=1
  1576 DIM D(5)
  1580 FOR I=1 TO 6
  1590 FOR N=1 TO 5
  1600 IF C(I)>0 THEN LET D(X)=I
  1602 IF C(I)>0 THEN LET X=X+1
  1605 IF C(I)>0 THEN LET C(I)=C(I)-1
  1620 NEXT N
  1625 NEXT I

  # X=sum of dices ?
  1630 LET X=D(1)+D(2)+D(3)+D(4)+D(5)

  1700 LET V=0
  1800 GOTO 6000+(S*100)
  2000 FOR N=1 TO 5
  2005 LET P=1+(N-1)*6
  2010 IF NOT K(N) THEN GOSUB 2000+(D(N)*100)
  2020 NEXT N
  2030 RETURN 
  2052 IF S(14)=0 THEN GOTO 3065
  2110 PRINT AT 17,P;"   ";AT 18,P;" ¶ ";AT 19,P;"   "
  2150 RETURN 
  2210 PRINT AT 17,P;"¶  ";AT 18,P;"   ";AT 19,P;"  ¶"
  2250 RETURN 
  2310 PRINT AT 17,P;"¶  ";AT 18,P;" ¶ ";AT 19,P;"  ¶"
  2350 RETURN 
  2410 PRINT AT 17,P;"¶ ¶";AT 18,P;"   ";AT 19,P;"¶ ¶"
  2450 RETURN 
  2510 PRINT AT 17,P;"¶ ¶";AT 18,P;" ¶ ";AT 19,P;"¶ ¶"
  2550 RETURN 
  2610 PRINT AT 17,P;"¶ ¶";AT 18,P;"¶ ¶";AT 19,P;"¶ ¶"
  2650 RETURN 
  3000 FOR I=1 TO 6
  3010 IF S(I)=-1 THEN RETURN 
  3020 NEXT I
  3030 FOR I=8 TO 12
  3040 IF S(I)=-1 THEN RETURN 
  3050 NEXT I
  3055 IF S(14)=-1 THEN LET ZZ=1
  3060 IF S(14)=-1 THEN RETURN 
  3065 LET T=0
  3070 FOR I=1 TO 6
  3080 LET T=T+S(I)
  3085 PRINT AT 14,29;T
  3090 NEXT I
  3100 IF T>62 THEN LET S(13)=35
  3110 IF T<62 THEN LET S(13)=0
  3120 PRINT AT 12,10;T
  3130 PRINT AT 13,10;S(13)
  3140 PRINT AT 14,10;S(13)+T
  3150 IF S(15)=-1 THEN LET S(15)=0
  3155 PRINT AT 13,29;S(15)
  3160 LET B=T+(S(15)*100)
  3170 FOR I=7 TO 14
  3180 LET B=B+S(I)
  3190 PRINT AT 14,29;B
  3200 NEXT I
  3210 STOP 
  4000 IF S(14)=0 THEN RETURN 
  4001 GOSUB 9200
  4005 IF S(14)=-1 THEN LET S(14)=50
  4010 LET S(15)=S(15)+1
  4020 IF S(15)>0 THEN PRINT AT 13,29;S(15)*100
  4030 PRINT AT 12,29;S(14)
  4032 IF S(15)>0 THEN LET C=1
  4035 IF S(15)>0 THEN RETURN 
  4040 GOTO 981

  5000 FOR B=1 TO 5
  5010 LET K(B)=NOT K(B)
  5020 PRINT AT 20,1+(B-1)*6;("¸¸¸¶" AND NOT K(B));("¿¿¿¶" AND K(B))
  5030 NEXT B
  5050 GOTO 1060

# ONES:   #1
  6100 FOR I=1 TO 5
  6120 IF D(I)=1 THEN LET V=V+1
  6130 NEXT I
  6140 LET S(S)=V
  6150 PRINT AT 6,9;":";S(S)
  6160 GOTO 981

# TOWS:   #2
  6200 FOR I=1 TO 5
  6220 IF D(I)=2 THEN LET V=V+2
  6230 NEXT I
  6240 LET S(S)=V
  6250 PRINT AT 7,9;":";S(S)
  6260 GOTO 981

# THREES:   #3
  6300 FOR I=1 TO 5
  6320 IF D(I)=3 THEN LET V=V+3
  6330 NEXT I
  6340 LET S(S)=V
  6350 PRINT AT 8,9;":";S(S)
  6360 GOTO 981

# FOURS:   #4
  6400 FOR I=1 TO 5
  6420 IF D(I)=4 THEN LET V=V+4
  6430 NEXT I
  6440 LET S(S)=V
  6450 PRINT AT 9,9;":";S(S)
  6460 GOTO 981

# FIVES:   #5
  6500 FOR I=1 TO 5
  6520 IF D(I)=5 THEN LET V=V+5
  6530 NEXT I
  6540 LET S(S)=V
  6550 PRINT AT 10,9;":";S(S)
  6560 GOTO 981

# SIXES:   #6
  6600 FOR I=1 TO 5
  6620 IF D(I)=6 THEN LET V=V+6
  6630 NEXT I
  6640 LET S(S)=V
  6650 PRINT AT 11,9;":";S(S)
  6660 GOTO 981

# SUM:   #7
  # X=sum...
  6700 LET S(7)=D(1)+D(2)+D(3)+D(4)+D(5)
  6710 PRINT AT 12,9;":";S(7)
  6720 GOTO 981

# 3 OF A KIND:   #8
  6800 IF D(1)=D(2) AND D(2)=D(3) THEN LET V=3
  6830 IF D(2)=D(3) AND D(3)=D(4) THEN LET V=3
  6840 IF D(3)=D(4) AND D(4)=D(5) THEN LET V=3

    # X=sum of dices... not 3x current dice value.
  6860 IF V=3 THEN LET S(S)=X
  6870 IF V<>3 THEN LET S(S)=0
  6880 PRINT AT 6,28;":";S(S)
  6890 GOTO 981

# 4 OF A KIND:   #9
  6900 IF D(1)=D(2) AND D(2)=D(3) AND D(3)=D(4) THEN LET V=4
  6920 IF D(2)=D(3) AND D(3)=D(4) AND D(4)=D(5) THEN LET V=4
  

    # X=sum of dices... not 4x current dice value.
  6960 IF V=4 THEN LET S(S)=X
  6970 IF V<>4 THEN LET S(S)=0
  6980 PRINT AT 7,28;":";S(S)
  6990 GOTO 981

# FULL HOUSE:   #10
  7000 IF D(1)=D(2) AND D(2)=D(3) AND D(4)=D(5) THEN LET V=1
  7020 IF D(1)=D(2) AND D(3)=D(4) AND D(4)=D(5) THEN LET V=1
  7060 IF V=1 THEN LET S(S)=25
  7070 IF V<>1 THEN LET S(S)=0
  7080 PRINT AT 8,28;":";S(S)
  7090 GOTO 981

# SMALL STRAIGHT:   #11
  7100 IF C=1 THEN LET V=1
  7110 IF F(1)>0 AND F(2)>0 AND F(3)>0 AND F(4)>0 THEN LET V=1
  7120 IF F(2)>0 AND F(3)>0 AND F(4)>0 AND F(5)>0 THEN LET V=1
  7130 IF F(3)>0 AND F(4)>0 AND F(5)>0 AND F(6)>0 THEN LET V=1
  7160 IF V=1 THEN LET S(S)=30
  7170 IF V<>1 THEN LET S(S)=0
  7180 PRINT AT 9,28;":";S(S)
  7190 GOTO 981

# LARGE STRAIGHT:   #12
  7200 IF C=1 THEN LET V=1
  7210 IF D(2)=D(1)+1 AND D(3)=D(2)+1 AND D(4)=D(3)+1 AND D(5)=D(4)+1 THEN LET V=1
  7260 IF V=1 THEN LET S(S)=40
  7270 IF V<>1 THEN LET S(S)=0
  7280 PRINT AT 10,28;":";S(S)
  7290 GOTO 981

# CHANCE:   #13
  7300 LET S(S)=X
  7310 PRINT AT 11,28;":";S(S)
  7320 GOTO 981

# Z-ZEE:   #14
  7400 IF S(14)>-1 THEN GOTO 1320
  7405 LET S(14)=0
  7410 PRINT AT 12,28;":";S(14)
  7420 GOTO 981

#  BONUS Z-ZEE: #15

  8000 FOR N=1 TO 5
  8005 LET P=1+(N-1)*6
  8010 PRINT AT 20,P;("¸¸¸¶" AND NOT K(N));("¿¿¿¶" AND K(N))
  8020 PRINT AT 16,P-1;"¼¸¸¸º";AT 17,P-1;"º";AT 17,P+3;"º";AT 18,P-1;"º";AT 18,P+3;"º";AT 19,P-1;"º";AT 19,P+3;"º"
  8060 NEXT N
  8070 RETURN 

  9000 PRINT AT 6,5;"ONES:";AT 7,5;"TWOS:";AT 8,3;"THREES:";AT 9,4;"FOURS:";AT 10,4;"FIVES:";AT 11,4;"SIXES:";AT 12,6;"SUM:";AT 13,0;"BONUS>=63:";AT 14,0;"GRAND SUM:";AT 6,17;"3 OF A KIND:";AT 7,17;"4 OF A KIND:";AT 8,18;"FULL HOUSE:";AT 9,14;"SMALL STRAIGHT:";AT 10,14;"LARGE STRAIGHT:";AT 11,22;"CHANCE:";AT 12,23;"Z-ZEE:";AT 13,17;"BONUS Z-ZEE:";AT 14,17;"TOTAL SCORE:";AT 20,0;"1     2     3     4     5     6";AT 19,30;"l";AT 18,30;"l";AT 17,30;"a"
  9200 FOR I=0 TO 4
  9210 PRINT AT 0,I;"«"
  9220 PRINT AT 4,I;"«"
  9230 PRINT AT 0,I+7;"«"
  9240 PRINT AT 4,I+7;"«"
  9250 PRINT AT 0,I+13;"«"
  9260 PRINT AT 2,I+13;"«"
  9270 PRINT AT 4,I+13;"«"
  9280 PRINT AT 0,I+19;"«"
  9290 PRINT AT 2,I+19;"«"
  9300 PRINT AT 4,I+19;"«"
  9310 PRINT AT I,13;"«"
  9320 PRINT AT I,19;"«"
  9330 PRINT AT I,4-I;"«"
  9340 PRINT AT I,11-I;"«"
  9350 NEXT I
  9360 PRINT AT 2,5;"««"
  9390 NEXT I
  9400 FOR I=0 TO 4
  9410 PRINT AT 0,I;"½"
  9420 PRINT AT 4,I;"½"
  9430 PRINT AT 0,I+7;"½"
  9440 PRINT AT 4,I+7;"½"
  9450 PRINT AT 0,I+13;"½"
  9460 PRINT AT 2,I+13;"½"
  9470 PRINT AT 4,I+13;"½"
  9480 PRINT AT 0,I+19;"½"
  9490 PRINT AT 2,I+19;"½"
  9500 PRINT AT 4,I+19;"½"
  9510 PRINT AT I,13;"½"
  9520 PRINT AT I,19;"½"
  9530 PRINT AT I,4-I;"½"
  9540 PRINT AT I,11-I;"½"
  9550 NEXT I
  9560 PRINT AT 2,5;"½½"
  9570 PRINT AT 1,24;"CODE BY:"
  9580 PRINT AT 3,24;"S.ANELLO"
  9699 RETURN 
  9900 SAVE "Z-ZEE"
  9999 RUN

[edit] updated in next messages.
Last edited by XavSnap on Fri Jul 29, 2022 6:17 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3312
Joined: Wed Jun 18, 2008 2:00 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by Moggy »

I have taken your optimised version Xav and added a FAST and SLOW line for the scoring and I have to say that when used with the Big Bang ROM on real kit or a speeded up emulator this thing now flies for a BASIC program! but I have to say the final scoring doesn't seem to add up correctly at all I only got 62 but was given a bonus for a >= 63 score and the final score totals are completely wrong but we're getting there :lol:

Great work both of you.
Attachments
zeopt.P
(9.21 KiB) Downloaded 48 times
User avatar
sanello
Posts: 100
Joined: Sat Jul 23, 2022 9:26 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by sanello »

@Moggy

I plan on looking at all this great stuff this weekend when I have time. Before I deep dive, is the scoring wrong on my second post as well? The first one I know I messed up small straight and fixed that.
-sanello
User avatar
sanello
Posts: 100
Joined: Sat Jul 23, 2022 9:26 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by sanello »

I found the problem with getting 35 bonus with only 62. It's at line 3110 but I'll fix it like this.

3100 LET S(13)=0
3110 IF T>62 THEN LET S(13)=35

Less characters same correct result.
-sanello
Moggy
Posts: 3312
Joined: Wed Jun 18, 2008 2:00 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by Moggy »

The "improved" versions by XavSnap seem to be the ones with incorrect scoring even if they play faster whereas your versions seem ok, although I did once get a -1 score for not getting a >= 63 total on the upper sheet when it should have been a zero.

I will play around some more and use the changes you made and report back. This is worth pursuing as we don't often get large BASIC programs and Yahtzee is non existent apart from one other version which I think is written in Dutch.
Moggy
Posts: 3312
Joined: Wed Jun 18, 2008 2:00 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by Moggy »

@Sanello.

This is your version with the new lines added and after half a dozen games the scoring is now perfect (I hope!). :D

I have added the line 987 RAND.
Attachments
TESTZEE.P
(10.13 KiB) Downloaded 57 times
User avatar
XavSnap
Posts: 1950
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by XavSnap »

Hi,
To keep memory, avoid repeating BASIC routines...
The file will be reduced to 7960 bytes.

Code: Select all

# ONES:   #1
  6100 FOR I=1 TO 5
  6120 IF D(I)=1 THEN LET V=V+1
  6130 NEXT I
  6140 LET S(S)=V
  6150 PRINT AT 6,9;":";S(S)
  6160 GOTO 981

# TOWS:   #2
  6200 FOR I=1 TO 5
  6220 IF D(I)=2 THEN LET V=V+2
  6230 NEXT I
  6240 LET S(S)=V
  6250 PRINT AT 7,9;":";S(S)
  6260 GOTO 981

# THREES:   #3
  6300 FOR I=1 TO 5
  6320 IF D(I)=3 THEN LET V=V+3
  6330 NEXT I
  6340 LET S(S)=V
  6350 PRINT AT 8,9;":";S(S)
  6360 GOTO 981

# FOURS:   #4
  6400 FOR I=1 TO 5
  6420 IF D(I)=4 THEN LET V=V+4
  6430 NEXT I
  6440 LET S(S)=V
  6450 PRINT AT 9,9;":";S(S)
  6460 GOTO 981

# FIVES:   #5
  6500 FOR I=1 TO 5
  6520 IF D(I)=5 THEN LET V=V+5
  6530 NEXT I
  6540 LET S(S)=V
  6550 PRINT AT 10,9;":";S(S)
  6560 GOTO 981

# SIXES:   #6
  6600 FOR I=1 TO 5
  6620 IF D(I)=6 THEN LET V=V+6
  6630 NEXT I
  6640 LET S(S)=V
  6650 PRINT AT 11,9;":";S(S)
  6660 GOTO 981
equal

Code: Select all

(...)
  1800 IF S>6 THEN GOTO 6000+(S*100)
  1810 GOTO 6000
(...)
# ONES:   #1
# TOWS:   #2
# THREES: #3
# FOURS:  #4
# FIVES:  #5
# SIXES:  #6
6000 DIM R(6)
6010 FOR A=1 TO 5
6020 LET R(D(A))= R(D(A))+1
6030 NEXT A
6040 LET S(S)=R(S)*S
6050 PRINT AT 5+S,9;":";S(S)
6060 GOTO 981
Don't know if advice is useful... We had to rewrite all the program, and sanello won't retrieve his own stuff.

Crayon said : "Don't rewrite my game!"

But, users usually take standard BASIC listing (TRS80,Spectrum, CPC) and type ins the code as is.
Standard BASIC don't suit to the slow ZX81'S BASiC.

We had to translate it and keep in mind the ZX81's limitations.

It's the main (big!) challenge on this computer... never use FAST mode ("The Dead Mode"), it's the easy way to mask a bad code.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3312
Joined: Wed Jun 18, 2008 2:00 pm

Re: Z-ZEE (Awfully Similar to Yahtzee)

Post by Moggy »

@XavSnap

Yes your code id fast and compact but the scoring is all wrong, not sure why you can't see that. :?


Will try your updated routines.
Post Reply