⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 包括Pheromones Algorythm、Memory Algorythm和Hill Climbing Algorythm I
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using Square;
using Fuzzy_Logic_Library;
using System.IO;
using System.Xml;
using System.Security;
using System.Text;
using MenuItemExtension;

namespace PathFinder
{
	/// <summary>
	/// positions that the available squares are stored in the array
	/// </summary>
	public enum ArrayPositionSet{ CURRENT, TOP, RIGHT, BOTTOM, LEFT };

	/// <summary>
	/// position of the square with regard to the current square
	/// </summary>
	public enum SquarePositionSet{ NONE, LEFT, RIGHT, TOP, BOTTOM, CURRENT };

	/// <summary>
	///  enums for the direction that the critter came from
	/// </summary>
	public enum DirectionLastTravelledSet{ NONE, LEFT, RIGHT, TOP, BOTTOM };
 
	/// <summary>
	/// enums for the directions that the square go in
	/// </summary>
	public enum SquareDirectionsSet{ NONE, ALL, BOTTOMLEFT, BOTTOMRIGHT, LEFTRIGHT, TOPBOTTOM, TOPLEFT, TOPRIGHT };

	/// <summary>
	/// Which of the available critters is to be used
	/// </summary>
	public enum CrittersSet{ AMEOBA, ANT };

	/// <summary>
	/// which algorythm set should we be using
	/// </summary>
	public enum AlgorythmSet{ NONE, BASIC, BASIC2, PHEROMONES, MEMORY, HILLCLIMB, HILLCLIMBTWO, HILLCLIMBTHREE };

	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Button startButton;
		private System.Windows.Forms.Button stopButton;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem5;
		/// <summary>
		/// is the application running
		/// </summary>
		private bool bIsRunning;
		/// <summary>
		/// what critter are we using
		/// </summary>
		private CrittersSet critter;
		private System.Windows.Forms.ColorDialog colorDialog1;
		/// <summary>
		/// main control timer
		/// </summary>
		private System.Windows.Forms.Timer updateTimer;
		private System.Windows.Forms.GroupBox groupBox4;
		/// <summary>
		/// interval for the main controller timer
		/// </summary>
		private System.Windows.Forms.NumericUpDown timerInterval;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components;
		/// <summary>
		/// array of critters that the program is using
		/// </summary>
		private ArrayList crittersArray;
		/// <summary>
		/// timer to control the decay rate of pheromones
		/// </summary>
		private System.Windows.Forms.Timer pheromoneDecayTimer;
		/// <summary>
		/// array for passing a block of squares to the algorythms
		/// </summary>
		private ArrayList squaresAvailableArray;
		/// <summary>
		/// should we use ants
		/// </summary>
		private System.Windows.Forms.CheckBox useAntsCheckBox;
		/// <summary>
		/// should we use the ameoba
		/// </summary>
		private System.Windows.Forms.CheckBox useAmeobaCheckBox;
		/// <summary>
		/// should we use the most basic algorythm
		/// </summary>
		private System.Windows.Forms.CheckBox useBasicCheckBox;
		/// <summary>
		/// should we use the improved basic algorythm
		/// </summary>
		private System.Windows.Forms.CheckBox useBasic2CheckBox;
		/// <summary>
		/// is the program paused
		/// </summary>
		private bool bIsPaused;
		/// <summary>
		/// is this the start of the program
		/// </summary>
		private bool bIsStart;
		/// <summary>
		/// what algorythm are we using
		/// </summary>
		private AlgorythmSet algorythm;
		/// <summary>
		/// algorythm collection
		/// </summary>
		private PathFinderAlgorythms pathFinderAlgorythms;
		/// <summary>
		/// tab page for the ants
		/// </summary>
		private AntsGeneralPage antsGeneralPage;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.GroupBox colorGroupBox;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem loadStandardMenu;
		private System.Windows.Forms.MenuItem loadPreviousMenu;
		/// <summary>
		/// timer for the ants
		/// </summary>
		private AntTimersPage antsTimersPage;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.MenuItem menuItem10;
		/// <summary>
		/// array of squares on the board
		/// </summary>
		private ArrayList squaresArray;
		/// <summary>
		/// enter edit mode
		/// </summary>
		private System.Windows.Forms.Button editButton;
		/// <summary>
		/// timer that updates maps during editing
		/// </summary>
		private System.Windows.Forms.Timer editTimer;
		/// <summary>
		/// are we in edit mode
		/// </summary>
		private bool bEditMode;
		private System.Windows.Forms.ContextMenu pathFinderContextMenu;
		/// <summary>
		/// mouse point to tell which square we are editing
		/// </summary>
		private Point mousePoint;
		private System.Windows.Forms.MenuItem menuItem12;
		private System.Windows.Forms.MenuItem menuItem13;
		private System.Windows.Forms.MenuItem saveCurrentMap;
		private System.Windows.Forms.MenuItem loadMapMenu;
		private System.Windows.Forms.Button resetButton;
		private System.Windows.Forms.CheckBox pheromonesCheckBox;
		private System.Windows.Forms.CheckBox memoryCheckBox;
		private System.Windows.Forms.CheckBox hillClimbingCheckBox;
		private const int SQUARESCOUNT = 126; /// number of squares in current map
		private bool bShowApplicationLogs = true;
		private bool bShowCritterLogs = true;
		private System.Windows.Forms.Label displayLabel;
		private System.Windows.Forms.TabPage tabPage3;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.CheckBox crittersLogLastTenMessages;
		private System.Windows.Forms.CheckBox crittersLogLastTwentyMessages;
		private System.Windows.Forms.CheckBox critterLogLastThirtyMessages;
		private System.Windows.Forms.CheckBox crittersLogAll;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.CheckBox generalProgressMessages;
		private System.Windows.Forms.CheckBox generalShowAll;
		private System.Windows.Forms.CheckBox useHillClimbingTwoAlgorythmCheckBox;
		private System.Windows.Forms.CheckBox useHillClimbingThreeAlgorythmCheckBox;
		private System.Windows.Forms.Button button1;



