C# :: Aufgabe #185
3 Lösungen

Wetteinsatzstrategien: statisch, martingal, reverse-martingal oder Fibonacci
Fortgeschrittener - C#
von hollst
- 18.07.2017 um 09:49 Uhr
Bei zweiwertigen Wettspielen wie bspw. Münzwerfen (Kopf/Zahl), Roulette (Rot/Blau) oder Würfeln (gerade Zahl/ungerade Zahl) gibt es verschiedene Strategien zum Setzen des Einsatzes, um eingefahrenen Verlust so schnell wie möglich wieder zurückzuholen. Neben der statischen Strategie, d. h. man setzt in jeder Runde immer auf das gleiche Ereignis, sind die bekanntesten Strategien die martingale, die reverse-martingale und die Fibonacci-Strategie.
Die martingale Strategie sollte in der Praxis immer zu einem Gewinn führen, allerdings bräuchte man dafür unbegrenzte Ressourcen in der Hinterhand und einen Gegener (die Bank), der sich darauf einlässt. Die Strategie geht wie folgt: Hat man in einer Runde verloren, so setzt man in der Folgerunde den doppelten Einsatz. Die Hoffnung ist, dass man keine zu lang anhaltende Pechstähne hat und irgendwann auch einmal gewinnt. In diesem Falle hat man unter dem Strich genau seinen Starteinsatz gewonnen. Allerdings sind eiserne Nerven notwendig. Gehen wir einmal davon aus, dass wir mit dem Starteinsatz von einem EURO begonnen haben und zehnmal hintereinander verloren (1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 = 1.023), also bereits bei einem Spielstand von -1.023 EURO stehen. Für den elften Versuch müssten wir 1.024 EURO setzen mit der Perspektive, bei einem Gewinn unter dem Strich genau einen einzigen EURO gewonnen zu haben oder bei Verlust auf dann -2.047 EURO zu sitzen. Mindestens an dieser Stelle würde die Bank das Spiel sicher auch abbrechen.
Bei der reverse-martingalen Strategie geht man ganau anders herum vor: Bei einem Verlust setzt man immer wieder den gleichen Startbetrag (sagen wir wieder einen EURO). Bei einem Gewinn hofft man, dass dies der Beginn einer kleinen Glückssträhne ist und wir verdoppeln für die nächste Wettrunde den Einsatz. Die Länge dieser Strähne muss allerdings zuvor festgelegt worden sein, nehmen wir bspw. fünf an. Ist sie eingetroffen, dann beginnen wir wieder mit dem Starteinsatz und streichen die hier z. B. insgesamt gewonnenen 31 EURO ein. Bei der reverse-martingalen Strategie führt ein Rundenverlust immer nur zum Verlust des Starteinsatzes (ein EURO) u. z. auch dann nur, wenn die angestrebte Gewinnserie z. B. erst mit der letzten Wette (fünften) zerstört worden ist.
Bei der Fibonacci-Strategie folgt man bzgl. des Wetteinsatzes der Fibonaccireihe (1, 1, 2, 3, 5, 8, 13, 21, 34 …). Man startet bei 1 und im Falle eines oder mehrerer Verluste geht man jeweils einen Schritt weiter in der Folge. Der Wetteinsatz ist dann das Produkt des Starteinsatzes (ein EURO) mit der entsprechenden Fibonaccizahl. Im Gewinnfall geht man zwei Glieder in der Reihe zurück. Das wird solange wiederholt, bis man vor dem ersten Glied landet. Man hat dann wie bei der martingale Strategie genau den Starteinsatz gewonnen. Allerdings ist eine längere Pechstähne nicht so katastrophal wie beim „Martingale“, man bleibt mit der Fibonacci-Strategie in der Regel „länger am Leben“.
Ohne tiefer auf die Vor- und Nachteile der Setzstrategien einzugehen (im wahren Leben werdet ihr mit keiner davon auf Dauer wirklich reich werden können) soll die Programmieraufgabe darin bestehen, alle vier Strategien zu simulieren und statistisch zu bewerten. Folgendes sei vereinbart: Wir starten eine Serie immer mit einem EURO. In der Hinterhand (Startkapital) haben wir z. B. 100 EURO. Eine Serie sei dann beendet, wenn wir entweder alles verloren haben oder mindestens das doppelte Startkapital auf dem Konto haben. Sollten wir bei einer Wette nicht mehr den geforderten Einsatz zur Verfügung haben, so setzen wir soviel, wie noch auf dem Konto ist. Maximal soll eine Wettserie über 1.000 Runden gehen. Unsere Gewinn-/Verlustwahrscheinlichkeit soll variabel zwischen 40 % und 60 % liegen, bei einer Serie allerdings jeweils konstant bleiben.
In den beigefügten Bildern ist exemplarisch dargestellt, wie eine Wettserie im zeitlichen Verlauf etwa aussehen könnte. Das Startkapital war hier auf 1.024 EURO festgelegt worden.
Die martingale Strategie sollte in der Praxis immer zu einem Gewinn führen, allerdings bräuchte man dafür unbegrenzte Ressourcen in der Hinterhand und einen Gegener (die Bank), der sich darauf einlässt. Die Strategie geht wie folgt: Hat man in einer Runde verloren, so setzt man in der Folgerunde den doppelten Einsatz. Die Hoffnung ist, dass man keine zu lang anhaltende Pechstähne hat und irgendwann auch einmal gewinnt. In diesem Falle hat man unter dem Strich genau seinen Starteinsatz gewonnen. Allerdings sind eiserne Nerven notwendig. Gehen wir einmal davon aus, dass wir mit dem Starteinsatz von einem EURO begonnen haben und zehnmal hintereinander verloren (1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 = 1.023), also bereits bei einem Spielstand von -1.023 EURO stehen. Für den elften Versuch müssten wir 1.024 EURO setzen mit der Perspektive, bei einem Gewinn unter dem Strich genau einen einzigen EURO gewonnen zu haben oder bei Verlust auf dann -2.047 EURO zu sitzen. Mindestens an dieser Stelle würde die Bank das Spiel sicher auch abbrechen.
Bei der reverse-martingalen Strategie geht man ganau anders herum vor: Bei einem Verlust setzt man immer wieder den gleichen Startbetrag (sagen wir wieder einen EURO). Bei einem Gewinn hofft man, dass dies der Beginn einer kleinen Glückssträhne ist und wir verdoppeln für die nächste Wettrunde den Einsatz. Die Länge dieser Strähne muss allerdings zuvor festgelegt worden sein, nehmen wir bspw. fünf an. Ist sie eingetroffen, dann beginnen wir wieder mit dem Starteinsatz und streichen die hier z. B. insgesamt gewonnenen 31 EURO ein. Bei der reverse-martingalen Strategie führt ein Rundenverlust immer nur zum Verlust des Starteinsatzes (ein EURO) u. z. auch dann nur, wenn die angestrebte Gewinnserie z. B. erst mit der letzten Wette (fünften) zerstört worden ist.
Bei der Fibonacci-Strategie folgt man bzgl. des Wetteinsatzes der Fibonaccireihe (1, 1, 2, 3, 5, 8, 13, 21, 34 …). Man startet bei 1 und im Falle eines oder mehrerer Verluste geht man jeweils einen Schritt weiter in der Folge. Der Wetteinsatz ist dann das Produkt des Starteinsatzes (ein EURO) mit der entsprechenden Fibonaccizahl. Im Gewinnfall geht man zwei Glieder in der Reihe zurück. Das wird solange wiederholt, bis man vor dem ersten Glied landet. Man hat dann wie bei der martingale Strategie genau den Starteinsatz gewonnen. Allerdings ist eine längere Pechstähne nicht so katastrophal wie beim „Martingale“, man bleibt mit der Fibonacci-Strategie in der Regel „länger am Leben“.
Ohne tiefer auf die Vor- und Nachteile der Setzstrategien einzugehen (im wahren Leben werdet ihr mit keiner davon auf Dauer wirklich reich werden können) soll die Programmieraufgabe darin bestehen, alle vier Strategien zu simulieren und statistisch zu bewerten. Folgendes sei vereinbart: Wir starten eine Serie immer mit einem EURO. In der Hinterhand (Startkapital) haben wir z. B. 100 EURO. Eine Serie sei dann beendet, wenn wir entweder alles verloren haben oder mindestens das doppelte Startkapital auf dem Konto haben. Sollten wir bei einer Wette nicht mehr den geforderten Einsatz zur Verfügung haben, so setzen wir soviel, wie noch auf dem Konto ist. Maximal soll eine Wettserie über 1.000 Runden gehen. Unsere Gewinn-/Verlustwahrscheinlichkeit soll variabel zwischen 40 % und 60 % liegen, bei einer Serie allerdings jeweils konstant bleiben.
In den beigefügten Bildern ist exemplarisch dargestellt, wie eine Wettserie im zeitlichen Verlauf etwa aussehen könnte. Das Startkapital war hier auf 1.024 EURO festgelegt worden.
Lösungen:
MainWindow.xaml.cs
C#-Code
MainWindow.xaml
XML-Code

