Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / Visual Basic

Mastermind: An Evolutionary Computing Framework Demo

Rate me:
Please Sign up or sign in to vote.
4.29/5 (8 votes)
16 Sep 2004CPOL2 min read 51.4K   161   24  
Demonstration on how to use the evolutionary computing framework
Public Class Properties
    Inherits System.Windows.Forms.Form

#Region "Private properties"
    Private _PopulationSize As Integer = 10
    Private _CorrectGuess As MastermindGenome
#End Region

#Region "Public properties"
    Public ReadOnly Property PopulationSize() As Integer
        Get
            Return _PopulationSize
        End Get
    End Property

    Public ReadOnly Property NumberOfPegHoles() As Integer
        Get
            Return Me.NumericUpDown_PegHoles.Value
        End Get
    End Property

    Public ReadOnly Property CorrectGuess() As MastermindGenome
        Get
            If Not _CorrectGuess Is Nothing Then
                Return _CorrectGuess
            End If
        End Get
    End Property
#End Region

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
    Friend WithEvents Label_PopulationSize As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents NumericUpDown_PegHoles As System.Windows.Forms.NumericUpDown
    Friend WithEvents MastermindRow1 As Mastermind.MastermindRow
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TrackBar1 = New System.Windows.Forms.TrackBar()
        Me.Label_PopulationSize = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.NumericUpDown_PegHoles = New System.Windows.Forms.NumericUpDown()
        Me.MastermindRow1 = New Mastermind.MastermindRow()
        CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown_PegHoles, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'TrackBar1
        '
        Me.TrackBar1.LargeChange = 100
        Me.TrackBar1.Location = New System.Drawing.Point(0, 32)
        Me.TrackBar1.Maximum = 1000
        Me.TrackBar1.Minimum = 5
        Me.TrackBar1.Name = "TrackBar1"
        Me.TrackBar1.Size = New System.Drawing.Size(320, 42)
        Me.TrackBar1.TabIndex = 0
        Me.TrackBar1.TickFrequency = 100
        Me.TrackBar1.Value = 100
        '
        'Label_PopulationSize
        '
        Me.Label_PopulationSize.Location = New System.Drawing.Point(0, 8)
        Me.Label_PopulationSize.Name = "Label_PopulationSize"
        Me.Label_PopulationSize.Size = New System.Drawing.Size(320, 24)
        Me.Label_PopulationSize.TabIndex = 1
        Me.Label_PopulationSize.Text = "Population size: 100 genomes"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(0, 80)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(163, 24)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Number of peg holes (2-10) :"
        '
        'NumericUpDown_PegHoles
        '
        Me.NumericUpDown_PegHoles.Location = New System.Drawing.Point(160, 80)
        Me.NumericUpDown_PegHoles.Maximum = New Decimal(New Integer() {10, 0, 0, 0})
        Me.NumericUpDown_PegHoles.Minimum = New Decimal(New Integer() {2, 0, 0, 0})
        Me.NumericUpDown_PegHoles.Name = "NumericUpDown_PegHoles"
        Me.NumericUpDown_PegHoles.Size = New System.Drawing.Size(48, 20)
        Me.NumericUpDown_PegHoles.TabIndex = 3
        Me.NumericUpDown_PegHoles.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        Me.NumericUpDown_PegHoles.Value = New Decimal(New Integer() {2, 0, 0, 0})
        '
        'MastermindRow1
        '
        Me.MastermindRow1.Location = New System.Drawing.Point(0, 112)
        Me.MastermindRow1.Name = "MastermindRow1"
        Me.MastermindRow1.Size = New System.Drawing.Size(320, 40)
        Me.MastermindRow1.TabIndex = 4
        '
        'Properties
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(314, 154)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.MastermindRow1, Me.NumericUpDown_PegHoles, Me.Label1, Me.Label_PopulationSize, Me.TrackBar1})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "Properties"
        Me.Text = "Properties"
        CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown_PegHoles, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged

        _PopulationSize = TrackBar1.Value
        Label_PopulationSize.Text = "Population size: " & _PopulationSize.ToString & " genomes"

    End Sub

    Private Sub NumericUpDown_PegHoles_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown_PegHoles.ValueChanged
        _CorrectGuess = New MastermindGenome(NumericUpDown_PegHoles.Value)
        MastermindRow1.Guess = _CorrectGuess
        MastermindRow1.Refresh()
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

Comments and Discussions