RockScissorsPaper1

Even though participants were supposed to write one function, this has a number of auxiliary functions. All this should replace the function rightPick.

code format="blitzbasic" function LastWin(wins$) for i = len(wins$) to 1 step -1 if mid$(wins$, i, 1) <> "0" then LastWin = val(mid$(wins$, i, 1)) exit for end if   next i end function

function WinningMove(guessedOpMove) WinningMove = guessedOpMove + 1 if WinningMove > 3 then WinningMove = 1 if WinningMove < 1 then WinningMove = 3 end function

function Opponent1(history$) Opponent1 = 1 c$ = left$(history$, 1) for i = 2 to len(history$) if mid$(history$, i, 1) <> c$ then Opponent1 = 0 : exit for next i end function

function Opponent2(history$) Opponent2 = 1 val = val(left$(history$, 1)) - 1 for i = 2 to len(history$) if (val + 1) mod 3 + 1 <> val(mid$(history$, i, 1)) then Opponent2 = 0 : exit for val = (val + 1) mod 3 next i end function

function Opponent3(history$) Opponent3 = 1 val = val(left$(history$, 1)) - 1 for i = 2 to len(history$) if val <> val(mid$(history$, i, 1)) mod 3 then Opponent3 = 0 : exit for val = (val + 2) mod 3 next i end function

function Opponent4(me$, opp$) Opponent4 = 1 for i = 2 to len(me$) if mid$(me$, i - 1, 1) <> mid$(opp$, i, 1) then Opponent4 = 0 : exit for next i end function

function Opponent5(me$, opp$) Opponent5 = 1 for i = 2 to len(me$) if val(mid$(me$, i - 1, 1)) mod 3 + 1 <> val(mid$(opp$, i, 1)) then Opponent5 = 0 : exit for next i end function

function Opponent7(opp$, win$) Opponent7 = 1 for i = 2 to len(opp$) n = val(mid$(win$, i - 1, 1)) if n <> 0 then currentWin = n       if currentWin <> 0 and val(mid$(opp$, i, 1)) <> currentWin then Opponent7 = 0 : exit for next i end function

function Opponent8(opp$, win$) Opponent8 = 1 for i = 2 to len(opp$) n = val(mid$(win$, i - 1, 1)) if n <> 0 then currentWin = n       if currentWin <> 0 and currentWin mod 3 + 1 <> val(mid$(opp$, i, 1)) then Opponent8 = 0 : exit for next i end function

function Opponent9(opp$, win$) Opponent9 = 1 for i = 2 to len(opp$) n = val(mid$(win$, i - 1, 1)) if n <> 0 then currentWin = n       if currentWin <> 0 and val(mid$(opp$, i, 1)) mod 3 + 1 <> currentWin then Opponent9 = 0 : exit for next i end function

function rightPick(ownHistory$, oppHistory$, winHistory$) select case case Opponent1(oppHistory$) : predictedMove = val(left$(oppHistory$, 1)) case Opponent2(oppHistory$) : predictedMove = val(right$(oppHistory$, 1)) mod 3 + 1 case Opponent3(oppHistory$) : predictedMove = (val(right$(oppHistory$, 1)) + 2) mod 3 case Opponent4(ownHistory$, oppHistory$) : predictedMove = val(right$(ownHistory$, 1)) case Opponent5(ownHistory$, oppHistory$) : predictedMove = val(right$(ownHistory$, 1)) mod 3 + 1 'case Opponent6 : I win anyway case Opponent7(oppHistory$, winHistory$): predictedMove = LastWin(winHistory$) case Opponent8(oppHistory$, winHistory$): predictedMove = LastWin(winHistory$) mod 3 + 1 case Opponent9(oppHistory$, winHistory$): predictedMove = LastWin(winHistory$) -1 end select rightPick = WinningMove(predictedMove) end function code