私はMartingaleの戦略をテストするためのアプリケーションを作ったが、実行中に私のアプリでこの厄介な例外が発生している。テストのためのループ内でStackOverflowExceptionを取得する
完全なアプリケーションコード:
If roll > rollunder Then
'Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("LOSE - " & roll & " - Bet: " & bet) *** HERE!
'Console.ResetColor()
balance -= bet
bet = bet * increaseby
Console.Title = "Martingale Sim - Balance: " & balance
Else
'Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("WIN - " & roll & " - Bet: " & bet) *** HERE!
'Console.ResetColor()
balance += bet
bet = basebet
Console.Title = "Martingale Sim - Balance: " & balance
End If
Threading.Thread.Sleep(sleep)
checkRoll()
私はこれがために起こることを承知している:
モジュールModule1が
Dim basebet, balance, rollunder, sleep As Integer
Dim increaseby As Decimal
Dim bet As Decimal
Dim confTarget As Integer
Sub Main()
bootConf()
Menu()
End Sub
Sub bootConf()
basebet = 1 '1 Base Bet
bet = 1 'Current Bet
increaseby = 3 'Multiplier on loss
balance = 50000 '100 Starting Balance
rollunder = 4998 '1% House Edge
sleep = 50 'Sleep between bets in MS
End Sub
Sub basebetConf(ByVal newVal As Integer)
basebet = newVal
Conf()
End Sub
Sub increasebyConf(ByVal newVal As Integer)
increaseby = newVal
Conf()
End Sub
Sub balanceConf(ByVal newVal As Integer)
balance = newVal
Conf()
End Sub
Sub rollunderConf(ByVal newVal As Integer)
If newVal > 4999 Then
Conf()
ElseIf newVal < 1 Then
Conf()
Else
rollunder = newVal
Conf()
End If
End Sub
Sub sleepConf(ByVal newVal As Integer)
sleep = newVal
Conf()
End Sub
Sub Conf()
Console.Clear()
Console.WriteLine("")
Console.WriteLine(" Martingale Simulator")
Console.WriteLine(" Developed by Art3mis")
Console.WriteLine("")
Console.WriteLine(" CONFIGURATION")
Console.WriteLine(" ¯¯¯¯¯¯¯¯¯¯¯¯¯")
Console.WriteLine(" BASE BET : " & basebet)
Console.WriteLine(" LOSE MULTIPLIER : " & increaseby)
Console.WriteLine(" BASE BALANCE : " & balance)
Console.WriteLine(" ROLLUNDER (0-5000) : " & rollunder)
Console.WriteLine(" SLEEP (IN MILLISEC) : " & sleep)
Console.WriteLine("")
Console.WriteLine(" Select value to edit (1-5)")
Console.WriteLine(" Press X to return.")
Console.Write(" > ")
Dim input As ConsoleKeyInfo = Console.ReadKey()
If input.Key = ConsoleKey.D1 Then
confTarget = 1
ElseIf input.Key = ConsoleKey.D2 Then
confTarget = 2
ElseIf input.Key = ConsoleKey.D3 Then
confTarget = 3
ElseIf input.Key = ConsoleKey.D4 Then
confTarget = 4
ElseIf input.Key = ConsoleKey.D5 Then
confTarget = 5
ElseIf input.Key = ConsoleKey.X Then
Menu()
Else
Conf()
End If
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine(" Enter new value")
Console.WriteLine(" Press X to return.")
Console.Write(" > ")
Dim input2 As Integer = Console.ReadLine()
If confTarget = 1 Then
basebetConf(input2)
ElseIf confTarget = 2 Then
increasebyConf(input2)
ElseIf confTarget = 3 Then
balanceConf(input2)
ElseIf confTarget = 4 Then
rollunderConf(input2)
ElseIf confTarget = 5 Then
sleepConf(input2)
End If
'Console.Read()
End Sub
Sub Menu()
Console.Clear()
Console.WriteLine("")
Console.WriteLine(" Martingale Simulator")
Console.WriteLine(" Developed by Art3mis")
Console.WriteLine("")
Console.WriteLine(" ╔═ MENU ═════════════════╗")
Console.WriteLine(" ╠═ 1 : START ║")
Console.WriteLine(" ╠═ 2 : CONFIGURATION ║")
Console.WriteLine(" ╠═ 3 : ABOUT & CREDITS ║")
Console.WriteLine(" ╚════════════════════════╝")
Console.Write(" > ")
Dim input As ConsoleKeyInfo = Console.ReadKey()
If input.Key = ConsoleKey.D1 Then
Console.Clear()
Console.WriteLine("")
Console.WriteLine(" Martingale Simulator")
Console.WriteLine(" Developed by Art3mis")
Console.WriteLine("")
Roll()
ElseIf input.Key = ConsoleKey.D2 Then
Conf()
ElseIf input.Key = ConsoleKey.D3 Then
About()
Else
Menu()
End If
End Sub
Sub Roll()
Dim rn As New Random
Dim roll As Integer
roll = rn.Next(0, 10000)
If roll > rollunder Then
'Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("LOSE - " & roll & " - Bet: " & bet)
'Console.ResetColor()
balance -= bet
bet = bet * increaseby
Console.Title = "Martingale Sim - Balance: " & balance
Else
'Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("WIN - " & roll & " - Bet: " & bet)
'Console.ResetColor()
balance += bet
bet = basebet
Console.Title = "Martingale Sim - Balance: " & balance
End If
Threading.Thread.Sleep(sleep)
checkRoll()
End Sub
Sub checkRoll()
If balance < 0 Then
MsgBox("Ran out of balance.")
Else
Roll()
End If
End Sub
Sub About()
End Sub
End Module
ここでは、アプリケーションが失敗し、例外をスロースポットですそれは無限ループです。私はこの状況で私を助けるために何かを見つけませんでしたので、私は本当に何をすべきか分かりません。事前にhttp://prntscr.com/aw7mqd
ありがとう:
は、ここでバグを示すスクリーンショットです!
'ロール()(条件は、彼らはほとんど毎回である、正しいですか?)'() ''ロール() '' checkRollを呼び出して呼び出している '' checkRoll()呼び出しています。あなたは 'while(true){roll();のような無限ループを持つ関数を持っているので、呼び出しを再構成する必要があります。 if(balance <0)break;} 'を呼び出し、' roll() 'の中で' checkRoll() 'を呼び出します。これは、 'roll()'がそれ以降呼び出されることなく再度呼び出されるので、無限の再帰問題を解決します。問題は、あなたが作るすべての 'CALL'でスタックが成長し、séごとに無限ループではなくなることです。 –