The fingers game is quite simple, and can be played anywhere with another person.
1. The two players start by holding up two fingers each, one on each hand.
2. On a player's turn, that player can point with one hand to any of the three hands around him (his own or the other players'). The hand that gets pointed to adds the number of fingers on the hand that did the pointing to his own, and sticks that many fingers up. For instance, if my right hand has two fingers up and I point it to your left hand, which has one finger up, you would now show three fingers on your left hand.
3. If five fingers or more should be up, make a fist. A fist cannot be used to point with.
4. If you have one fist and your other hand has an even number of fingers, you can point with the second hand to the fist on your turn, and divide the fingers evenly between the hands. This is the only time a fist may be pointed to.
Players alternate turns, and the first player to show two fists loses.
Is there a winning strategy for either player? Which player, if either, has a better chance of winning?
(In reply to
solution by Charlie)
DIM state$(4, 4, 4, 4)'subs are own high, own low, opponent's high, opp. low
DATA h1l,h2h,h2l,l1h,l2h,l2l
'move desc: "h1l" - high hand points to own low hand
' "h2h" - high hand points to opp high hand, etc.
FOR i = 1 TO 6
READ mv$(i)
NEXT
FOR i = 0 TO 4
FOR j = 0 TO i
state$(0, 0, i, j) = "l"
state$(i, j, 0, 0) = "x"
NEXT
NEXT
state$(0, 0, 0, 0) = "x"
DO
doneAnything = 0
'first check for new winning moves for all states
FOR myHigh = 1 TO 4
FOR myLow = 0 TO myHigh
FOR yrHigh = 1 TO 4
FOR yrLow = 0 TO yrHigh
IF state$(myHigh, myLow, yrHigh, yrLow) = "" THEN
currStat(1) = myHigh: currStat(2) = myLow
currStat(3) = yrHigh: currStat(4) = yrLow
FOR pMove = 1 TO 6
move$ = mv$(pMove): GOSUB moveResult
IF valid THEN
IF LEFT$(state$(newStat(3), newStat(4), newStat(1), newStat(2)), 1) = "l" THEN
' this is a winner
state$(myHigh, myLow, yrHigh, yrLow) = "w" + move$
doneAnything = 1
EXIT FOR
END IF
END IF
NEXT pMove
END IF
NEXT yrLow
NEXT yrHigh
NEXT myLow
NEXT myHigh
' now check for losing states (where all moves yield opp winner)
FOR myHigh = 1 TO 4
FOR myLow = 0 TO myHigh
FOR yrHigh = 1 TO 4
FOR yrLow = 0 TO yrHigh
IF state$(myHigh, myLow, yrHigh, yrLow) = "" THEN
currStat(1) = myHigh: currStat(2) = myLow
currStat(3) = yrHigh: currStat(4) = yrLow
hadNonLoss = 0
FOR pMove = 1 TO 6
move$ = mv$(pMove): GOSUB moveResult
IF valid THEN
rslt$ = LEFT$(state$(newStat(3), newStat(4), newStat(1), newStat(2)), 1)
IF rslt$ <> "w" THEN
' this is a nonLoser
hadNonLoss = 1: EXIT FOR
EXIT FOR
END IF
END IF
NEXT pMove
IF hadNonLoss = 0 THEN
state$(myHigh, myLow, yrHigh, yrLow) = "l"
doneAnything = 1
END IF
END IF
NEXT yrLow
NEXT yrHigh
NEXT myLow
NEXT myHigh
GOSUB showStatus: gen = gen + 1: PRINT gen
DO: LOOP UNTIL INKEY$ > ""
LOOP WHILE doneAnything
GOSUB saveStatus
END
moveResult:
valid = 1
FOR stPt = 1 TO 4
newStat(stPt) = currStat(stPt)
NEXT
IF LEFT$(move$, 1) = "h" THEN numPting = currStat(1): subj = 1: ELSE numPting = currStat(2): subj = 2
SELECT CASE MID$(move$, 2, 2)
CASE "1l"
obj = 2
CASE "1h"
obj = 1
CASE "2l"
obj = 4
CASE "2h"
obj = 3
END SELECT
IF subj = obj OR numPting = 0 THEN
valid = 0: RETURN
END IF
IF move$ = "h1l" AND currStat(1) MOD 2 = 0 AND currStat(2) = 0 THEN
newStat(2) = currStat(1) / 2: newStat(1) = newStat(2)
ELSE
IF currStat(obj) = 0 THEN valid = 0: RETURN
newStat(obj) = currStat(obj) + currStat(subj)
IF newStat(obj) >= 5 THEN newStat(obj) = 0
IF newStat(2) > newStat(1) THEN SWAP newStat(2), newStat(1)
IF newStat(4) > newStat(3) THEN SWAP newStat(4), newStat(3)
END IF
RETURN
showStatus:
PRINT : PRINT : PRINT " ";
FOR yrHigh = 0 TO 4
FOR yrLow = 0 TO yrHigh
PRINT LTRIM$(STR$(yrHigh)); LTRIM$(STR$(yrLow)); " ";
NEXT
NEXT
PRINT
FOR myHigh = 0 TO 4
FOR myLow = 0 TO myHigh
PRINT LTRIM$(STR$(myHigh)); LTRIM$(STR$(myLow)); " ";
FOR yrHigh = 0 TO 4
FOR yrLow = 0 TO yrHigh
IF state$(myHigh, myLow, yrHigh, yrLow) = "" THEN
PRINT USING "\ \"; ".";
ELSE
PRINT USING "\ \"; state$(myHigh, myLow, yrHigh, yrLow);
END IF
NEXT yrLow
NEXT yrHigh
PRINT
NEXT myLow
NEXT myHigh
RETURN
saveStatus:
OPEN "pointing.txt" FOR OUTPUT AS #2
PRINT #2, : PRINT #2, : PRINT #2, " ";
FOR yrHigh = 0 TO 4
FOR yrLow = 0 TO yrHigh
PRINT #2, LTRIM$(STR$(yrHigh)); LTRIM$(STR$(yrLow)); " ";
NEXT
NEXT
PRINT #2,
FOR myHigh = 0 TO 4
FOR myLow = 0 TO myHigh
PRINT #2, LTRIM$(STR$(myHigh)); LTRIM$(STR$(myLow)); " ";
FOR yrHigh = 0 TO 4
FOR yrLow = 0 TO yrHigh
IF state$(myHigh, myLow, yrHigh, yrLow) = "" THEN
PRINT #2, USING "\ \"; ".";
ELSE
PRINT #2, USING "\ \"; state$(myHigh, myLow, yrHigh, yrLow);
END IF
NEXT yrLow
NEXT yrHigh
PRINT #2,
NEXT myLow
NEXT myHigh
PRINT #2,
FOR myHigh = 0 TO 4
FOR myLow = 0 TO myHigh
FOR yrHigh = 0 TO 4
FOR yrLow = 0 TO yrHigh
PRINT #2, LTRIM$(STR$(myHigh)); LTRIM$(STR$(myLow)); LTRIM$(STR$(yrHigh)); LTRIM$(STR$(yrLow)); " ";
s$ = state$(myHigh, myLow, yrHigh, yrLow)
IF s$ > "" THEN
IF LEN(s$) = 1 THEN
PRINT #2, s$; " ";
IF s$ <> "w" THEN
currStat(1) = myHigh: currStat(2) = myLow
currStat(3) = yrHigh: currStat(4) = yrLow
FOR mvPt = 1 TO 6
move$ = mv$(mvPt)
GOSUB moveResult
IF valid THEN
PRINT #2, move$; " ";
PRINT #2, LTRIM$(STR$(newStat(3))); LTRIM$(STR$(newStat(4))); LTRIM$(STR$(newStat(1))); LTRIM$(STR$(newStat(2)));
PRINT #2, " ";
END IF
NEXT
END IF
PRINT #2,
ELSE
move$ = MID$(s$, 2)
currStat(1) = myHigh: currStat(2) = myLow
currStat(3) = yrHigh: currStat(4) = yrLow
GOSUB moveResult
PRINT #2, LEFT$(s$, 1); " "; move$; " ";
PRINT #2, LTRIM$(STR$(newStat(3))); LTRIM$(STR$(newStat(4))); LTRIM$(STR$(newStat(1))); LTRIM$(STR$(newStat(2)))
END IF
ELSE
currStat(1) = myHigh: currStat(2) = myLow
currStat(3) = yrHigh: currStat(4) = yrLow
FOR mvPt = 1 TO 6
move$ = mv$(mvPt)
GOSUB moveResult
IF valid THEN
PRINT #2, LEFT$(s$, 1); " "; move$; " ";
PRINT #2, LTRIM$(STR$(newStat(3))); LTRIM$(STR$(newStat(4))); LTRIM$(STR$(newStat(1))); LTRIM$(STR$(newStat(2)));
IF LEFT$(state$(newStat(3), newStat(4), newStat(1), newStat(2)), 1) = "w" THEN
PRINT #2, "*";
ELSE
PRINT #2, "+";
END IF
PRINT #2, " ";
END IF
NEXT
PRINT #2,
END IF
NEXT
NEXT
NEXT
NEXT
CLOSE 2
RETURN
|
Posted by Charlie
on 2004-07-11 12:51:38 |