Post by B+ on Oct 30, 2019 14:24:39 GMT
I think I can work out the AI for Rummikub IF.... but I haven't played this game so am not familiar with all fine points of game, so I need a ruling:
IF a player rearranges all the sets or most on table and IF all the sets are legal AND the player adds a tile from his rack it's OK right? ie it is not necessary to follow and rule every rearranged set along the way.
Wait one caveat, if the player uses a joker in another place he must first provide the legal substitute for that joker from his rack THEN he is free to use it any where he pleases and then thus able to completely rearrange any or all the sets as long as he leaves all legal sets when done.
Ah another caveat, for any joker not replaced, that Joker's placement in that set can't be moved or broken until a real tile replaces it. eg if joker is sitting at high end of straight it (can or can 't) be moved to low end if player wants to play a tile below that ?
hmm... these Jokers aren't funny ;(
I was thinking an AI referee would just have to copy the table, and the players hand (or AI if AI's turn) before the turn, wait until player (or AI) says they are done.
THEN the AI referee would just need to see if all the new sets are legal, if so allow next player's turn, if NOT restore table as it was and player's rack as it was and either force player to take a tile or have player do sets over again (pointing out the first illegal set discovered after player says his turn is done).
So I am thinking the above would be fine for refereeing if NO Jokers.
With Jokers, the player must replace Joker(s) with his own tile first before accessing the whole table freely to rearrange otherwise the Joker stays glued to it's position in a Straight or it's number and open color in a group.
Here is code for checking if a set is legal even if it contains one or two Jokers and it will assign the highest legal points allowed, say if player has a Joker positioned at low end of straight, the setOK function will give point credit for high end up to 13 and then start just below if 2 Jokers.
I think this is solid checker, if you find a set that is judged incorrectly, let me know.
I find it difficult to proceed with my AI meld maker SUB without more info about game rulings.
More notes: Jokers in my structure have color #5 and #6 and zero value in sorts of color and number. Tiles are 4 characters long the first is a color number 1 thru 6 then a _ for visually separating the color number from the tile number 1 thru 13 or J for Joker and a space if tile number is 1 character long. So a set minimally has to be 12 characters long, the tiles every 4 characters.
IF a player rearranges all the sets or most on table and IF all the sets are legal AND the player adds a tile from his rack it's OK right? ie it is not necessary to follow and rule every rearranged set along the way.
Wait one caveat, if the player uses a joker in another place he must first provide the legal substitute for that joker from his rack THEN he is free to use it any where he pleases and then thus able to completely rearrange any or all the sets as long as he leaves all legal sets when done.
Ah another caveat, for any joker not replaced, that Joker's placement in that set can't be moved or broken until a real tile replaces it. eg if joker is sitting at high end of straight it (can or can 't) be moved to low end if player wants to play a tile below that ?
hmm... these Jokers aren't funny ;(
I was thinking an AI referee would just have to copy the table, and the players hand (or AI if AI's turn) before the turn, wait until player (or AI) says they are done.
THEN the AI referee would just need to see if all the new sets are legal, if so allow next player's turn, if NOT restore table as it was and player's rack as it was and either force player to take a tile or have player do sets over again (pointing out the first illegal set discovered after player says his turn is done).
So I am thinking the above would be fine for refereeing if NO Jokers.
With Jokers, the player must replace Joker(s) with his own tile first before accessing the whole table freely to rearrange otherwise the Joker stays glued to it's position in a Straight or it's number and open color in a group.
Here is code for checking if a set is legal even if it contains one or two Jokers and it will assign the highest legal points allowed, say if player has a Joker positioned at low end of straight, the setOK function will give point credit for high end up to 13 and then start just below if 2 Jokers.
'test setOK function" 'b+ 2019-10-25
' convert to JB 2019-10-29
'setOK% is such a monster function I want to test it independent from random tile assignments,
'see if I can break it with a legal set and get no points or wrong points or get points for illegal sets
'specially test 1 and 2 joker states
DIM table$(40), n(0), c(0) 'arrays are global n() is for numbers and c() is for colors, table$() holds the different sets of tiles.
table$(1) = "1_1 2_1 " 'right 0 points, not even long enough to check
table$(2) = "1_1 2_1 3_1 " ' legal starting, return 3
table$(3) = "1_1 2_1 1_3 " 'OK not legal 0 points
table$(4) = "3_4 3_5 3_6 " 'legal straight 15 points
table$(5) = "3_6 3_4 3_5 " 'mix order
table$(6) = "3_6 5_J 3_4 3_5 " 'mix order add joker 15+7 = 22 great!
table$(7) = "3_2 3_6 5_J 3_4 3_5 " ' add joker filling a straight 2+3+4+5+6 = 20 yeah!" !!!'here's where troubles started
table$(8) = "3_2 3_6 5_J 3_4 3_5 3_8 6_J " ' two jokers filling inside straights 20 + 7 + 8 = 35 check !!! Oh my disaster!!!
table$(9) = "3_2 3_6 5_J 3_5 6_J " 'two jokers fill 2 places next to each other inside fantastic!
table$(10) = "3_125_J 3_116_J " '2 jokers cover outside slots both ends 10+11+12+13? =46 great!
table$(11) = "1_125_J 3_126_J " ' little change for group 4*12 = 48
table$(12) = "5_J 3_126_J " ' just one real color tile 3*12
table$(13) = "1_123_122_12" '3*12 the real way
for slot = 1 to 13
PRINT "Slot ";slot;" Points ";setOK(table$(slot)) 'this will just print 0 because we are testing troubled first part of function
input "Press enter... ";w$
next
print "Testing done."
FUNCTION setOK(setString$) 'return 0 if NOT OK, else return points
nTiles = LEN(setString$) / 4
print:print "Slot #";nSlot;" has nTiles = ";nTiles
IF nTiles < 3 OR nTiles > 13 THEN EXIT FUNCTION 'NOT OK to have less than 3 tiles or more than 13
'load 2 little arrays sorting as we go to analyse colors and numbers
REDIM c(nTiles)
redim n(nTiles) 'erase and redim
FOR i = 1 TO nTiles
tile$ = MID$(setString$, i * 4 - 3, 4)
print "Tile$ ";tile$;
clr = VAL(LEFT$(tile$, 1)): num = VAL(MID$(tile$, 3, 2))
print " clr ";clr;" num ";num
if i = 1 then
c(1) = clr
else
for j = 1 to i - 1
if clr < c(j) then
for k = i to j + 1 step -1
c(k) = c(k - 1)
next
exit for '<<< here is what I didn't do last night!!!
end if
next
c(j) = clr
end if
'now same for num
if i = 1 then
n(1) = num
else
for j = 1 to i - 1
if num < n(j) then
for k = i to j + 1 step -1
n(k) = n(k - 1)
next
exit for '<<< here is what I didn't do last night!!!
end if
next
n(j) = num
end if
NEXT
print "check load/sort of colors and numbers:"
for i = 1 to nTiles
print i, c(i), n(i)
next
'colors: either they are all the same which means the numbers need to be in sequence
' or they are all different and total 3 or 4 tiles
' for colors the jokers will sort last, for numbers the jokers will sort first
'count jokers
IF c(nTiles) = 5 OR c(nTiles) = 6 THEN
joker = 1
IF c(nTiles - 1) = 5 THEN joker = 2
END IF
start = joker + 1
'color check
IF c(1) = c(nTiles - joker) THEN 'do a straight check because all colors the same
FOR i = start TO nTiles - 1 'jokers in numbers are at bottom the rest of the numbers are in sequence
IF n(i) <> n(i + 1) - 1 THEN
IF n(i) = n(i + 1) - 2 AND (joker > 0) THEN
joker = joker - 1: points = points + 2 * n(i) + 1
ELSE
IF n(i) = n(i + 1) - 3 AND joker = 2 THEN
joker = 0: points = points + 3 * n(i) + 3
ELSE
EXIT FUNCTION 'don't have a straight
end if
END IF
ELSE
points = points + n(i)
END IF
NEXT
points = points + n(nTiles)
'have we not used jokers in the middle?
IF joker = 2 THEN '2 jokers!!! not used in middle what are the odds???
IF n(nTiles) = 13 THEN
points = points + 2 * n(start) - 3
else
IF n(nTiles) = 12 THEN
points = points + 13 + n(start) - 1
ELSE 'n(nTiles)< 12
points = points + 2 * n(nTiles) + 3
end if
END IF
END IF
IF joker = 1 THEN
IF n(nTiles) = 13 THEN
points = points + n(start) - 1
ELSE
points = points + n(nTiles) + 1
END IF
END IF
ELSE
'see that all the colors are different and only 3 or 4 tiles and all the numbers are same if not joker
IF nTiles > 4 THEN EXIT FUNCTION 'max 4 different colors
IF n(start) <> n(nTiles) THEN EXIT FUNCTION 'not all the numbers ( past the jokers) are the same
'now check each color is different
FOR i = 1 TO nTiles - joker - 1 ' if 1 actual tile and 2 jokers this test wil not even start!
FOR j = i + 1 TO nTiles - joker
IF c(i) = c(j) THEN EXIT FUNCTION
NEXT
NEXT
'if still here then
points = nTiles * n(nTiles)
END IF
setOK = points
END FUNCTION
I think this is solid checker, if you find a set that is judged incorrectly, let me know.
I find it difficult to proceed with my AI meld maker SUB without more info about game rulings.
More notes: Jokers in my structure have color #5 and #6 and zero value in sorts of color and number. Tiles are 4 characters long the first is a color number 1 thru 6 then a _ for visually separating the color number from the tile number 1 thru 13 or J for Joker and a space if tile number is 1 character long. So a set minimally has to be 12 characters long, the tiles every 4 characters.