Tuesday, June 26, 2012
Small Basic Spell Checker - 25 lines challenge
'Spell checker example - wxv722-2
'Uses Dictionary.GetDefinition(word) - Need internet access
'Harry Hardjono
'June 2012 - 25 line small basic challenge version
'
Str="abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ"
While (inputtext<>" ")
TextWindow.WriteLine(" ")
TextWindow.WriteLine("Enter your sentence: ")
inputtext=text.Append(TextWindow.Read()," ")
For i=1 To Text.GetLength(inputtext)
If (Text.GetIndexOf(Str,Text.GetSubText(inputtext,i,1))=0) Then 'Not word
If (Word<>"") Then
If (Dictionary.GetDefinition(Word)="") Then
TextWindow.BackgroundColor="white"
TextWindow.ForegroundColor="black"
TextWindow.Write(Word)
TextWindow.BackgroundColor="black"
TextWindow.ForegroundColor="white"
Else
TextWindow.Write(Word)
EndIf
Word=""
EndIf
TextWindow.Write(Text.GetSubText(inputtext,i,1))
Else 'Word
Word=Text.Append(Word,Text.GetSubText(inputtext,i,1))
EndIf
endfor
EndWhile
Tuesday, June 19, 2012
Small Basic Cube Root
'Cuberoot challenge - MLQ436-0
'Harry Hardjono
'June 2012
'Just a 10 minute quickie
Loop:
TextWindow.Write("Enter a number (1-1000): ")
N=TextWindow.ReadNumber()
If N=0 Then
Program.End()
EndIf
D=1000 'Delta. Decreasing range in calcloop.
S=1 'Starting number. To be modified in calcloop.
E=0.00000000001 ' Epsilon. Desired accuracy.
calcloop:
While (D>E)
C=(S+D)*(S+D)*(S+D)
If C<=N Then
S=S+D
Else 'Not comfortable skipping else when D isn't a power of two.
D=D/2
EndIf
EndWhile
TextWindow.Write("Cube root is: ")
TextWindow.WriteLine(S)
TextWindow.WriteLine(" ")
Goto Loop
Tuesday, June 12, 2012
Small Basic Spell Checker
'Spell checker example - wxv722-1
'Uses Dictionary.GetDefinition(word) - Need internet access
'Harry Hardjono
'June 2012
'
Init:
Str="abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Word=""
Loop:
TextWindow.BackgroundColor="black"
TextWindow.ForegroundColor="white"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("Enter your sentence: ")
inputtext=text.Append(TextWindow.Read()," ") 'bug fix. ^_^;
If (inputtext=" ") Then
Goto End
EndIf
For i=1 To Text.GetLength(inputtext)
curchar=Text.GetSubText(inputtext,i,1)
If (Text.GetIndexOf(Str,curchar)=0) Then
'Not word
If (Word<>"") Then
WordDef=Dictionary.GetDefinition(Word)
If (WordDef="") Then
TextWindow.BackgroundColor="white"
TextWindow.ForegroundColor="black"
TextWindow.Write(Word)
TextWindow.BackgroundColor="black"
TextWindow.ForegroundColor="white"
Else
TextWindow.Write(Word)
EndIf
Word=""
EndIf
TextWindow.Write(curchar)
Else 'Word
Word=Text.Append(Word,curchar)
EndIf
endfor
Goto Loop
End:
Program.End()
Tuesday, June 5, 2012
Poker Hand Probabilities using nCr
'Poker probabilities - ZFS003-0
'Harry Hardjono
'May 2012
'
' Verified: Royal Flush, Flush
'I wonder why the probabilities don't match?
'
'
'All cards possibilities
S=52*51*50*49*48
TextWindow.WriteLine("All Card Possibilities: "+S)
'Royal Flush
P=20*4*3*2*1
TextWindow.WriteLine("Royal Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Straight Flush
P=32*4*3*2*1
TextWindow.WriteLine("Straight Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Four of a Kind
P=52*3*2*1*48
TextWindow.WriteLine("Four of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Full House
P=52*3*2*48*3
TextWindow.WriteLine("Full House: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Flush
P=52*12*11*10*9
TextWindow.WriteLine("Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Straight
P=52*16*12*8*4
TextWindow.WriteLine("Straight: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Three of a Kind
P=52*3*2*48*44
TextWindow.WriteLine("Three of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Two Pair
P=52*3*48*3*44
TextWindow.WriteLine("Two Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'One Pair
P=52*3*48*44*42
TextWindow.WriteLine("One Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'High Card
P=52*48*44*42*38
TextWindow.WriteLine("High Card: 1 in "+Math.Round(S/P)+" "+(P*100/S))
TextWindow.WriteLine(" ")
TextWindow.WriteLine("These combinations are verified on Wiki")
'Combination
N=52
R=5
nCr()
S=C
TextWindow.WriteLine("Combination: "+C+" ")
'Royal Flush
N=4
R=1
nCr()
TextWindow.WriteLine("Royal Flush: 1 in "+Math.Round(S/C)+" "+(C*100/S))
'Straight Flush
ArrN="1=10;2=4;3=4;"
ArrR="1=1;2=1;3=1;"
MultinCr()
P=(ArrC[1]*ArrC[2])-ArrC[3]
TextWindow.WriteLine("Straight Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Four of a Kind
ArrN="1=13;2=12;3=4;"
ArrR="1=1;2=1;3=1;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[3])
TextWindow.WriteLine("Four of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Full House
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=3;3=1;4=2;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4])
TextWindow.WriteLine("Full House: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Flush
ArrN="1=13;2=4;3=10;4=4;"
ArrR="1=5;2=1;3=1;4=1;"
MultinCr()
P=(ArrC[1]*ArrC[2])-(ArrC[3]*ArrC[4])
TextWindow.WriteLine("Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Straight
ArrN="1=10;2=4;3=10;4=4;"
ArrR="1=1;2=1;3=1;4=1;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[2]*ArrC[2]*ArrC[2]*ArrC[2])-(ArrC[3]*ArrC[4])
TextWindow.WriteLine("Straight: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Three of a Kind
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=3;3=2;4=1;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4]*ArrC[4])
TextWindow.WriteLine("Three of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Two Pair
ArrN="1=13;2=4;3=11;4=4;"
ArrR="1=2;2=2;3=1;4=1;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[2]*ArrC[3]*ArrC[4])
TextWindow.WriteLine("Two Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'One Pair
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=2;3=3;4=1;"
MultinCr()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4]*ArrC[4]*ArrC[4])
TextWindow.WriteLine("One Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'High Card
ArrN="1=13;2=10;3=4;4=4;"
ArrR="1=5;2=1;3=1;4=1;"
MultinCr()
P=(ArrC[1]-ArrC[2])*(ArrC[3]*ArrC[3]*ArrC[3]*ArrC[3]*ArrC[3]-ArrC[4])
TextWindow.WriteLine("High Card: 1 in "+Math.Round(S/P)+" "+(P*100/S))
Sub MultinCr
For m=1 To Array.GetItemCount(ArrN)
N=ArrN[m]
R=ArrR[m]
nCr()
ArrC[m]=C
EndFor
endsub
'nCr = (n!)/(r!*(n-r)!)
Sub nCr
'N (input)
'R (input)
C=1 '(output)
For i=Math.Max(R,(N-R))+1 To N
C=C*i
EndFor
For i=1 To Math.Min(R,(N-R))
C=C/i
EndFor
EndSub
TextWindow.WriteLine(" ")
TextWindow.WriteLine("These combinations are verified on Wiki")
'Combination
N=52
R=5
nCr2()
S=C
TextWindow.WriteLine("Combination: "+C+" ")
'Royal Flush
N=4
R=1
nCr2()
TextWindow.WriteLine("Royal Flush: 1 in "+Math.Round(S/C)+" "+(C*100/S))
'Straight Flush
ArrN="1=10;2=4;3=4;"
ArrR="1=1;2=1;3=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2])-ArrC[3]
TextWindow.WriteLine("Straight Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Four of a Kind
ArrN="1=13;2=12;3=4;"
ArrR="1=1;2=1;3=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[3])
TextWindow.WriteLine("Four of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Full House
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=3;3=1;4=2;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4])
TextWindow.WriteLine("Full House: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Flush
ArrN="1=13;2=4;3=10;4=4;"
ArrR="1=5;2=1;3=1;4=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2])-(ArrC[3]*ArrC[4])
TextWindow.WriteLine("Flush: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Straight
ArrN="1=10;2=4;3=10;4=4;"
ArrR="1=1;2=1;3=1;4=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[2]*ArrC[2]*ArrC[2]*ArrC[2])-(ArrC[3]*ArrC[4])
TextWindow.WriteLine("Straight: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Three of a Kind
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=3;3=2;4=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4]*ArrC[4])
TextWindow.WriteLine("Three of a Kind: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'Two Pair
ArrN="1=13;2=4;3=11;4=4;"
ArrR="1=2;2=2;3=1;4=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[2]*ArrC[3]*ArrC[4])
TextWindow.WriteLine("Two Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'One Pair
ArrN="1=13;2=4;3=12;4=4;"
ArrR="1=1;2=2;3=3;4=1;"
MultinCr2()
P=(ArrC[1]*ArrC[2]*ArrC[3]*ArrC[4]*ArrC[4]*ArrC[4])
TextWindow.WriteLine("One Pair: 1 in "+Math.Round(S/P)+" "+(P*100/S))
'High Card
ArrN="1=13;2=10;3=4;4=4;"
ArrR="1=5;2=1;3=1;4=1;"
MultinCr2()
P=(ArrC[1]-ArrC[2])*(ArrC[3]*ArrC[3]*ArrC[3]*ArrC[3]*ArrC[3]-ArrC[4])
TextWindow.WriteLine("High Card: 1 in "+Math.Round(S/P)+" "+(P*100/S))
Sub MultinCr2
For m=1 To Array.GetItemCount(ArrN)
N=ArrN[m]
R=ArrR[m]
nCr2()
ArrC[m]=C
EndFor
endsub
'nCr = (n!)/(r!*(n-r)!)
Sub nCr2
'N (input)
'R (input)
C=N '(output)
For i=2 To Math.Min(R,(N-R))
C=C*(N-(i-1))/i
EndFor
EndSub
Monday, June 4, 2012
Wario Ware DIY Review (short version)
Originally posted on Amazon.com. I figure I'll need to refer to the game development steps later. A more complete review is at Amazon.com
The designers have selected a very clever set of instructions. These aren't the traditional game development algorithm set, but they do provide most of the capabilities desired. There are some instructions missing. Namely "Tap Screen" can use area parameter, and "Switch object" can use "Switch OTHER object". You can do a work-around the limitation, so those aren't strictly necessary, but the designers sure miss an easy way to define Hotspots, IMHO.The package does provide all that a game designer needs. Namely, screen and objects, paint program, music program, storyboard (actually comic strip, but who's nit-picking?), and distribution channel. All you game designers wannabe, this is your chance to have your creation showcased to the world!
I managed to re-create my very first computer game (Cowboy shoots red dots) on the Amiga. The difference is, instead of 12 hours of work, on WarioWare DIY, it was only 1.5 hours, graphic included! Even though the options and animation are necessarily more limited, I daresay that the fun level is quite high! This is the natural result from the ever-increasing game speed as the play progressed. Granted, the design is fixed, and that is the hardest thing, but still, 1.5 hours! Including learning the package? I'm getting sick. I wish I had this "game" then!
My usual step is:
1. Idea (I use comic strip program provided)
2. Technical (Objects, AI, and programmer's art)
3. Presentation (Better graphics, color, animation)
4. Sound and Music (I use automatic music generation, and fiddle it a bit)
5. Playtesting (As a complete game)
6. Refinement (Trying out different ideas)
As you probably can tell, those steps are usually fielded by different hats. They are: Game Designer, Programmer, Artist, Musician, Play-tester, User (feedback). The really nice thing about this, is that you do not have to be everyone. Thanks to the sharing feature, you can choose to be an artist only, and draw graphics (Wario jobs). Or you can be a programmer (Advanced Dojo Skill). Or perhaps a game designer with great idea (comic strip as storyboard). Maybe you're just an avid gamer, and want to participate in game evaluation and give feedback? Friend code and Wii Showcase.
You can also use the sharing feature as a "Save" feature. I know I have modified a game several times, after I shipped it. Also, I have no hesitation to provide a game filled with programmer's art (colored boxes, really) knowing that somebody with a better artistic skill can put good graphics. Perhaps some comic book artist who don't know how to program, but want to put his characters in a game? Done!
More importantly, I think that this is a great program to share among friends. You are not limited to just games, after all. How about animated greeting cards? Or a Jack-in-a-Box surprise? Vocabulary builder type of games? Math skills? The sky is the limit.
Subscribe to:
Posts (Atom)