		public bool DisplayLogs 
		{
			get
			{
				return bShowApplicationLogs;
			}
			set
			{
				bShowApplicationLogs = value;
			}
		}

		public bool DisplayCritterLogs
		{
			get
			{
				return bShowCritterLogs;
			}
			set
			{
				bShowCritterLogs = value;
			}
		}

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			bIsRunning = false;
			bIsPaused = true;
			bIsStart = true;
			critter = CrittersSet.ANT;
			crittersArray = new ArrayList();
			squaresArray = new ArrayList();
			squaresAvailableArray = new ArrayList();

			updateTimer.Interval = ( int )timerInterval.Value * 1000;

			algorythm = AlgorythmSet.BASIC;
			pathFinderAlgorythms = new PathFinderAlgorythms();

			/// tab pages
			antsGeneralPage = new AntsGeneralPage( this );
			antsTimersPage = new AntTimersPage( this );

			this.tabControl1.Controls.Add( antsGeneralPage );
			this.tabControl1.Controls.Add( antsTimersPage );

			pheromoneDecayTimer.Interval = antsTimersPage.PheromoneDecay;

			if( loadStandardMenu.Checked == true )
			{
				OnLoadMap( "DefaultMap.xml" );
			}

			bEditMode = false;
			mousePoint = new Point( 0, 0 );

			this.tabControl1.Controls.Remove( tabPage2 );

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.button1 = new System.Windows.Forms.Button();
			this.resetButton = new System.Windows.Forms.Button();
			this.editButton = new System.Windows.Forms.Button();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.timerInterval = new System.Windows.Forms.NumericUpDown();
			this.stopButton = new System.Windows.Forms.Button();
			this.startButton = new System.Windows.Forms.Button();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.useHillClimbingThreeAlgorythmCheckBox = new System.Windows.Forms.CheckBox();
			this.useHillClimbingTwoAlgorythmCheckBox = new System.Windows.Forms.CheckBox();
			this.hillClimbingCheckBox = new System.Windows.Forms.CheckBox();
			this.memoryCheckBox = new System.Windows.Forms.CheckBox();
			this.pheromonesCheckBox = new System.Windows.Forms.CheckBox();
			this.useBasicCheckBox = new System.Windows.Forms.CheckBox();
			this.useBasic2CheckBox = new System.Windows.Forms.CheckBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.useAntsCheckBox = new System.Windows.Forms.CheckBox();
			this.useAmeobaCheckBox = new System.Windows.Forms.CheckBox();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.colorGroupBox = new System.Windows.Forms.GroupBox();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.groupBox5 = new System.Windows.Forms.GroupBox();
			this.generalProgressMessages = new System.Windows.Forms.CheckBox();
			this.generalShowAll = new System.Windows.Forms.CheckBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.crittersLogAll = new System.Windows.Forms.CheckBox();
			this.critterLogLastThirtyMessages = new System.Windows.Forms.CheckBox();
			this.crittersLogLastTwentyMessages = new System.Windows.Forms.CheckBox();
			this.crittersLogLastTenMessages = new System.Windows.Forms.CheckBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.menuItem8 = new System.Windows.Forms.MenuItem();
			this.menuItem12 = new System.Windows.Forms.MenuItem();
			this.menuItem10 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.loadStandardMenu = new System.Windows.Forms.MenuItem();
			this.loadPreviousMenu = new System.Windows.Forms.MenuItem();
			this.menuItem9 = new System.Windows.Forms.MenuItem();
			this.loadMapMenu = new System.Windows.Forms.MenuItem();
			this.menuItem13 = new System.Windows.Forms.MenuItem();
			this.saveCurrentMap = new System.Windows.Forms.MenuItem();
			this.colorDialog1 = new System.Windows.Forms.ColorDialog();
			this.updateTimer = new System.Windows.Forms.Timer(this.components);
			this.pheromoneDecayTimer = new System.Windows.Forms.Timer(this.components);
			this.editTimer = new System.Windows.Forms.Timer(this.components);
			this.pathFinderContextMenu = new System.Windows.Forms.ContextMenu();
			this.displayLabel = new System.Windows.Forms.Label();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.groupBox4.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.timerInterval)).BeginInit();
			this.groupBox2.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.tabPage2.SuspendLayout();
			this.tabPage3.SuspendLayout();
			this.groupBox5.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Controls.Add(this.tabPage3);
			this.tabControl1.Location = new System.Drawing.Point(0, 400);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(592, 256);
			this.tabControl1.TabIndex = 24;
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.Add(this.button1);
			this.tabPage1.Controls.Add(this.resetButton);
			this.tabPage1.Controls.Add(this.editButton);
			this.tabPage1.Controls.Add(this.groupBox4);
			this.tabPage1.Controls.Add(this.stopButton);
			this.tabPage1.Controls.Add(this.startButton);
			this.tabPage1.Controls.Add(this.groupBox2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -