|
Post by bluatigro on Oct 14, 2019 11:31:45 GMT
first step : creating stones + shuflining stones + filling hand's
error : my shufle does not work
'' bluatigro 14 okt 2019 '' rumicub dim stone( 51 ) , c( 51 ) , h( 51 ) , table$( 40 , 14 ) global ctel , htel
'' init for i = 0 to 51 stone( i ) = value( i ) + color( i ) * 16 next i '' shuffle for i = 0 to 51 dice = irange( 0 , 51 ) h = stone( dice ) stone( dice ) = ( i ) stone( i ) = h next i '' init hand's for i = 0 to 12 c( i ) = ( i ) h( i ) = ( i + 12 ) next i '' show hand's for i = 0 to 12 print stone.str$( c( i ) ) ; " | " ; stone.str$( h( i ) ) next i input "[ push return . ]" ; in$
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) value = i mod 14 end function function color( i ) color = int( i / 14 ) end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ), 2 ) ; " " ; color( i ) end function
|
|
|
Post by bluatigro on Oct 14, 2019 11:47:26 GMT
update : stone init is now good
'' bluatigro 14 okt 2019 '' rumicub dim stone( 51 ) , c( 51 ) , h( 51 ) , table$( 40 , 14 ) global ctel , htel
'' init for i = 0 to 51 stone( i ) = value( i ) + color( i ) * 16 next i '' shuffle for i = 0 to 51 dice = irange( 0 , 51 ) h = stone( i ) stone( i ) = stone( dice ) stone( dice ) = h next i '' init hand's for i = 0 to 13 c( i ) = ( i ) h( i ) = ( i + 14 ) next i '' show hand's for i = 0 to 13 print stone.str$( c( i ) ) ; " | " ; stone.str$( h( i ) ) next i input "[ push return . ]" ; in$
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) value = i mod 14 end function function color( i ) color = int( i / 14 ) end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ) , 2 ) ; " " ; color( i ) end function
|
|
|
Post by B+ on Oct 15, 2019 18:34:43 GMT
|
|
|
Post by Rod on Oct 16, 2019 19:30:35 GMT
Yep, color and indeed sprites would be great. Player rules, runs,sets etc are doable but computer AI gameplay could be a challenge?
|
|
|
Post by bluatigro on Oct 17, 2019 16:26:33 GMT
update : first step AI : first move try
version 1.2
not fully tested so the print's wil stay for a while
'' bluatigro 14 okt 2019 '' rumicub global stmax stmax = 13 * 8 + 1 dim stone( stmax ) , c( stmax ) , h( stmax ) , table( stmax ) dim q( 13 ) , set( 3 ) , w( 3 ) global ctel , htel , sttel
'' init for i = 0 to stmax - 2 stone( i ) = value( i ) + 13 * color( i ) next i '' shuffle for i = 0 to stmax dice = irange( 0 , stmax ) h = stone( dice ) stone( dice ) = stone( i ) stone( i ) = h next i '' init hand's for i = 0 to 12 c( i ) = stone( i ) h( i ) = stone( i + 13 ) next i '' show hand's for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 1 : random hand's : push return . ]" ; in$ '' AI : first move '' looking for 'streets sort c() , 0 , 12 sort h() , 0 , 12 '' looking for double sttel = 26 for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 2 : sorted hand's : push return . ]" ; in$ '' removing double for i = 0 to 11 if c( i ) = c( i + 1 ) then c( i ) = stone( sttel ) sttel = sttel + 1 end if next i for i = 0 to 11 if h( i ) = h( i + 1 ) then h( i ) = stone( sttel ) sttel = sttel + 1 end if next i sort c() , 0 , 12 sort h() , 0 , 12 for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 3 : double removed : push return . ]" ; in$ call AI 1 print "[ game over ]" end sub AI firstmove streetfl = 0 setfl = 0 if firstmove then i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) _ + value( c( i + 2 ) ) >= 30 ) _ and i < 11 i = i + 1 wend if i = 11 then input "[ 4 : first move AI : no street fount by AI . : push return . ]" ; in$ else for q = i to i + 2 print stone.str$( c( q ) ) next q input "[ 4 : first move AI : street fount by AI . : push return . ]" ; in$ streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 for i = 0 to 13 if q( i ) >= 3 then print "set " ; i ; " of " ; q( i ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i if r >= 10 then tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i if r >= 8 then tel = 0 for i = 8 to 13 if q( i ) = 4 then w( tel ) = i tel = tel + 1 end if next i end if for i = 0 to tel print stone.str$( c( w( i ) ) ) next i input "[ 5 : first move AI : above set fount : push return . ] " ; in$ else input "[ 5 : first move AI : no set fount : push return . ]" ; in$ end if end if input "[ 6 : this was first move try from AI : push return . ]" ; in$ else end if if not( streetfl ) and not( setfl ) then input "[ no set or street fount : AI buy's stone : push return ." ; in$ else end if input "[ end AI ]" ; in$ end sub print "[ game over ]"
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) uit = ( i mod 13 ) + 1 if i >= 13 * 8 then uit = 0 value = uit end function function color( i ) uit = ( int( i / 13 ) and 3 ) + 1 if i >= 13 * 8 then uit = 0 color = uit end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ) , 2 ) ; color( i ) end function
|
|
|
Post by bluatigro on Oct 17, 2019 16:57:11 GMT
update : 2e step on AI : 2e move start .
i have no idea on how to do the human move's
'' bluatigro 14 okt 2019 '' rumicub global stmax stmax = 13 * 8 + 1 dim stone( stmax ) , c( stmax ) , h( stmax ) , table( stmax ) dim q( 13 ) , set( 3 ) , w( 3 ) global ctel , htel , sttel '' init for i = 0 to stmax - 2 stone( i ) = value( i ) + 13 * color( i ) next i '' shuffle for i = 0 to stmax dice = irange( 0 , stmax ) h = stone( dice ) stone( dice ) = stone( i ) stone( i ) = h next i '' init hand's for i = 0 to 12 c( i ) = stone( i ) h( i ) = stone( i + 13 ) next i '' show hand's for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 1 : random hand's : push return . ]" ; in$ '' looking for double ctel = 12 htel = 12 sttel = 26 for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 2 : sorted hand's : push return . ]" ; in$ '' removing double for i = 0 to 11 if c( i ) = c( i + 1 ) then c( i ) = stone( sttel ) sttel = sttel + 1 end if next i for i = 0 to 11 if h( i ) = h( i + 1 ) then h( i ) = stone( sttel ) sttel = sttel + 1 end if next i '' test hand's sort c() , 0 , 12 sort h() , 0 , 12 for i = 0 to 12 print stone.str$( c( i ) ) , stone.str$( h( i ) ) next i input "[ 3 : double removed : push return . ]" ; in$ call AI 1 input "[ test AI firstmove : push return . ]" ; in$ call AI 0 input "[ test AI move : push return . ]" ; in$ print "[ game over : push return . ]" ; in$ end sub AI firstmove streetfl = 0 setfl = 0 sort c() , 0 , ctel if firstmove then i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) _ + value( c( i + 2 ) ) >= 30 ) _ and i < 11 i = i + 1 wend if i = 11 then input "[ 4 : first move AI : no street fount by AI . : push return . ]" ; in$ else for q = i to i + 2 print stone.str$( c( q ) ) next q input "[ 4 : first move AI : street fount by AI . : push return . ]" ; in$ streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 for i = 0 to 13 if q( i ) >= 3 then print "set " ; i ; " of " ; q( i ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i if r >= 10 then tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i if r >= 8 then tel = 0 for i = 8 to 13 if q( i ) = 4 then w( tel ) = i tel = tel + 1 end if next i end if for i = 0 to tel print stone.str$( c( w( i ) ) ) next i input "[ 5 : first move AI : above set fount : push return . ] " ; in$ else input "[ 5 : first move AI : no set fount : push return . ]" ; in$ end if end if input "[ 6 : this was first move try from AI : push return . ]" ; in$ else i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) ) _ and i < 11 i = i + 1 wend if i = 11 then input "[ move AI : no street fount by AI . : push return . ]" ; in$ else for q = i to i + 2 print stone.str$( c( q ) ) next q input "[ move AI : street fount by AI . : push return . ]" ; in$ streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 for i = 0 to 13 if q( i ) >= 3 then print "set " ; i ; " of " ; q( i ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i end if end if if not( streetfl ) and not( setfl ) then input "[ no set or street fount : AI buy's stone : push return ." ; in$ else end if input "[ end AI ]" ; in$ end sub print "[ game over ]"
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) uit = ( i mod 13 ) + 1 if i >= 13 * 8 then uit = 0 value = uit end function function color( i ) uit = ( int( i / 13 ) and 3 ) + 1 if i >= 13 * 8 then uit = 0 color = uit end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ) , 2 ) ; color( i ) end function
|
|
|
Post by B+ on Oct 17, 2019 19:37:18 GMT
I was thinking you don't have to do the human moves but you do need to check that any move, human or AI, is legal. To that end, I was thinking you could layout a table such that there would be 4 set places where you could put any tile, one of 2 straights (runs) or 1 of 2 color groups. The table layout would go like this: 2 X 4 colors X 13 runs of 1 to 13 for straights, number sequences of 1 color = 8 X 13 = 104 places PLUS 2 sets X 13 numbers X 4 colors = another 104 places for color groups. Thus, tiles can only be played in a few set places on the table. To eliminate the ambiguity of the Joker, you could have an additional rule that the tile must be exactly the same as where the Joker sits on the table to replace the Joker with a tile of yours and then use the Joker somewhere else (which must sit only by your tiles you add to the play on your turn. That was a rule I learned watching U tube tuts.) So if human intends to use Joker on table, he must click that first and put it where he intends to add his tiles. (The AI would then pull the tile from humans rack that fits there or say no tile of human's rack matches the spot.) Human then adds his tiles next to Joker, then whatever else he might do from his rack. The human clicks his tiles out to the board and then clicks tiles on board to rearrange if need be, the human must leave at least 3 tiles remaining side by side in every spot there is tiles. The human indicates when finished. Then the AI checks 3 tiles side by side in every spot that has tiles. The complete move is erased if illegal or unfinished and the human is handed a tile. Piece of cake! ;-)) Update: Here is the Table layout I had in mind, player's rack with 14 tiles is on the right and contains a Joker tile Oh I should mention the first board on the left is for laying out Straights, sequences of numbers of the same color, so they go up and down, vertically, the other middle boards are for like number and different color Groups, there the tiles should be laid horizontally, across.
|
|
|
Post by bluatigro on Oct 18, 2019 5:11:23 GMT
update : first try at gui
error : menu syntacks error
'' bluatigro 14 okt 2019 '' rumicub global stmax , screenx stmax = 13 * 8 + 1 dim stone( stmax ) , c( stmax ) , h( stmax ) , table( 52 , 13 ) , tmax( 52 ) dim q( 13 ) , set( 3 ) , w( 3 ) global ctel , htel , sttel '' init for i = 0 to stmax - 2 stone( i ) = value( i ) + 13 * color( i ) next i stone( 13 * 4 ) = 250 stone( 13 * 4 + 1 ) = 250 WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy winx = WindowWidth winy = WindowHeight menu #m , "game" _ , "new" , [new.game] _ , | , "exit" , [quit.menu] menu #m , "move" _ , "buy stone" , [buy.stone] _ , | , "left add" , [left.add] _ , "right add" , [right.add] _ , "split street" , [split.street] _ , "place street" , [place street] _ , "place set" , [place.set] _ , | , "buy stone" , "[buy stone] button #m.left , "<" , DR , [btn.left] , 100 , 50 , 50 , 50 button #m.right , ">" , DR , [btn.right] , 50 , 50 , 50 , 50 open "rummikub 2.0" for graphics as #m #m "trapclose [quit]" #m "font 20 bold" call draw.table wait [new.game] call new.game wait sub new.game '' shuffle for i = 0 to stmax dice = irange( 0 , stmax ) h = stone( dice ) stone( dice ) = stone( i ) stone( i ) = h for j = 0 to 13 table( i , j ) = 0 next j tmax( i ) = 0 next i '' init hand's for i = 0 to 12 c( i ) = stone( i ) h( i ) = stone( i + 13 ) next i ctel = 12 htel = 12 sttel = 24 '' looking for and removing double for i = 0 to 11 if c( i ) = c( i + 1 ) then c( i ) = stone( sttel ) sttel = sttel + 1 end if next i for i = 0 to 11 if h( i ) = h( i + 1 ) then h( i ) = stone( sttel ) sttel = sttel + 1 end if next i end sub [quit] close #m end [quit.menu] close #m end [buy.stone] notice "buy stone ." wait [left.add] notice "left add ." wait [right.add] notice "right add ." wait [split.street] notice "split street ." wait [place.street] notice "place street ." wait [place.set] notice "place set ." wait [btn.left] if screenx > 0 then screenx = screenx - 1 call draw.table wait [btn.right] if screeny < 52 - winx / 80 then screenx = screenx + 1 call draw.table wait sub draw.table #m "fill white" #m "goto 0 " ; winy - 50 #m "backcolor pink" #m "down" #m "boxfilled " ; winx ; " " ; winy #m "up" for i = 0 to winx / 80 #m "goto " ; ( i - screenx ) * winx / 80 ; " 20" q$ = mid$( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM" , i + 1 , 1 ) #m "down" #m "\" ; q$ #m "up" next i for i = 0 to 40 for j = 0 to 13 call draw.stone i , j , table( i , j ) next j next i end sub sub draw.stone x , y , i if table( x , y ) then #m "color black" select case color( i ) case 0 #m "backcolor black" #m "color white" case 1 #m "backcolor yellow" case 2 #m "backcolor green" case 3 #m "backcolor blue" case 4 #m "backcolor red" end select #m "goto " ; ( x - screenx ) * winx / 80 ; " " ; 100 + y * 30 #m "down" #m "\" ; stone.str$( table( x, y ) ) #m "up" end if end sub sub AI firstmove streetfl = 0 setfl = 0 sort c() , 0 , ctel if firstmove then i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) _ + value( c( i + 2 ) ) >= 30 ) _ and i < 11 i = i + 1 wend if i = 11 then input "[ 4 : first move AI : no street fount by AI . : push return . ]" ; in$ else for q = i to i + 2 print stone.str$( c( q ) ) next q input "[ 4 : first move AI : street fount by AI . : push return . ]" ; in$ streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 for i = 0 to 13 if q( i ) >= 3 then print "set " ; i ; " of " ; q( i ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i if r >= 10 then tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i if r >= 8 then tel = 0 for i = 8 to 13 if q( i ) = 4 then w( tel ) = i tel = tel + 1 end if next i end if for i = 0 to tel print stone.str$( c( w( i ) ) ) next i input "[ 5 : first move AI : above set fount : push return . ] " ; in$ else input "[ 5 : first move AI : no set fount : push return . ]" ; in$ end if end if input "[ 6 : this was first move try from AI : push return . ]" ; in$ else i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) ) _ and i < 11 i = i + 1 wend if i = 11 then input "[ move AI : no street fount by AI . : push return . ]" ; in$ else for q = i to i + 2 print stone.str$( c( q ) ) next q input "[ move AI : street fount by AI . : push return . ]" ; in$ streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 for i = 0 to 13 if q( i ) >= 3 then print "set " ; i ; " of " ; q( i ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i end if end if if not( streetfl ) and not( setfl ) then input "[ no set or street fount : AI buy's stone : push return ." ; in$ else end if input "[ end AI ]" ; in$ end sub print "[ game over ]"
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) uit = ( i mod 13 ) + 1 if i >= 13 * 8 then uit = 0 value = uit end function function color( i ) uit = ( int( i / 13 ) and 3 ) + 1 if i = 250 then uit = 25 color = uit end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ) , 2 ) ; color( i ) end function
|
|
|
Post by bluatigro on Oct 18, 2019 7:43:31 GMT
update : human hand in image AI gui style
'' bluatigro 14 okt 2019 '' rumicub global stmax , screenx stmax = 13 * 8 + 1 dim stone( stmax ) , c( stmax ) , h( stmax ) , table( 52 , 20 ) , tmax( 52 ) dim q( 13 ) , set( 3 ) , w( 3 ) global ctel , htel , sttel '' init for i = 0 to stmax - 2 stone( i ) = value( i ) + 13 * color( i ) next i stone( 13 * 4 ) = 250 stone( 13 * 4 + 1 ) = 250 WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy winx = WindowWidth winy = WindowHeight menu #m , "game" _ , "new" , [new.game] _ , | , "exit" , [quit.menu] ''menu #m , "move" _ '' , "buy stone" , [buy.stone] _ '' , | , "left add" , [left.add] _ '' , "right add" , [right.add] _ '' , "split street" , [split.street] _ '' , "place street" , [place street] _ '' , "place set" , [place.set] _ '' , | , "buy stone" , "[buy stone] button #m.left , "<" , [btn.left] , LR , 100 , 50 , 50 , 50 button #m.right , ">" , [btn.right] , LR , 50 , 50 , 50 , 50 nomainwin open "rummikub 2.0" for graphics as #m #m "trapclose [quit]" #m "font 20 bold" call new.game call draw.table '' call AI 1 '' call AI 0 wait [new.game] call new.game wait sub new.game '' shuffle for i = 0 to stmax dice = irange( 0 , stmax ) h = stone( dice ) stone( dice ) = stone( i ) stone( i ) = h next i for i = 0 to 52 for j = 0 to 13 table( i , j ) = 0 next j tmax( i ) = 0 next i '' init hand's for i = 0 to 12 c( i ) = stone( i ) h( i ) = stone( i + 13 ) next i ctel = 12 htel = 12 sttel = 24 '' looking for and removing double for i = 0 to 11 if c( i ) = c( i + 1 ) then c( i ) = stone( sttel ) sttel = sttel + 1 end if next i for i = 0 to 11 if h( i ) = h( i + 1 ) then h( i ) = stone( sttel ) sttel = sttel + 1 end if next i end sub [quit] close #m end [quit.menu] close #m end [buy.stone] notice "buy stone ." wait [left.add] notice "left add ." wait [right.add] notice "right add ." wait [split.street] notice "split street ." wait [place.street] notice "place street ." wait [place.set] notice "place set ." wait [btn.left] if screenx > 0 then screenx = screenx - 1 call draw.table wait [btn.right] if screeny < 52 - winx / 80 then screenx = screenx + 1 call draw.table wait sub draw.table #m "fill white" #m "backcolor white" for i = 0 to 35 #m "goto " ; ( i - screenx ) * 80 ; " 20" q$ = mid$( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJ" , i + 1 , 1 ) #m "down" #m "\" ; q$ #m "up" next i for i = 0 to 52 for j = 0 to 13 call draw.stone i , j , table( i , j ) , 0 next j next i sort h() , 0 , htel for i = 0 to htel table( i , 10 ) = 1 call draw.stone i , 15 , h( i ) , 2 '' table( i , 2 ) = 1 '' call draw.stone i , 2 , c( i ) , 1 next i end sub sub draw.stone x , y , i , q #m "color black" select case color( i ) case 0 #m "backcolor black" #m "color white" case 1 #m "backcolor yellow" case 2 #m "backcolor green" case 3 #m "backcolor blue" #m "color white" case 4 #m "backcolor red" end select #m "goto " ; ( x - screenx ) * 80 ; " " ; 30 + y * 30 #m "down" if q = 0 and table( x , y ) then #m "\" ; stone.str$( table( x , y ) ) if q = 1 then #m "\" ; stone.str$( c( x ) ) if q = 2 then #m "\" ; stone.str$( h( x ) ) #m "up" end sub sub AI firstmove streetfl = 0 setfl = 0 sort c() , 0 , ctel if firstmove then i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) _ + value( c( i + 2 ) ) >= 30 ) _ and i < 11 i = i + 1 wend if i = 11 then notice "AI" + chr$( 13 ) _ + "first move AI :" + chr$( 13 ) _ + "no street fount by AI ." else q$ = "" for q = i to i + 2 q$ = q$ + stone.str$( c( q ) ) + " " next q notice "AI" + chr$( 13 ) _ + "first move AI :" + chr$( 13 ) _ + q$ + chr$( 13 ) _ + "street fount by AI ." streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 q$ = "" for i = 0 to 13 if q( i ) >= 3 then q$ = q$ + "set " + str$( i ) ; " of " ; str$( q( i ) ) + chr$( 13 ) fl = i setfl = 1 end if next i if fl then for i = 0 to 13 if q( i ) >= 3 then r = i end if next i if r >= 10 then tel = 0 for i = 10 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i if r >= 8 then tel = 0 for i = 8 to 13 if q( i ) = 4 then w( tel ) = i tel = tel + 1 end if next i end if for i = 0 to tel print stone.str$( c( w( i ) ) ) next i notice "AI" + chr$( 13 ) _ + "first move AI :" + q$ _ + "above set fount ." else notice "AI" + chr$( 13 ) _ + "first move AI :" + chr$( 13 ) _ + "no set fount ." end if end if else i = 0 while not( color( c( i ) ) = color( c( i + 1 ) ) _ and color( c( i ) ) = color( c( i + 2 ) ) _ and c( i ) = c( i + 1 ) - 1 _ and c( i ) = c( i + 2 ) - 2 _ and value( c( i ) ) _ + value( c( i + 1 ) ) ) _ and i < 11 i = i + 1 wend if i = 11 then notice "AI" + chr$( 13 ) _ + "move AI :" + chr$( 13 ) _ + "no street fount by AI ." else q$ = "" for q = i to i + 2 q$ = q$ + stone.str$( c( q ) ) + " " next q notice"AI" + chr$( 13 ) _ + "move AI :" + chr$( 13 ) _ + q$ + chr$( 13 ) _ + "above street fount by AI ." streetfl = 1 end if '' look for 'sets' for i = 0 to 13 q( value( c( i ) ) ) = q( value( c( i ) ) ) + 1 next i fl = 0 q$ = "" for i = 1 to 13 if q( i ) >= 3 then q$ = q$ + "set " ; str$( i ) ; " of " ; str$( q( i ) ) + chr$( 13 ) fl = i setfl = 1 end if next i if fl then for i = 1 to 13 if q( i ) >= 3 then r = i end if next i tel = 0 for i = 1 to 13 if q( i ) = 3 then w( tel ) = i tel = tel + 1 end if next i tel2 = 0 for i = 1 to 13 if q( i ) = 4 then w( tel2 ) = i tel2 = tel2 + 1 end if next i if tel = 0 and tel2 = 0 then notice "AI" + chr$( 13 ) _ + "move AI :" + chr$( 13 ) _ + "no set fount ." else notice "AI" + chr$( 13 ) _ + "move AI :" + chr$( 13 ) _ + q$ + "above sets fount ." end if end if end if if not( streetfl ) and not( setfl ) then notice "AI" + chr$( 13 ) _ + "no set or street fount :" + chr$( 13 ) _ + "AI buy's stone ." end if notice "AI" + chr$( 13 ) _ + "end AI ." end sub
end function irange( l , h ) irange = int( rnd(0) * ( h - l + 1 ) ) + l end function function value( i ) uit = ( i mod 13 ) + 1 if i = 250 then uit = 25 value = uit end function function color( i ) uit = ( int( i / 13 ) and 3 ) + 1 if i = 250 then uit = 0 color = uit end function function stone.str$( i ) stone.str$ = right$( " " _ + str$( value( i ) ) , 2 ) ; color( i ) end function
|
|
|
Post by Rod on Oct 18, 2019 8:14:47 GMT
Hmmm.... we play Rummikub as a family, it is a very visual game, nothing is laid out in columns or rows. They are laid out in sets, but anywhere on the table. The joker is played in place of any needed tile. As soon as it is played it is available to any other player who can swap in the tile it is pretending to be.
I will post some sprite code that will give a bag of counters to play with.
|
|
|
Post by bluatigro on Oct 18, 2019 8:58:40 GMT
Hmmm.... we play Rummikub as a family, it is a very visual game, nothing is laid out in columns or rows. They are laid out in sets, but anywhere on the table. that is true but beond my skils this is the way i can code it at least i have some idea whet i m doing
|
|
|
Post by B+ on Oct 18, 2019 14:38:11 GMT
Hmmm.... we play Rummikub as a family, it is a very visual game, nothing is laid out in columns or rows. They are laid out in sets, but anywhere on the table. The joker is played in place of any needed tile. As soon as it is played it is available to any other player who can swap in the tile it is pretending to be. I will post some sprite code that will give a bag of counters to play with. I thought last night that it might be easier for the AI or game control code to check in preset places for straights (like in color sequence of number) or groups (like in number different in color) but after laying out board with preset places for straights and groups in rows and columns I see it is added nightmare to track all the additional places. Oh well back to drawing board.
|
|
|
Post by Rod on Oct 19, 2019 11:25:43 GMT
This is a simple start at a sprite engine that might use some of bluatigro's AI. Currently it just draws some sprites and fills a bag with chips in random order. The idea is that the chips will move from the bag to the players and eventually to the table array.
Lots still to do but bluatigro always comes up with interesting concepts.
nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) midx=int(WindowWidth/2) midy=int(WindowHeight/2) open "Chips" for graphics_nsb as #w #w "trapclose [quit]"
dim bag$(106,6) chipnum=1 'chips numbered 1 to 106 chipcol=2 'color of chip or j if joker chipval=3 'value of chip chiprnd=4 'rnd() value for shuffle
'make the sprites and fill bag$() array gosub [makesprites]
'shuffle the bag sort bag$(),1,106,chiprnd
'set all chips off screen for n= 1 to 106 #w "spritexy chip";bag$(n,chipnum);" -100 -100" next
'set chip pointer to first chip in bag chippointer=1
'deal the first hand, 14 chips to each player dim p1$(50,4) dim p2$(50,4) dim p3$(50,4) dim p4$(50,4) cnum=1 cval=2 ccol=3
[deal] for n=1 to 14 p1$(n,cnum)=bag$(chippointer,chipnum) p1$(n,cval)=bag$(chippointer,chipval) p1$(n,ccol)=bag$(chippointer,chipcol) chippointer=chippointer+1 next player1holds=14 for n=1 to 14 p2$(n,cnum)=bag$(chippointer,chipnum) p2$(n,cval)=bag$(chippointer,chipval) p2$(n,ccol)=bag$(chippointer,chipcol) chippointer=chippointer+1 next player2holds=14 for n=1 to 14 p3$(n,cnum)=bag$(chippointer,chipnum) p3$(n,cval)=bag$(chippointer,chipval) p3$(n,ccol)=bag$(chippointer,chipcol) chippointer=chippointer+1 next player3holds=14 for n=1 to 14 p4$(n,cnum)=bag$(chippointer,chipnum) p4$(n,cval)=bag$(chippointer,chipval) p4$(n,ccol)=bag$(chippointer,chipcol) chippointer=chippointer+1 next player4holds=14
'show player one's hand x=400 y=600 sort p1$(),1,player1holds,cval sort p1$(),1,player1holds,ccol for n= 1 to player1holds #w "spritexy chip";p1$(n,cnum);" ";x;" ";y x=x+55 if x>900 then y=y+110 : x=400 next #w "drawsprites" wait
[makesprites] #w "down ; fill darkgreen ; font comic_sans 20 bold" #w "getbmp bak 0 0 1 1 ; background bak" #w "place 0 0 ; color black ; backcolor black ; boxfilled 50 140" #w "place 0 0 ; color white ; backcolor white ; boxfilled 50 70" #w "place 3 3 ; color black ; backcolor black ; boxfilled 47 67" #w "place 3 73 ;color 231 233 194 ; backcolor 231 233 194 ; boxfilled 47 137" #w "color white ; line 5 75 5 135 ; line 5 75 45 75" #w "color black; line 46 74 46 137 ; line 46 136 3 136" #w "flush chip"
chip=1 #w "backcolor 231 233 194 ; color red" col$="r" gosub [sprite] #w "color black" col$="b" gosub [sprite] #w "color 25 186 245 " col$="o" gosub [sprite] #w "color 255 162 24" col$="c" gosub [sprite]
#w "color black" #w "discard ; redraw chip ; place 15 110 ;\J" #w "getbmp chip";str$(chip);" 0 0 50 140" #w "addsprite chip";str$(chip);" chip";str$(chip) bag$(chip,chipnum)=str$(chip) bag$(chip,chipcol)="j" bag$(chip,chipval)="30" bag$(chip,chiprnd)=str$(int(rnd(0)*10000)) chip=chip+1 #w "getbmp chip";str$(chip);" 0 0 50 140" #w "addsprite chip";str$(chip);" chip";str$(chip) bag$(chip,chipnum)=str$(chip) bag$(chip,chipcol)="j" bag$(chip,chipval)="30" bag$(chip,chiprnd)=str$(int(rnd(0)*10000)) return
[sprite] for n=1 to 13 if n>9 then #w "discard ; redraw chip ; place 8 110 ;\";str$(n) else #w "discard ; redraw chip ; place 15 110 ;\";str$(n) end if #w "getbmp chip";str$(chip);" 0 0 50 140" #w "addsprite chip";str$(chip);" chip";str$(chip) bag$(chip,chipnum)=str$(chip) bag$(chip,chipcol)=col$ bag$(chip,chipval)=str$(n) bag$(chip,chiprnd)=str$(int(rnd(0)*10000)) chip=chip+1 #w "getbmp chip";str$(chip);" 0 0 50 140" #w "addsprite chip";str$(chip);" chip";str$(chip) bag$(chip,chipnum)=str$(chip) bag$(chip,chipcol)=col$ bag$(chip,chipval)=str$(n) bag$(chip,chiprnd)=str$(int(rnd(0)*10000)) chip=chip+1 next return
[quit] close #w end
|
|
|
Post by bluatigro on Oct 22, 2019 11:27:39 GMT
some useful sub's
table$ is 2d dynamic array whit strings whit can be used to steer the sprites
global set.cut$ : set.cut$ = "|" global stone.cut$ : stone.cut$ = "," global table$
end sub add.left.to.set byref set$ , stone$ set$ = stone$ + stone.cut$ + set$ end sub sub add.right.to.set byref set$ , stone$ set$ = set$ + stone.cut$ + stone$ end function function size( al$ , cut$ ) uit = 1 while word$( al$ , uit , cut$ ) <> "" uit = uit + 1 wend set.size = uit end function sub add.set.to.table set$ table$ = table$ + set.cut$ + set$ end sub sub remove.set.from.table set$ m = size( table$ , set.cut$ ) for i = 1 to m if word$( table$ , i , set.cut$ ) <> set$ then uit$ = uit$ + set.cut$ + word$( table$ , i , set.cut$ ) end if next i table$ = uit$ end sub sub split.set nr , stone$ t$ = word$( table$ , nr , set.cut$ ) qa = size( t$ , stone.cut$ ) if qa <= 5 then exit sub q = find( t$ , stone$ , stone.cut$ ) if q <= 2 then exit sub l$ = get.part.of.set$( t$ , 1 , q ) r$ = get.part.of.set$( t$ , q + 1 , qa ) call remove.set t$ call add.set.to.table l$ call add.set.to.table r$ end sub function get.part.of.set$( set$ , l , h ) uit$ = "" for i = l to h call add.right.to.set uit$ , word$( set$ , i , stone.cut$ ) next i get.part.of.set$ = uit$ end function function find( al$ , item$ , cut$ ) uit = 0 m = size( al$ , cut$ ) for i = 1 to m if word$( al$ , i , cut$ ) = item$ then uit = i end if next i find = uit end function
|
|