Microsoft Small Basic

Program Listing: PMV523-0
' Random 8-picture 55-card set (Dobble / Spot it!) - PMV523-0
' Copyright (c) 2014 Nonki Takahashi
'
' Lisence:
' The MIT Lisence (MIT)
' http://en.wikipedia.org/wiki/MIT_License
'
Not = "False=True;True=False;"
random = "True"
smax = 8
cmax = 55
pmax = smax * cmax / 2
timeout = "True"
Timer.Interval = 600
Timer.Tick = OnTick
t = 0
While timeout
card = ""
timeout = "False"
t = t + 1
r = Math.Remainder(t, 10)
If r = 1 Then
TextWindow.WriteLine(t + "st Try")
ElseIf r = 2 Then
TextWindow.WriteLine(t + "nd Try")
ElseIf r = 3 Then
TextWindow.WriteLine(t + "rd Try")
Else
TextWindow.WriteLine(t + "th Try")
EndIf
c = 0
For p = 1 To pmax
FindCard()
If found Then
Append()
Else
Goto error
EndIf
c1 = c
found = "False"
While Not[found] And Not[timeout]
FindCard()
If Not[found] Then
Goto error
EndIf
c2 = c
AreDup()
found = Not[dup]
If found Then
Append()
EndIf
EndWhile
EndFor
error:
If timeout Then
TextWindow.WriteLine("Timeout")
EndIf
Print()
EndWhile
Sub Append
' param c - card number
' param p - picture number
len = Text.GetLength(p)
If len < 3 Then
p = Text.Append(Text.GetSubTextToEnd("00", len), p)
EndIf
If card[c] = "" Then
card[c] = p
Else
card[c] = card[c] + "-" + p
EndIf
EndSub
Sub AreDup
' param c1, c2 - card numbers to compare
' return dup - "True" if two cards have the same number
len = Text.GetLength(card[c1])
dup = "False"
For i = 1 To len - 3 Step 4
If Text.IsSubText(card[c2], Text.GetSubText(card[c1], i, 3)) Then
dup = "True"
Goto exit
EndIf
EndFor
exit:
EndSub
Sub FindCard
' param p - picture number
' return c - card number
' return found - "True" if found
found = "False"
While Not[found] And Not[timeout]
If random Then
c = Math.GetRandomNumber(cmax)
Else
c = c + 1
If cmax < c Then
c = 1
EndIf
EndIf
If card[c] = "" Then
found = "True"
ElseIf (Text.GetLength(card[c]) < (4 * smax - 1)) And Not[Text.IsSubText(card[c], p)] Then
found = "True"
EndIf
EndWhile
EndSub
Sub OnTick
timeout = "True"
EndSub
Sub Print
For c = 1 To cmax
If Text.GetLength(c) < 2 Then
c = Text.Append(0, c)
EndIf
If card[c * 1] <> "" Then
TextWindow.WriteLine(c + ":" + card[c * 1])
EndIf
EndFor
TextWindow.WriteLine("")
EndSub