乱数にXorShiftを使ったじゃんけんゲーム。


Dim XorSeed[3] As DWord

'乱数初期化
Sub sxor128() As DWord
Dim s As DWord
Dim n As DWord
s = GetTickCount()

For n=0 To 3
s = 1812433253 * (s Xor (s >> 30)) + n
XorSeed[n] = s
Next
End Sub

'乱数発生
Function xor128() As DWord
Dim t As DWord

t = (XorSeed[0] Xor (XorSeed[0] << 11))
XorSeed[0] = XorSeed[1]: XorSeed[1] = XorSeed[2]: XorSeed[2] = XorSeed[3]
XorSeed[3] = (XorSeed[3] Xor (XorSeed[3] >> 19)) Xor (t Xor (t >> 8))
xor128 = XorSeed[3]
End Function


#N88BASIC
Enum
GU = 0
TYOKI
PAA
End Enum

Dim HandNameStr[2] = ["ぐう", "ちょき", "ぱあ"] As *Byte
Dim JudgeNameStr[2] = ["あいこ", "勝ち", "負け"] As *Byte

Function NumbarToHandName(nu As Long) As String
NumbarToHandName = HandNameStr[nu]
End Function

Function NumbarToJudgeName(nu As Long) As String
NumbarToJudgeName = JudgeNameStr[nu]
End Function

Function Judge(a As DWord, b As DWord) As DWord
If a = b Then Judge = 0
If (a = GU And b = TYOKI) Or (a = TYOKI And b = PAA) Or (a = PAA And b = GU) Then Judge = 1
If (a = GU And b = PAA) Or (a = TYOKI And b = GU) Or (a = PAA And b = TYOKI) Then Judge = 2
End Function

Dim pc As DWord'コンピュータの手
Dim usr As DWord'ユーザーの手

sxor128()
Print "じゃんけんゲーム"
*LABEL1
Input "ぐう=0, ちょき=1, ぱあ=2を入力。";usr
If usr <> GU And usr <> TYOKI And usr <> PAA Then *LABEL1
pc = xor128() Mod 3 As DWord

Print "あなたの手=";NumbarToHandName(usr),"コンピュータの手=";NumbarToHandName(pc)
Print NumbarToJudgeName(Judge(usr, pc))
Print ""
Goto *LABEL1