Ejemplo n.º 1
0
 public void Run()
 {
     while (Generations > 0 && !Stop)
     {
         int NetIndex = 0;
         for (int i = 0; i < networks.Count; i++)
         {
             for (int j = 0; j < RoundNumber; j++)
             {
                 BlackjackLogic.GetInstance().PlayRound();
                 while (BlackjackLogic.GetInstance().CanAct)
                 {
                     if (networks[NetIndex].Decision())
                     {
                         BlackjackLogic.GetInstance().Hit();
                     }
                     else
                     {
                         BlackjackLogic.GetInstance().Stay();
                     }
                 }
                 int[] results = BlackjackLogic.GetInstance().round_replay.GetRoundResults();
                 networks[NetIndex].SetResults(j, results[0], results[1], results[2]);
             }
             NetIndex++;
         }
         NextGeneration();
         Generations--;
     }
     if (Generations == 0)
     {
         NetDisplay.Reset();
     }
 }
Ejemplo n.º 2
0
 public static BlackjackLogic GetInstance()
 {
     if (logic == null)
     {
         logic = new BlackjackLogic();
         return(logic);
     }
     else
     {
         return(logic);
     }
 }
Ejemplo n.º 3
0
        public MainForm()
        {
            logic = BlackjackLogic.GetInstance();

            font       = new Font(FontFamily.GenericSansSerif, 25);
            CardWidth  = 75;
            CardHeight = 100;

            InitializeComponent();

            DealerPoint        = new Point(DealerHandLabel.Left, DealerHandLabel.Top);
            PlayerPoint        = new Point(PlayerHandLabel.Left, PlayerHandLabel.Top);
            HitButton.Enabled  = false;
            StayButton.Enabled = false;
        }
Ejemplo n.º 4
0
 private void CheckRunning()
 {
     if (logic.CanAct)
     {
         HitButton.Enabled  = true;
         StayButton.Enabled = true;
     }
     else
     {
         HitButton.Enabled  = false;
         StayButton.Enabled = false;
         ReDrawCards(true);
         graphics = this.CreateGraphics();
         brush    = new SolidBrush(Color.Black);
         string results = (BlackjackLogic.GetInstance().round_replay.win) ? "You win!" : "You lose!";
         graphics.DrawString(results, font, brush, Width / 2, Height / 2);
     }
 }
Ejemplo n.º 5
0
 public void TestTopNetwork()
 {
     for (int j = 0; j < 10; j++)
     {
         BlackjackLogic.GetInstance().PlayRound();
         while (BlackjackLogic.GetInstance().CanAct)
         {
             if (networks[0].Decision())
             {
                 BlackjackLogic.GetInstance().Hit();
             }
             else
             {
                 BlackjackLogic.GetInstance().Stay();
             }
         }
         NetDisplay.UpdateDisplay(BlackjackLogic.GetInstance().round_replay.PrintReplay());
     }
 }
Ejemplo n.º 6
0
        public bool Decision()
        {
            //Feed card values to input neurons
            double[] IN_Array = new double[3];
            IN_Array[0] = BlackjackLogic.GetInstance().Player.Hand.Value;
            if (BlackjackLogic.GetInstance().Player.Hand.AceFlag)
            {
                IN_Array[1] = BlackjackLogic.GetInstance().Player.Hand.GetHighValue();
            }
            else
            {
                IN_Array[1] = -1;
            }
            IN_Array[2] = BlackjackLogic.GetInstance().DealerHand.Cards[1].NumValue;
            layers[0].SetInputs(IN_Array);
            //Feed values to hidden layer after processing input layer
            layers[1].SetInputs(layers[0].ProcessLayer());
            //Feed to output layer from processing hidden layer
            layers[2].SetInputs(layers[1].ProcessLayer());

            return(((int)layers[2].ProcessLayer()[0] == 1) ? true : false);
        }