using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; using System.Windows.Shapes; namespace WpfWetteinsatz { /// <summary> /// Interaktionslogik für MainWindow.xaml /// </summary> public partial class MainWindow : Window { private static readonly Random rnd = new Random(); private SolidColorBrush brushStatic; private SolidColorBrush brushMartingal; private SolidColorBrush brushReverseMartingal; private SolidColorBrush brushFibonacci; private double SKX, SKY; private Point ZeroPoint; private Simulation[] simulation; public MainWindow() { InitializeComponent(); brushStatic = (SolidColorBrush)Application.Current.MainWindow.FindResource("brushStatic"); brushMartingal = (SolidColorBrush)Application.Current.MainWindow.FindResource("brushMartingal"); brushReverseMartingal = (SolidColorBrush)Application.Current.MainWindow.FindResource("brushReverseMartingal"); brushFibonacci = (SolidColorBrush)Application.Current.MainWindow.FindResource("brushFibonacci"); } private bool InitGrid(out int rounds, out int budget, out double p, out int luck) { canvasChart.Children.Clear(); simulationDataGrid.Items.Refresh(); bool b = int.TryParse(textBoxMaxRound.Text, out rounds) && int.TryParse(textBoxStartCapital.Text, out rounds) && double.TryParse(textBoxP.Text, out p) && int.TryParse(textBoxLuck.Text, out luck); if (!b) { rounds = 0; budget = 0; p = 0; luck = 0; return false; } rounds = int.Parse(textBoxMaxRound.Text); budget = int.Parse(textBoxStartCapital.Text); p = double.Parse(textBoxP.Text) / 100.0; luck = int.Parse(textBoxLuck.Text); canvasChart.UpdateLayout(); SKX = canvasChart.ActualWidth / rounds; SKY = canvasChart.ActualHeight / (2.0 * budget); ZeroPoint = new Point(0, canvasChart.ActualHeight / 2); Line mid = new Line() { X1 = 0, X2 = canvasChart.ActualWidth, Y1 = canvasChart.ActualHeight / 2, Y2 = canvasChart.ActualHeight / 2, Stroke = Brushes.Black, StrokeThickness = 2 }; canvasChart.Children.Add(mid); return true; } private Point GetPoint(double X, double Y) { Point P = new Point(); P.X = ZeroPoint.X + X * SKX; P.Y = ZeroPoint.Y - Y * SKY; return P; } private bool SimulateGame(double winChance) { double d = rnd.NextDouble(); return d <= winChance; } private void buttonStart_Click(object sender, RoutedEventArgs e) { int round, budget, luck; double p; simulation = new Simulation[0]; if (InitGrid(out round, out budget, out p, out luck)) { simulation = new Simulation[round]; for (int i = 0; i < simulation.Length; i++) { simulation[i] = new Simulation() { Wins = SimulateGame(p), Round = i + 1 }; } SimulateStatic(budget); SimulateMartingal(budget); SimulateReverseMartingal(budget, luck); SimulateFibonacci(budget); } System.Windows.Data.CollectionViewSource simulationViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("simulationViewSource"))); simulationViewSource.Source = simulation; simulationDataGrid.Items.Refresh(); } private void SimulateStatic(int budget) { Point last = new Point(ZeroPoint.X, ZeroPoint.Y); int money = budget; int bet = 1; for (int i = 0; i < simulation.Length; i++) { if (money >= budget * 2 || money <= 0) { simulation[i].WinStatisch = i - 1 >= 0 ? simulation[i - 1].WinStatisch : 0; continue; } if (simulation[i].Wins) { money += money > bet ? bet : money; } else { money -= money > bet ? bet : money; } int win = money - budget; simulation[i].WinStatisch = win; Point p = GetPoint(i, win); Line l = new Line() { X1 = last.X, Y1 = last.Y, X2 = p.X, Y2 = p.Y, Stroke = brushStatic, StrokeThickness = 1 }; canvasChart.Children.Add(l); last = p; } } private void SimulateMartingal(int budget) { Point last = new Point(ZeroPoint.X, ZeroPoint.Y); int money = budget; int bet = 1; for (int i = 0; i < simulation.Length; i++) { if (money >= budget * 2 || money <= 0) { simulation[i].WinMartingal = i - 1 >= 0 ? simulation[i - 1].WinMartingal : 0; continue; } if (simulation[i].Wins) { money += money > bet ? bet : money; bet = 1; } else { money -= money > bet ? bet : money; bet *= 2; } int win = money - budget; simulation[i].WinMartingal = win; Point p = GetPoint(i, win); Line l = new Line() { X1 = last.X, Y1 = last.Y, X2 = p.X, Y2 = p.Y, Stroke = brushMartingal, StrokeThickness = 1 }; canvasChart.Children.Add(l); last = p; } } private void SimulateReverseMartingal(int budget, int luck) { Point last = new Point(ZeroPoint.X, ZeroPoint.Y); int money = budget; int bet = 1; int c = 0; for (int i = 0; i < simulation.Length; i++) { if (money >= budget * 2 || money <= 0) { simulation[i].WinReverseMartingal = i - 1 >= 0 ? simulation[i - 1].WinReverseMartingal : 0; continue; } if (simulation[i].Wins) { money += money > bet ? bet : money; bet *= 2; c++; if (c >= luck) { bet = 1; } } else { money -= money > bet ? bet : money; bet = 1; } int win = money - budget; simulation[i].WinReverseMartingal = win; Point p = GetPoint(i, win); Line l = new Line() { X1 = last.X, Y1 = last.Y, X2 = p.X, Y2 = p.Y, Stroke = brushReverseMartingal, StrokeThickness = 1 }; canvasChart.Children.Add(l); last = p; } } private void SimulateFibonacci(int budget) { Point last = new Point(ZeroPoint.X, ZeroPoint.Y); int money = budget; int bet = 1; List<int> fibonacci = CreateFibonacciList(budget); int index = 0; for (int i = 0; i < simulation.Length; i++) { if (money >= budget * 2 || money <= 0) { simulation[i].WinFibonacci = i - 1 >= 0 ? simulation[i - 1].WinFibonacci : 0; continue; } int temp = bet; if (simulation[i].Wins) { money += money > bet ? bet : money; index -= 2; if (index < 0) { index = 1; } bet = fibonacci[index]; } else { money -= money > bet ? bet : money; bet = fibonacci[++index]; } int win = money - budget; simulation[i].WinFibonacci = win; Point p = GetPoint(i, win); Line l = new Line() { X1 = last.X, Y1 = last.Y, X2 = p.X, Y2 = p.Y, Stroke = brushFibonacci, StrokeThickness = 1 }; canvasChart.Children.Add(l); last = p; } } private static List<int> CreateFibonacciList(int max) { List<int> fibonacci = new List<int>() { 1, 1 }; int i = 0; while (fibonacci.Last() <= max) { fibonacci.Add(fibonacci.Skip(i++).Take(2).Sum()); } return fibonacci; } } class Simulation { public int Round { get; set; } public int WinStatisch { get; set; } public int WinMartingal { get; set; } public int WinReverseMartingal { get; set; } public int WinFibonacci { get; set; } public bool Wins { get; set; } } }
MainWindow.xaml

<Window x:Class="WpfWetteinsatz.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfWetteinsatz" mc:Ignorable="d" Title="MainWindow" Height="448" Width="843" Background="AliceBlue" ResizeMode="CanMinimize"> <Window.Resources> <SolidColorBrush x:Key="brushStatic" Color="Blue"/> <SolidColorBrush x:Key="brushMartingal" Color="Red"/> <SolidColorBrush x:Key="brushReverseMartingal" Color="Green"/> <SolidColorBrush x:Key="brushFibonacci" Color="Yellow"/> <CollectionViewSource x:Key="simulationViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Simulation}, CreateList=True}"/> </Window.Resources> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <Grid DataContext="{StaticResource simulationViewSource}"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Grid Grid.Column="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <TextBox x:Name="textBoxMaxRound" Width="50" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="114,13,0,0" Text="1000" TextAlignment="Center"/> <TextBox x:Name="textBoxStartCapital" Width="50" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="114,37,0,0" Text="1000" TextAlignment="Center"/> <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="10,40,0,0" TextWrapping="Wrap" Text="Startkapital" VerticalAlignment="Top"/> <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="10,13,0,0" TextWrapping="Wrap" Text="Runden" VerticalAlignment="Top"/> <Button x:Name="buttonStart" Content="Start" HorizontalAlignment="Left" Margin="10,120,0,0" VerticalAlignment="Top" Width="154" Click="buttonStart_Click"/> <TextBox x:Name="textBoxP" HorizontalAlignment="Left" Height="23" Margin="114,64,19,0" TextWrapping="Wrap" Text="50" VerticalAlignment="Top" Width="50" TextAlignment="Center"/> <TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="10,67,0,0" TextWrapping="Wrap" Text="Wahrscheinlichkeit" VerticalAlignment="Top"/> <TextBox x:Name="textBoxLuck" HorizontalAlignment="Left" Height="23" Margin="114,92,0,0" TextWrapping="Wrap" Text="5" VerticalAlignment="Top" Width="50" TextAlignment="Center"/> <TextBlock x:Name="textBlock3" HorizontalAlignment="Left" Margin="10,95,0,0" TextWrapping="Wrap" Text="Glück" VerticalAlignment="Top"/> </Grid> <Grid Grid.Column="1"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal" Margin="10,10,0,0" Grid.Row="0"> <Ellipse Height="15" Width="15" Fill="{Binding Mode=OneWay, Source={StaticResource brushStatic}}"/> <TextBlock Text="Statisch" Margin="5,0,0,0"/> </StackPanel> <StackPanel Orientation="Horizontal" Margin="10,10,0,0" Grid.Row="1"> <Ellipse Height="15" Width="15" Fill="{Binding Mode=OneWay, Source={StaticResource brushMartingal}}"/> <TextBlock Text="Martingal" Margin="5,0,0,0"/> </StackPanel> <StackPanel Orientation="Horizontal" Margin="10,10,0,0" Grid.Row="2"> <Ellipse Height="15" Width="15" Fill="{Binding Mode=OneWay, Source={StaticResource brushReverseMartingal}}"/> <TextBlock Text="Reverse Martingal" Margin="5,0,0,0"/> </StackPanel> <StackPanel Orientation="Horizontal" Margin="10,10,0,0" Grid.Row="3"> <Ellipse Height="15" Width="15" Fill="{Binding Mode=OneWay, Source={StaticResource brushFibonacci}}"/> <TextBlock Text="Fibonacci" Margin="5,0,0,0"/> </StackPanel> </Grid> </Grid> <DataGrid x:Name="simulationDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="10" RowDetailsVisibilityMode="VisibleWhenSelected" Grid.Row="1" IsReadOnly="True"> <DataGrid.Columns> <DataGridTextColumn x:Name="roundColumn" Binding="{Binding Round}" Header="Runde" Width="SizeToHeader"/> <DataGridTextColumn x:Name="winStatischColumn" Binding="{Binding WinStatisch}" Header="Statisch" Width="SizeToHeader"/> <DataGridTextColumn x:Name="winMartingalColumn" Binding="{Binding WinMartingal}" Header="Martingal" Width="SizeToHeader"/> <DataGridTextColumn x:Name="winReverseMartingalColumn" Binding="{Binding WinReverseMartingal}" Header="Reverse Martingal" Width="SizeToHeader"/> <DataGridTextColumn x:Name="winFibonacciColumn" Binding="{Binding WinFibonacci}" Header="Fibonacci" Width="SizeToHeader"/> <DataGridCheckBoxColumn x:Name="winsColumn" Binding="{Binding Wins}" Header="Gewonnen" Width="SizeToHeader"/> </DataGrid.Columns> </DataGrid> </Grid> <Canvas x:Name="canvasChart" Grid.Column="1" Margin="10" Background="LightGray"/> </Grid> </Window>
Achtung: Für die grafischen Darstellungen ist die ZedGraph-Assembly einzubinden (oder man verzichtet auf Grafik)!
Außerdem sollte ein Ordner pics angelegt werden, der ein Imagefile namens feedback.png enthält (oder man streicht
den entsprechenden Teil im Code).
C#-Code
C#-Code
C#-Code
Außerdem sollte ein Ordner pics angelegt werden, der ein Imagefile namens feedback.png enthält (oder man streicht
den entsprechenden Teil im Code).

using System; using System.Text; using System.Windows; using System.Windows.Controls; using setzsysteme.fibo; namespace setzsysteme { public partial class MainWindow : Window { private static string NL = Environment.NewLine, LZ = " "; private SettingSytems ss; private double gewinngrenze;// = 0.48; private int startgeld = 1024; private int setzgeld = 10; private int max_steps = 100;//10 * 8 * 60 / 5; private Random r = new Random(); private ZedGraph.PointPairList[] LPointPairs;// = new List<PointPairList>(); private System.Drawing.Color[] SDC = new System.Drawing.Color[] { System.Drawing.Color.Black, System.Drawing.Color.Red, System.Drawing.Color.Green, System.Drawing.Color.Blue }; private string[] bezeichner = new string[] { " static ", " fibo ", " martingale ", " reverse m. " }; private bool[] bo_draw = new bool[] { true, true, true, true }; //new bool[] { false, true, true, false }; private bool bo_forminit = false; public MainWindow() { InitializeComponent(); Init_LPointPairs(); this.tb2.Text = ((int)25).FiboAmerican(); bt3_Click(null, null); this.bo_forminit = true; } private void bt1_Click(object sender, RoutedEventArgs e) { } private void bt_clear_Click(object sender, RoutedEventArgs e) { this.tb3.Clear(); DateTime dt = DateTime.Now; this.tb3.Text = "start: " + dt.ToShortDateString() + " " + dt.ToShortTimeString() + NL + NL; } int[] LB_content = new int[] {0, 0, 0, 0 }; int[] LB_counter = new int[] { 0, 0, 0, 0 }; int[] LB_content_bt4; int[] tf = new int[2]; private void bt2_Click(object sender, RoutedEventArgs e) { } private void InitGraph() { string[] sgewinngrenze = this.combo_prozent.SelectionBoxItem.ToString().Split(' '); this.gewinngrenze = int.Parse(sgewinngrenze[0]) * 0.01; DateTime dt = DateTime.Now; this.tb1.Clear(); this.tb2.Clear(); this.tb3.Text = " start: " + dt.ToShortDateString() + " " + dt.ToShortTimeString() + NL + NL; ss = new SettingSytems(startgeld, setzgeld, 32 * setzgeld, this.gewinngrenze, 1.0); tf = new int[2]; ClearGraph(); this.UpdateGraph(ss); LB_content = new int[] { 0, 0, 0, 0 }; LB_content_bt4 = new int[] { 0, 0, 0, 0 }; LB_counter = new int[] { 0, 0, 0, 0 }; this.glob_round_counter = 0; } private void bt3_Click(object sender, RoutedEventArgs e) // reset and start { if(!this.bo_run_from_bt5) InitGraph(); if (this.bo_forminit) { this.bo_run_for_ever = true; bo_draw = new bool[] { (bool)this.cb1.IsChecked, (bool)this.cb2.IsChecked, (bool)this.cb3.IsChecked, (bool)this.cb4.IsChecked }; do { this.ss = new SettingSytems(this.startgeld, this.setzgeld, 32 * this.setzgeld, this.gewinngrenze, 1.0); tf = new int[2]; System.Windows.Forms.Application.DoEvents(); this.bt4_Click(sender, e); this.glob_round_counter++; StringBuilder sb = new StringBuilder(glob_round_counter.ToString() + NL + NL); for (var i = 0; i < LB_content.Length; i++) { LB_content[i] += ss.spielstandgeld[i]; LB_counter[i] += ss.counter[i]; sb.AppendLine(LB_content[i].ToString()); } this.tb3.Text = sb.ToString(); tb3.Focus(); tb3.SelectionStart = tb3.Text.Length; tb3.ScrollToEnd(); System.Windows.Forms.Application.DoEvents(); } while (this.bo_run_for_ever); UpdateGraph(ss); } else this.host.Visibility = Visibility.Visible; } private void bt4_Click(object sender, RoutedEventArgs e) //run one circle { UpdateGraph(ss); StringBuilder sb = new StringBuilder(); for (var j = 0; j < max_steps; j++) { this.ss.run_one_step(); UpdateGraph(ss); if (ss.bo_win) tf[0]++; else tf[1]++; } for (var i = 0; i < LB_content.Length; i++) LB_content_bt4[i] += this.ss.spielstandgeld[i]; sb.Append( ss.counter.ToMyString() + tf.ToMyString(space: 8) + ss.pos.ToMyString() + ss.spielstandgeld.ToMyString(space: 6) + NL); tb2.Text += sb.ToString(); tb2.Focus(); tb2.SelectionStart = tb2.Text.Length; tb2.ScrollToEnd(); tb1.Text += LB_content_bt4.ToMyString() + LB_counter.ToMyString() + NL; tb1.Focus(); tb1.SelectionStart = tb2.Text.Length; tb1.ScrollToEnd(); } private bool bo_run_from_bt5 = false; private void bt5_Click(object sender, RoutedEventArgs e) // stop { this.bo_run_for_ever = !this.bo_run_for_ever; if (this.bo_run_for_ever) { bt5.Content = " STOP "; bo_run_from_bt5 = true; } else bt5.Content = " CONTINUE "; this.lb_info.Content = "bo_run_from_bt5: " + bo_run_from_bt5.ToString(); } int glob_round_counter;// = 0; public void warte() { int k = 0; for (var ii = 0; ii < int.MaxValue / 100; ii++) k += 1; } private void Init_LPointPairs() { this.LPointPairs = new ZedGraph.PointPairList[4]; for (var i = 0; i < 4; i++) this.LPointPairs[i] = new ZedGraph.PointPairList(); } private void combo_prozent_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (bo_loaded) { string[] sgewinngrenze = this.combo_prozent.SelectionBoxItem.ToString().Split(' '); this.gewinngrenze = int.Parse(sgewinngrenze[0]) * 0.01; ss.gewinngrenze = this.gewinngrenze; } } bool bo_loaded = false; private void Window_Loaded(object sender, RoutedEventArgs e) { bo_loaded = true; } private void ClearGraph() { this.graph.GraphPane.CurveList.Clear(); this.Init_LPointPairs(); } private bool bo_run_for_ever = false; private void UpdateGraph(SettingSytems ss) { this.host.Visibility = Visibility.Visible; this.graph.GraphPane.Title.Text = "Start: " + ss.startgeld[0].ToString("n0") + " P_Verlust: " + (100 * ss.gewinngrenze).ToString("0.00") + " % " + LZ + LZ + LB_content[0].ToString("n0") + LZ + LB_content[1].ToString("n0") + LZ + LB_content[2].ToString("n0") + LZ + LB_content[3].ToString("n0") + LZ + LZ + this.glob_round_counter.ToString("n0") + NL + LB_counter[0].ToString("n0") + LZ + LB_counter[1].ToString("n0") + LZ + LB_counter[2].ToString("n0") + LZ + LB_counter[3].ToString("n0") ; this.graph.GraphPane.Fill = new ZedGraph.Fill(System.Drawing.Color.FromArgb(222, 224, 212)); this.graph.GraphPane.Chart.Fill = new ZedGraph.Fill(System.Drawing.Color.FromArgb(255, 218, 185)); //http://www.mediaevent.de/tutorial/farbcodes.html String F = this.graph.GraphPane.XAxis.Title.FontSpec.Family; this.graph.GraphPane.YAxis.Title = new ZedGraph.AxisLabel(String.Empty, F, (float)12.0, System.Drawing.Color.Blue, false, false, false); this.graph.GraphPane.XAxis.Title = new ZedGraph.AxisLabel("Schritt (max = " + this.max_steps.ToString() + ")", F, (float)12.0,// 12.0, System.Drawing.Color.Blue, false, false, false); this.graph.GraphPane.XAxis.Scale.Min = 0.0; this.graph.GraphPane.XAxis.Scale.Max = this.max_steps + 1; double y_offset = 100; this.graph.GraphPane.YAxis.Scale.Max = ss.startgeld[0] + y_offset;// +0.0001;// 1.01 * this.max_value; this.graph.GraphPane.YAxis.Scale.Min = -(ss.startgeld[0] + y_offset);// -0.0001; //0.99 * this.min_value; this.graph.GraphPane.AxisChange(); if (ss.general_counter % (int)this.graph.GraphPane.XAxis.Scale.Max != 0) for (var i = 0; i < LPointPairs.Length; i++) LPointPairs[i].Add(ss.general_counter % (int)this.graph.GraphPane.XAxis.Scale.Max, ss.spielstandgeld[i]); else ClearGraph(); ZedGraph.SymbolType sbt = ZedGraph.SymbolType.None; this.graph.GraphPane.CurveList.Clear(); float linienstaerke = (float)3.0; for(var i = 0; i < LPointPairs.Length; i++) if(bo_draw[i]) { ZedGraph.LineItem myCurve = new ZedGraph.LineItem(this.bezeichner[i], this.LPointPairs[i], SDC[i], sbt, linienstaerke); myCurve.Line.StepType = ZedGraph.StepType.ForwardStep; this.graph.GraphPane.CurveList.Add(myCurve); } this.graph.Refresh(); } } public static class MyExtension { private static string LZ = " "; public static string Klammer(this string s) => " (" + s.ToString() + ") "; public static string Space(this String s, int chars) { string result = s; for (var i = s.Length; i < chars; i++) result = LZ + result; return result; } public static string ToMyString<T>(this T[] x, string klammerauf = "[", string trenner = " ", string klammerzu = "]", int space = 4) { StringBuilder sb = new StringBuilder(klammerauf); for (var i = 0; i < x.Length - 1; i++) sb.Append(x[i].ToString().Space(space) + trenner); sb.Append(x[x.Length - 1].ToString().Space(space) + klammerzu); return sb.ToString(); } } }

using System; using System.Text; using System.Windows; namespace setzsysteme.fibo { public class Class_Fibo { Random rand = new Random(); public Double mychance { get;} public int max_fibo { get; } public int mymax { get;} public int mymoney { get; set; } public int counter { get; set; } public int counter_win { get; set; } public bool bo_ready = false; public Class_Fibo(Double mychance = 0.51, int mymax = 100, int max_fibo = 8) { this.mychance = mychance; this.mymax = mymax; this.counter_win = 0; this.max_fibo = max_fibo; } public int fibo(int n) { int f0 = 1, f1 = 1, f = 1; if (n < 2) return 1; for(var i = 1; i < n; i++) { f0 = f1; f1 = f; f = f0 + f1; } return f; } public void run() { mymoney = mymax; counter = 0; int setze = 0; while ((mymoney > 0) && (mymoney < 2 * this.mymax) && (setze < max_fibo)) { int einsatz = fibo(setze); bool bo_win = rand.NextDouble() < this.mychance; counter++; if (bo_win) { mymoney += einsatz; setze -= 2; } else { mymoney -= einsatz; setze += 1; } if (setze < 0) setze = 1; } if (mymoney >= mymax) counter_win++; bo_ready = true; } } public static class MyDebugSamples { public static string FiboAmerican(this int biszu) { StringBuilder sb = new StringBuilder(); Class_Fibo cf = new Class_Fibo(); int q = 1; for(var i = 0; i < biszu; i++) { sb.AppendLine((i + 1).ToString().Space(4) + q.ToString("n0").Space(16) + cf.fibo(i).ToString("n0").Space(16)); q *= 2; } return sb.ToString(); } public static string FiboSequenze(out int counter, out int money, out int max_einsatz, int obergrenze, double verlustgrenze, Random r) { string NL = Environment.NewLine; StringBuilder sb = new StringBuilder(); sb.AppendLine(NL + "FiboSequenze"); Class_Fibo cf = new Class_Fibo(); int pos = 0, einsatz = cf.fibo(0), verlust = 0; counter = 1; money = 0; max_einsatz = 1; while ((pos >= 0) && (obergrenze > (einsatz - money))) { bool bo_win = r.NextDouble() >= verlustgrenze; einsatz = cf.fibo(pos); sb.Append(counter.ToString().Space(4) + ": act_pos = " + pos.ToString().Space(4) + " einsatz = " + einsatz.ToString().Space(4) + bo_win.ToString().Space(6)); if ((einsatz - money) > obergrenze) { string s = NL + " obergrenze erreicht " + obergrenze.ToString().Space(6) + einsatz.ToString().Space(6) + money.ToString().Space(6); MessageBox.Show(s); sb.AppendLine(s); break; } if (einsatz > max_einsatz) max_einsatz = einsatz; if (bo_win) { money += einsatz; verlust -= einsatz; pos -= 2; } else { money -= einsatz; verlust += einsatz; pos += 1; } sb.AppendLine( " money = " + money.ToString().Space(6) + " next_pos = " + pos.ToString().Space(4)); counter++; } if (pos >= 0) { string s = "serie stopps with pos: " + pos.ToString() + money.ToString().Space(6); sb.AppendLine(s); } sb.AppendLine("FiboSequenze ENDE (Zuwachs: " + money.ToString() + ")" + NL); return sb.ToString(); } public static string MartingaleSequenze(out int counter, out int money, out int max_einsatz, int obergrenze, double verlustgrenze, Random r) { string NL = Environment.NewLine; StringBuilder sb = new StringBuilder(); Class_Fibo cf = new Class_Fibo(); int pos = 0, einsatz = 1, verlust = 0; counter = 1; money = 0; max_einsatz = 1; while ((pos >= 0) && (obergrenze >= einsatz - money)) { bool bo_win = r.NextDouble() >= verlustgrenze; sb.Append(counter.ToString().Space(4) + ": act_pos = " + pos.ToString().Space(4) + " act_money = " + money.ToString().Space(6) + " bo_win = " + bo_win.ToString().Space(5)); einsatz = (int)Math.Pow(2, pos);// cf.fibo(pos); if (einsatz - money > obergrenze) { sb.AppendLine(NL + " obergrenze erreicht"); break; } if (einsatz > max_einsatz) max_einsatz = einsatz; if (bo_win) { money += einsatz; pos = -1; } else { money -= einsatz; verlust += einsatz; pos += 1; } sb.AppendLine( " new_pos = " + pos.ToString().Space(4) + " new_money = " + money.ToString().Space(6)); counter++; } return sb.ToString(); } public static string AntiMartingaleSequenze(out int counter, out int money, out int max_einsatz, int obergrenze, double verlustgrenze, Random r) { string NL = Environment.NewLine; StringBuilder sb = new StringBuilder(); Class_Fibo cf = new Class_Fibo(); int pos = 0, einsatz = 1, verlust = 0; counter = 1; money = 0; max_einsatz = 1; while (pos >= 0) { bool bo_win = r.NextDouble() >= verlustgrenze; sb.Append(counter.ToString().Space(4) + ": act_pos = " + pos.ToString().Space(4) + " act_money = " + money.ToString().Space(6) + " bo_win = " + bo_win.ToString().Space(5)); einsatz = einsatz + money; //(int)Math.Pow(2, pos);// cf.fibo(pos); if (einsatz >= obergrenze) { sb.AppendLine(NL + " obergrenze erreicht"); break; } if (bo_win) { money += einsatz; pos += 1; } else { money = -1; verlust += einsatz; pos = -1; } sb.AppendLine( " new_pos = " + pos.ToString().Space(4) + " new_money = " + money.ToString().Space(6)); counter++; } return sb.ToString(); } } public class SettingSytems { public enum ensystems { normal, fibo, martingale, antimartingale } public int[] pos { get; } public double gewinngrenze { get; set; } public double bo_faktor { get; } public int[] startgeld { get; } public int[] spielstandgeld { get; } public int[] einsatz { get; } public bool[] bo_amleben { get; } public int[] counter { get; set; } public int general_counter { get; set; } public bool bo_run_over { get; set; } public bool bo_win; private Random rand; private int optionen = 4; private int starteinsatz; private int temp_einsatz_antimartingale; private int stop_reverse; private int fibo(int n) { int f0 = 1, f1 = 1, f = 1; if (n < 2) return 1; for (var i = 1; i < n; i++) { f0 = f1; f1 = f; f = f0 + f1; } return f; } private int pot(int n) { int erg = 1; for (var i = 0; i < n; i++) erg *= 2; return erg; } public SettingSytems(int startgeld = 100, int starteinsatz = 1, int stop_reverse = 32, double gewinngrenze = 0.5, double bo_faktor = 1.0) { this.pos = new int[optionen]; this.gewinngrenze = gewinngrenze; this.bo_faktor = bo_faktor; this.startgeld = new int[optionen]; this.counter = new int[optionen]; this.general_counter = 0; this.einsatz = new int[optionen]; this.spielstandgeld = new int[optionen]; this.bo_amleben = new bool[optionen]; for (var i = 0; i < optionen; i++) { this.startgeld[i] = startgeld; this.einsatz[i] = starteinsatz; this.pos[i] = 0; this.bo_amleben[i] = true; } this.rand = new Random(); this.bo_run_over = false; this.starteinsatz = starteinsatz; this.temp_einsatz_antimartingale = starteinsatz; this.stop_reverse = stop_reverse; } public void run_one_step() { this.bo_win = rand.NextDouble() > gewinngrenze; this.bo_run_over = !this.bo_amleben[0] && !this.bo_amleben[1] && !this.bo_amleben[2] && !this.bo_amleben[3]; this.general_counter++; if (bo_win) { for (var i = 0; i < optionen; i++) if(this.bo_amleben[i]) spielstandgeld[i] += einsatz[i]; temp_einsatz_antimartingale += einsatz[(int)ensystems.antimartingale]; pos[(int)ensystems.normal] = 0; pos[(int)ensystems.fibo] -= 2; if (pos[(int)ensystems.fibo] < 0) pos[(int)ensystems.fibo] = 0; pos[(int)ensystems.martingale] = 0; if (this.stop_reverse > temp_einsatz_antimartingale) pos[(int)ensystems.antimartingale]++; else { pos[(int)ensystems.antimartingale] = 0; temp_einsatz_antimartingale = starteinsatz; } } else { for (var i = 0; i < optionen; i++) if(this.bo_amleben[i]) spielstandgeld[i] -= einsatz[i]; pos[(int)ensystems.normal] = 0; pos[(int)ensystems.fibo]++; pos[(int)ensystems.martingale]++; pos[(int)ensystems.antimartingale] = 0; temp_einsatz_antimartingale = starteinsatz; } einsatz[(int)ensystems.normal] = starteinsatz * 1; einsatz[(int)ensystems.fibo] = starteinsatz * fibo(pos[(int)ensystems.fibo]); einsatz[(int)ensystems.martingale] = starteinsatz * pot(pos[(int)ensystems.martingale]); einsatz[(int)ensystems.antimartingale] = starteinsatz * pot(pos[(int)ensystems.antimartingale]); for (var i = 0; i < optionen; i++) if(this.bo_amleben[i]) { if (einsatz[i] > (startgeld[i] + spielstandgeld[i])) einsatz[i] = (startgeld[i] + spielstandgeld[i]); if ((einsatz[i] == 0) || (spielstandgeld[i] >= startgeld[i])) this.bo_amleben[i] = false; else this.counter[i]++; } } } }

<Window x:Class="setzsysteme.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:setzsysteme" mc:Ignorable="d" xmlns:zed="clr-namespace:ZedGraph;assembly=ZedGraph" Title="setting systems" Height="750" Width="1215" FontFamily="Courier New" Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="1*"/> <RowDefinition Height="1*"/> <RowDefinition Height="35"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="75*"/> <ColumnDefinition Width="5"/> <ColumnDefinition Width="420*"/> </Grid.ColumnDefinitions> <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" Grid.RowSpan="2"/> <StackPanel Margin="5,0,0,0" Grid.Row="2" Grid.Column="2" Orientation="Horizontal"> <Button x:Name="bt1" Content=" Reserve " HorizontalAlignment="Left" Margin="0,5" Click="bt1_Click"/> <Button x:Name="bt2" Content=" Test " HorizontalAlignment="Left" Margin="5,5,0,5" Click="bt2_Click"/> <Button x:Name="bt3" Content=" Reset and Start " HorizontalAlignment="Left" Margin="5,5,0,5" Click="bt3_Click" /> <Button x:Name="bt4" Content=" Test SettingSytems " HorizontalAlignment="Left" Margin="5,5,0,5" Click="bt4_Click" /> <Button x:Name="bt5" Content=" Stop " HorizontalAlignment="Left" Margin="5,5,0,5" Click="bt5_Click" /> </StackPanel> <Label Content=" version 2017/07/19" Margin="0,5,0,6" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Blue" FontWeight="Bold"/> <TabControl Grid.Column="2" Margin="5,15,0,0" Grid.RowSpan="2"> <TabItem Header=" List "> <Grid Background="#FFE5E5E5"> <Grid.RowDefinitions> <RowDefinition Height="75"/> <RowDefinition Height="1*"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="5"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <ComboBox Grid.Column="0" Grid.Row="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Center" HorizontalAlignment="Center" SelectedIndex="0" Margin="134,20,135,0" Width="150"> <ComboBoxItem Content="dafault"/> <ComboBoxItem Content="fibo"/> <ComboBoxItem Content="american"/> </ComboBox> <TextBox x:Name="tb1" Margin="5,0,3,5" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" AcceptsReturn="True" AcceptsTab="True" HorizontalScrollBarVisibility="Auto" Grid.Row="1" Grid.RowSpan="2"/> <ComboBox Grid.Column="2" Grid.Row="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Center" HorizontalAlignment="Center" SelectedIndex="0" Margin="119,20,134,0" Width="150"> <ComboBoxItem Content="dafault"/> <ComboBoxItem Content="fibo"/> <ComboBoxItem Content="american"/> </ComboBox> <TextBox x:Name="tb2" Grid.Column="2" Margin="3,0,5,5" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" AcceptsReturn="True" AcceptsTab="True" HorizontalScrollBarVisibility="Auto" Grid.Row="1" Grid.ColumnSpan="2" Grid.RowSpan="2"/> <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="1" ResizeDirection="Columns" Grid.RowSpan="2"/> </Grid> </TabItem> <TabItem Header=" Graph "> <WindowsFormsHost x:Name="host" Grid.Column="2" Margin="5" Grid.Row="2" Visibility="Hidden"> <WindowsFormsHost.Background> <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ActiveCaptionColorKey}}"/> </WindowsFormsHost.Background> <zed:ZedGraphControl x:Name="graph" Dock="Fill"/> </WindowsFormsHost> </TabItem> </TabControl> <StackPanel Margin="5" Grid.RowSpan="2"> <Image Height="100" Source="pics/feedback.png" Margin="0,15,0,5"/> <Button x:Name="bt_clear" Content=" Clear List " HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,20,0,5" Click="bt_clear_Click"/> <TextBox x:Name="tb3" Margin="10" HorizontalContentAlignment="Stretch" ScrollViewer.CanContentScroll="False" VerticalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" MaxHeight="400" AcceptsReturn="True"/> <Label Content=" drawings " HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,15,0,0"></Label> <StackPanel Orientation="Horizontal" Margin="0,0,0,20"> <CheckBox x:Name="cb1" IsChecked="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" /> <CheckBox x:Name="cb2" IsChecked="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" /> <CheckBox x:Name="cb3" IsChecked="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" /> <CheckBox x:Name="cb4" IsChecked="True" Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center" /> </StackPanel> <ComboBox x:Name="combo_prozent" HorizontalAlignment="Center" VerticalAlignment="Center" SelectedIndex="10" SelectionChanged="combo_prozent_SelectionChanged"> <ListBoxItem Content="40 %"/> <ListBoxItem Content="41 %"/> <ListBoxItem Content="42 %"/> <ListBoxItem Content="43 %"/> <ListBoxItem Content="44 %"/> <ListBoxItem Content="45 %"/> <ListBoxItem Content="46 %"/> <ListBoxItem Content="47 %"/> <ListBoxItem Content="48 %"/> <ListBoxItem Content="49 %"/> <ListBoxItem Content="50 %"/> <ListBoxItem Content="51 %"/> <ListBoxItem Content="52 %"/> <ListBoxItem Content="53 %"/> <ListBoxItem Content="54 %"/> <ListBoxItem Content="55 %"/> <ListBoxItem Content="56 %"/> <ListBoxItem Content="57 %"/> <ListBoxItem Content="58 %"/> <ListBoxItem Content="59 %"/> <ListBoxItem Content="60 %"/> </ComboBox> <Label x:Name="lb_info" Content="info" Margin="10,0,0,0"></Label> </StackPanel> </Grid> </Window>

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Glücksspielstartegie { class Program { static void Main(string[] args) { Random zufall = new Random(); int counterM = 0; int counterR = 0; int counterS = 0; int counterF = 0; for (int x =1; x <=100; x++) { int guthabenMe = 100; int guthabenBank = 10000; int einsatz = 1; if(MartingaleStartegie(zufall, guthabenBank, guthabenMe, einsatz))//funktioniert { counterM++; } if(ReverseMartingaleStrategie(zufall, guthabenBank, guthabenMe, einsatz))//funktioniert { counterR++; } if(Statisch(zufall, guthabenBank, guthabenMe, einsatz))//funktioniert { counterS++; } if(Fibonacci(zufall,guthabenBank,guthabenMe,einsatz))//probleme bei Fibonacci { counterF++; } } Console.WriteLine("Martingal: Ich gewinne " + counterM +" von 100 Spielen"); Console.WriteLine("Reverse Martingal: Ich gewinne " + counterR + " von 100 Spielen"); Console.WriteLine("Statisch: Ich gewinne " + counterS + " von 100 Spielen"); Console.WriteLine("Fibonacci: Ich gewinne " + counterF + " von 100 Spielen"); Console.ReadLine(); } private static bool MartingaleStartegie(Random zufall,int guthabenBank, int guthabenMe, int einsatz) { bool stop = false; while (!stop) { int ergebnis = Convert.ToInt32(zufall.Next(1, 3)); //bei 1 gewinnt bank, bei 2 gewinn ich if (ergebnis == 1) { guthabenMe -= einsatz; guthabenBank += einsatz; if (guthabenMe < einsatz * 2) einsatz = guthabenMe; else einsatz = einsatz * 2; } else if (ergebnis == 2) { guthabenMe += einsatz; guthabenBank -= einsatz; einsatz = 1; } if (guthabenMe >= 200) { stop = true; return true; } else if (guthabenMe <= 0) { stop = true; } } return false; } private static bool ReverseMartingaleStrategie(Random zufall, int guthabenBank, int guthabenMe, int einsatz) { bool stop = false; while (!stop) { int ergebnis = Convert.ToInt32(zufall.Next(1, 3)); //bei 1 gewinnt bank, bei 2 gewinn ich if (ergebnis == 1) { guthabenMe -= einsatz; guthabenBank += einsatz; einsatz = 1; } else if (ergebnis == 2) { guthabenMe += einsatz; guthabenBank -= einsatz; if(einsatz <= 30) { einsatz = einsatz * 2; } else if(einsatz >= 30) { einsatz = 1; } } if (guthabenMe >= 200) { stop = true; return true; } else if (guthabenMe <= 0) { stop = true; } } return false; } private static bool Statisch(Random zufall, int guthabenBank, int guthabenMe, int einsatz) { bool stop = false; while (!stop) { int ergebnis = Convert.ToInt32(zufall.Next(1, 3)); //bei 1 gewinnt bank, bei 2 gewinn ich if (ergebnis == 1) { guthabenMe = guthabenMe - einsatz; guthabenBank = guthabenBank + einsatz; } else if (ergebnis == 2) { guthabenMe = guthabenMe + einsatz; guthabenBank = guthabenBank - einsatz; } if (guthabenMe >= 200) { stop = true; return true; } else if (guthabenMe <= 0) { stop = true; } } return false; } private static bool Fibonacci(Random zufall,int guthabenBank, int guthabenMe,int einsatz) { int fibocount = 1; bool stop = false; while(!stop) { int ergebnis = Convert.ToInt32(zufall.Next(1, 3)); //bei 1 gewinnt bank, bei 2 gewinn ich if(ergebnis==1) { guthabenMe -= einsatz; guthabenBank += einsatz; fibocount++; einsatz = GetFibo(fibocount); } else if(ergebnis ==2) { guthabenMe += einsatz; guthabenBank -= einsatz; if(fibocount >= 3) { fibocount -= 2; einsatz = GetFibo(fibocount); } else { einsatz = 1; } } if(guthabenMe >= 200) { stop = true; return true; } else if(guthabenMe <=0) { stop = true; } } return false; } private static int GetFibo(int fibocount) { int x = 0; int y = 1; int fibo = 0; for (int i = 1; i <= fibocount; i++) { fibo = x + y; x = y; y = fibo; } return fibo; } } }