Click here to Skip to main content
Click here to Skip to main content

Stopwatch and Rubik's Cube Shuffle Algorithm Generator

By , 15 Feb 2008
 

Cube AlgGen-Timer (approx 900kb) by pHysiX



Introduction

This is my first post @ CP and I hope many people will find this useful.

Background

I enjoy speedcubing and have repeatedly looked for a straight-forward stopwatch to no avail. Now, I hope to solve that problem with my own app.

Using the code

There are two main codes in this program; stopwatch and algorithm generator.

Below are the major bits of code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.Security.Cryptography;
using System.IO; 
//Declare these things
private AlgGenerator cgenAlg;
private Stopwatch stopWatch;
private Boolean captureLap;
//These are functions for when you form is called
        public MainFrm()
        {
            stopWatch = new Stopwatch();
            captureLap = false;

            InitializeComponent();
        }

private void timerMain_Tick(System.Object sender, System.EventArgs e)
        {
            // When the timer is running, update the displayed timer 
            // value for each tick event.

            if (stopWatch.IsRunning)
            {
                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                labelTime.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours, ts.Minutes, ts.Seconds,
                    ts.Milliseconds / 10);

                // If the user has just clicked the "Lap" button,
                // then capture the current time for the lap time.

                if (captureLap)
                {
                    labelLap.Text = labelTime.Text;
                    captureLap = false;
                }
            }
        }

        private void btnGenerate_Click(object sender, System.EventArgs e)
      {
            if (null != cgenAlg)
            {
                if ((null != this.exclude.Text) || (String.Empty != this.exclude.Text))
                {
                    cgenAlg.Exclusions = this.exclude.Text;
                }
                cgenAlg.Maximum = this.maxSize.Value;
                cgenAlg.ConsecutiveCharacters = this.consecutive.Checked;
                cgenAlg.RepeatCharacters = this.repeating.Checked;
                cgenAlg.ExcludeSymbols = this.excludeSymbols.Checked;
                genAlg.Text = cgenAlg.Generate();
            }
        }
//The history function can read the stopwatch time and record it to a text file
private void buttonStartStop_Click(System.Object sender, System.EventArgs e)
        {
            if (stopWatch.IsRunning)
                using (StreamWriter sw = new StreamWriter("Cube History.txt", true))
                {
                    stopWatch.Stop();
                    buttonStartStop.Text = "Start";
                    buttonLapReset.Text = "Reset";
                    buttonLapReset.Visible = true;
                    buttonStartStop.Enabled = false;
                    sw.WriteLine("");
                    sw.WriteLine("===========================");
                    sw.WriteLine("PHYSIX Alg-Gen Cube Timer");
                    sw.WriteLine("Cubing Session:");
                    sw.WriteLine(DateTime.Now);
                    sw.WriteLine("");
                    sw.WriteLine("Your recorded time:");
                    sw.WriteLine(labelTime.Text);
                    sw.WriteLine("");
                    sw.WriteLine("Your shuffle algorithm:");
                    sw.WriteLine(genAlg.Text);
                    sw.WriteLine("===========================");
                }
            else
            {
                stopWatch.Start();
                buttonStartStop.Text = "Stop";
                buttonLapReset.Visible = false;
                button1.Enabled = false;
                button2.Enabled = false;
                button4.Enabled = false;
                labelLap.Visible = false;
                labelLapPrompt.Visible = false;
                groupBox1.Enabled = false;
            }
        }         

Those are just some things that I believe that can help you with using file I/O, a stopwatch and random strings/character generation.

To do

I was more a HTML developer so my C/C# skills will be no where near the skill of those on CP. What I hope to do is add some better aesthetics and make a less buggy algorithm generator (people that understand the names of the Rubik's Cube faces will understand the bug). Feel free to post any suggestions and if you are interested, simply request the SRC code below and I will upload as soon as I am free.

License

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

About the Author

pHysiX
PHYSIX Coding Corp
Australia Australia
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionplease source codememberhyderalima28 Oct '11 - 20:01 
Generalcodememberjskapur30 May '09 - 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 15 Feb 2008
Article Copyright 2008 by pHysiX
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid