Tuesday, March 17, 2015

Displays have been ordered


Tonight I ordered two 4x20 LCD displays.



Also, here is a picture from the clock test.


Sunday, March 15, 2015

Clock Project - Progress Update


Phase 2 is moving along nicely.  I have completed all of the projects in the booklet that came with the Arduino kit, and have read all of the relevant chapters in the book Teach Yourself Arduino Programming in 24 Hours by Richard Blum, published by Sams.

Today I started writing and testing some clock code.  I built a simple circuit to test the code:  it has two push button switches, a green LED for each side to indicate whose turn it is, and a red LED for each flag.  The circuit looks something like this (drawn using the Fritzing program which can be downloaded at http://fritzing.org/home/).



Here is a schematic for the circuit:  (drawn using the website http://www.digikey.com/schemeit/# )



The switches are connected to pins 2 and 3 on the Arduino.  A 10 K ohm pull up resistor keeps the pin at 5 volts until the button is pressed which pulls the pin to ground.  In the code you will see that I have to initialize pins 2 and 3 for digital input.

Pins 8 and 9 are connected to the green LEDs and pins 10 and 11 are connected to the red LEDs.  These pins are configured for digital output.


And now... the program

The program, called a sketch is listed below.  It flows something like this:


  • Initialize the variables
  • Setup function that initializes the input and output pins and sets variable states (every sketch has to have this function)
  • Loop function (also required in every sketch)  executes in a never ending loop.  This is where the body of code is.  The basic parts of my code in the loop:
    • Don't start counting until the first button press
    • On a button press, light the correct LED, and assign the "turn" variable to the opponent
    • Check if 1000 milliseconds have gone by,  if so, call the subroutine to print the times to the serial port (can be monitored on the PC)
    • Check to see if either time is down to zero, if so, light the corresponding LED.
  • Any other functions.  I only have one, to print the time to the serial port.  Later, this is where the code to write to the LCD displays will live.
This is what the output looks like on the serial monitor screen:  
(for this example, each player has 15 seconds on their clock)

                                                                     (nothing happens until the 1st button press)
Player 1 button                                             (Green LED for player 2 lights)
2  Player 1 = 15  Player 2 = 15
2  Player 1 = 15  Player 2 = 14
2  Player 1 = 15  Player 2 = 13
2  Player 1 = 15  Player 2 = 12
2  Player 1 = 15  Player 2 = 11
Player 2 button                                             (Green LED for player 1 lights)
1  Player 1 = 15  Player 2 = 11
1  Player 1 = 14  Player 2 = 11
1  Player 1 = 13  Player 2 = 11
1  Player 1 = 12  Player 2 = 11
1  Player 1 = 11  Player 2 = 11
Player 1 button                                             (Green LED for player 2 lights)
2  Player 1 = 11  Player 2 = 11
2  Player 1 = 11  Player 2 = 10
2  Player 1 = 11  Player 2 = 9
2  Player 1 = 11  Player 2 = 8
2  Player 1 = 11  Player 2 = 7
2  Player 1 = 11  Player 2 = 6
2  Player 1 = 11  Player 2 = 5
2  Player 1 = 11  Player 2 = 4
2  Player 1 = 11  Player 2 = 3
2  Player 1 = 11  Player 2 = 2
2  Player 1 = 11  Player 2 = 1
2  Player 1 = 11  Player 2 = 0
Player 2 Flag                                                 (Red LED for player 2 lights)
2  Player 1 = 11  Player 2 = 0


Some thoughts and plans:


  • The way the code is written, if a player hits the clock using less than a second, he will not have any time come off his clock.  (like the old Master Quartz clocks).  I think think the best fix for this is to update the clock every 1/10 second.  I tested this and it worked fine, but the serial display filled up really fast, so I put it back to 1 second for this blog post.
  • The program continues to run after one player flags.  That players clock will not count down past zero, but if he hits his clock, the opponent's flag will count down, so that it is possible to have both players flag.  This is the correct behavior for USCF rules.
  • I will need to add code for common options:
    • Delay time before the clocks start to count
    • Increment time added each move
    • More than one time period
  • Once I get some LCD displays, I will need to write code for:
    • Choosing options and setting initial time
    • Displaying the time on the LCD displays.



Here is the sketch listing:

//   
//  Chess Clock Practice Sketches
//
//  Bob Nolan
//  3/15/2015
//

// Declare Global Variables
unsigned int timeR1;
unsigned int timeR2;
unsigned long lastMilliS;
int turn;
int ledPin1 = 8;
int ledPin2 = 9;
int switchPin1 = 2;
int switchPin2 = 3;
int flagPin1 = 10;
int flagPin2 = 11;
boolean checkButton;
boolean flag1=0;
boolean flag2=0;

void setup() {
  Serial.begin(9600);
  timeR1 = 15;                // set initial time
  timeR2 = 15;                // need to add user input routine
  turn=0;
  pinMode(ledPin1,OUTPUT);
  pinMode(ledPin2,OUTPUT);
  pinMode(switchPin1,INPUT);
  pinMode(switchPin2,INPUT);
  pinMode(flagPin1,OUTPUT);
  pinMode(flagPin2,OUTPUT);
}

void loop() {  
 if (turn==0){              // dont start counting until 1st button press
    lastMilliS=millis();
 }
  if (millis()-lastMilliS >= 1000) {   // every 1000 msec, update time
    lastMilliS=millis();
    if((turn==1)&&(!flag1)){
      timeR1--;
    }
    if((turn==2)&&(!flag2)){
      timeR2--;
    }
    printTime();
  }
  checkButton=digitalRead(switchPin1);   // player 1 button press
  if(!checkButton && (turn!=2)){
    digitalWrite(ledPin2,HIGH);
    digitalWrite(ledPin1,LOW);
    turn = 2;
    Serial.println("Player 1 button");
    printTime();
    
  }
  checkButton=digitalRead(switchPin2);   // player 2 button press
  if(!checkButton && (turn!=1)){
    digitalWrite(ledPin1,HIGH);
    digitalWrite(ledPin2,LOW);
    turn = 1;
    Serial.println("Player 2 button");
    printTime();
   
  }
  if((timeR1<=0)&&(!flag1)){            // player 1 flag
    digitalWrite(flagPin1,HIGH);
    Serial.println("Player 1 Flag");
    flag1=1;
  }
  if((timeR2==0)&&(!flag2)){            // player 2 flag
    digitalWrite(flagPin2,HIGH);
    Serial.println("Player 2 Flag");
    flag2=1;    
  }
}

void printTime() {                      // print time function
   Serial.print(turn);                  
   Serial.print("  Player 1 = ");
   Serial.print(timeR1);
   Serial.print("  Player 2 = ");
   Serial.println(timeR2);
}

Tuesday, March 10, 2015

The Arduino has arrived



The Arduino experimenter's kit arrived today. 




I loaded the software without much trouble.  The only issue I had was the software recognized the Arduino was plugged into COM 3, but it was trying to write the program to COM 1.  This may have been due to having two instances of the software open.  After I closed one of them, it has worked ever since.

I built the first project from the booklet:  Making an LED blink.  I guess this is the "Hello World" program of the Arduino world.


So far this is going much more smoothly than I had hoped.   I will try to do a project each evening.  That should give me a good start at writing the chess clock program.


Monday, March 2, 2015

Building My Own Chess Clock


I now own 3 digital chess clocks:
  • DGT North American
  • DGT Easy Plus
  • Duel Timer
Each of them has drawbacks.  For instance, the DGT North American does not show the delay seconds counting down,  The Easy Plus cannot do more than one time period, and the Duel Timer only indicates whose turn it is to move on the display (no light or mechanical button).


So as an Engineer, I figure I can make something that can address all of these issues.  This is likely to become a massive project, so I will break it down into manageable chunks.


Phase 1 - Choose a Microcontroller

Based on what I have found on the interwebs, I am looking at the Arduine Uno R3.   Everything needed is onboard, just plug in and start programming.  Here are the specs:

MicrocontrollerATmega328
Operating Voltage5V
Input Voltage (recommended)7-12V
Input Voltage (limits)6-20V
Digital I/O Pins14 (of which 6 provide PWM output)
Analog Input Pins6
DC Current per I/O Pin40 mA
DC Current for 3.3V Pin50 mA
Flash Memory32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM2 KB (ATmega328)
EEPROM1 KB (ATmega328)
Clock Speed16 MHz
Length68.6 mm
Width53.4 mm
Weight25 g


Phase 2 - Learn to program the microcontroller

I can get the Arduino as with a starter kit that includes enough components and instructions for some first projects.  Plus there a lot of tutorials and videos on the web with instructions.  Failing that, I might even read some books.   It shouldn't take too long for me to be able to write the code for an elementary count down timer that switches to the other counter when a button is pressed.


Phase 3  -  Integrate the Displays

Right now I am looking at the HD4470 20x4 LCD display, one for each side.
The 8 custom characters would allow me to design a segmented display that would use 3 lines for the time H:MM:SS and the 4th line for information such as delay countdown (or increment), period, and move counter.  I mocked up something with only 5 custom characters that might look like this:



This display can be controlled with just 6 digital lines, one of which is the enable.  If I understand correctly, I could control 2 displays with just 7 lines, with a unique enable going to each display, and the rest of the data going to both.


Phase 4 -  Build the Case

For the first attempt, I will probably just use a clear plastic box, some large buttons and LEDs to indicate which player to move.  That would leave me 3 more digital pins to add Pause, and setting buttons.

The ultimate goal is to make a nice wooden body with mechanical buttons that click into place, just like my wife's nice Jerger analog clock.


Pressing the Start Button

Publishing my thoughts here forced me to spend some time thinking about what I would need and doing some research.  It also gives both my readers a chance to guide me back to the right path if I am starting out in the wrong direction.  So now is your chance; leave me some comments.

I'll publish some future posts with status reports and pictures as I make progress.











Sunday, March 1, 2015

Position Evaluation Criteria




A while back, I started compiling categories of position evaluation criteria as expressed by various authors. Here is the list based on the books in my library. I am curious as to what other authors (and readers of this blog) have to say on the subject.





Aleksander Kostyev, 40 Lessons for the Club Player
    Evaluation Principles:
  1. Material Balance
  2. Threats
  3. King Safety
  4. The Center
  5. Open Lines
  6. Active Pieces
  7. Pawn Structure Defects




Samuel Reshevsky, The Art of Positional Play
    Chapters:
  1. Weak Pawns
  2. Passed Pawns
  3. King Position
  4. Space
  5. Open Lines
  6. Tactics
  7. Good and Bad Pieces



Max Euwe, The Development of Chess Style
    Steinitz Theory, Characteristics:
  1. Lead in Development
  2. Superior Mobility
  3. Occupation of the Center
  4. Unsafe King Position
  5. Weak Squares
  6. Pawn Structure
  7. The Queenside Majority
  8. Open Files
  9. The Advantagbe of the Two Bishops
  10. Material Preponderance



Jeremy Silman, How to Reassess Your Chess
    Imbalances:
  1. Superior Minor Piece
  2. Pawn Structure
  3. Space
  4. Material
  5. Control of Key Squares
  6. Lead in Development
  7. Initiative



Gary Kasparov, Interview with Brian Readhead, Kasparov's Winning Chess Moves
    Dimensions:
  1. Material
  2. Time
  3. Quality



Johathan Rowson, Chess for Zebras
    Dimensions:
  1. Material
  2. Opportunity
  3. Time
  4. Quality



Dan Heisman, Elements of Positional Evaluation
    Elements:
  1. Mobility
  2. Flexibility
  3. Vulnerability
  4. Center Control
  5. Piece Coordination
  6. Time
  7. Speed


    Pseudo-Elements:
  1. Material
  2. Space
  3. King Safety
  4. Development



Aron Nimzowitsch, My System
    Elements:
  1. The Center and Development
  2. Open Files
  3. The Seventh and Eighth Ranks
  4. The Passed Pawn
  5. Exchanging
  6. Elements of Endgames
  7. The Pin
  8. Discovered Check
  9. The Pawn Chain



Ludek Pachman, Modern Chess Strategy
    Factors: (that determine the character of a position)
  1. Material Relationship
  2. Power of the individual pieces
  3. Quality of the individual pawns
  4. Position of the Pawns, Pawn Structure
  5. The Position of the Kings
  6. Co-operation amongst the Pieces and Pawns



CJS Purdy, paraphrased by Ralph J. Tykodi, CJS Purdy's Fine Art of Chess Annotation and Other Thoughts
    Key Features:
  1. Material
  2. King Position
  3. Weaknesses

    • Weak Pawns / squares
    • Pawn moved in front of the castled king
    • Confined pieces
    • cramped game
    • backward development

  4. Strengths

    • Well Posted Pieces
    • More Space
    • Greater elasticity, mobility, freedom
    • Control of Center

  5. Development
  6. Breakthrough Points



Larry Evans, New Ideas in Chess

  1. Space
  2. Time
  3. Force
  4. Pawn Structure






Conclusions:



After giving this some thought, I have concluded that these ideas fall into 3 different groups:


  1. Categories of Evaluation

    • Material - includes minor piece imbalances
    • King Safety
    • Pawn Structure - includes the center, and any weak pawns or weak squares
    • Piece Activity - includes mobility and development
    • Threats

  2. Units of Measurement

    • Relative Piece Value
    • Force
    • Space
    • Time

  3. Basis for Evaluation

    • Activity - Which I define as useful mobility that can generate threats
    • Vulnerability - Something (piece, pawn, square) that has value, can be attacked and is underdefended.
    • Flexibility - Multiple options for improving the position or responding to threats.


Extreme Example: Checkmate. The winning player has superior activity aimed at the enemy king. The losing player has a vulnerable king, and lacks flexibily to respond to the threats.

When I evaluate pawn structure, I may notice an isolated pawn. By itself, I cannot say if the isolated pawn is good or bad. It can only be evaluated in terms of:

  • Activity: Do the pieces gain activity due to the open files on either side of the isolated pawn?
  • Vulnerability: Can the pawn be attacked? Can it be defended?
  • Flexibility: Can the pawn be advanced? Blockaded?


What do you think about these ideas?


Sunday, February 15, 2015

Data Visualizations by Randy Olson



I just ran across Randy Olson's blog where he does data visualizations.   Info about Randy Olson from his blog:


Randy is a PhD candidate in Michigan State University's Computer Science program. As a member of Dr. Chris Adami's research lab, he studies biologically-inspired artificial intelligence and evolutionary processes.


He published a series of 4 blog articles with data visualizations of chess topics.


  1. Chess tournament games and Elo ratings 
  2. A data-driven exploration of the evolution of chess: Game lengths and outcomes
  3. A data-driven exploration of the evolution of chess: Popularity of openings over time
  4. A data-driven exploration of the evolution of chess: Moves, captures, and checkmates

Sunday, February 8, 2015

Opening Names - Tree Diagrams


What is the deal with opening names?

There are sequences of opening moves that are played over and over again.  This is because the moves make sense in accomplishing the goals of the opening.  These goals are:
  • Develop the pieces off the back rank and into the game
  • Fight for the center of the board
  • Castle your king into safety

The names of openings have been assigned pretty much by accident over history.  Openings can be named after:
  • The first player who popularized the opening
  • The city or country where the opening was first popular
  • A descriptive name of the what is happening on the board

Do I need to learn all of the opening names?

No, you don't need to learn the names of all of the openings, but you should probably learn the names of the openings you play.  The best way to do this is to write down the moves of your next game (if you are playing online, most servers will record the moves for you).  After the game, look up the moves on the tree diagrams below and try to find the name of the opening you just played.  If the moves you played do not have a name, you may have been playing inferior moves and should consider one of the moves from the diagram instead.

Once you know the name of the opening you play, you can search on the internet for more information about that opening.  There are even videos that explain the finer points of each opening.


And now, the tree diagrams

I couldn't fit all of the openings on one diagram, so I broke them up according to the common classification system, which is explained in the first diagram.  Note:  There are many other openings that I did not include here.  These are either very rarely played anymore, or are not suited for improving players.








Next Steps

Now that you know the name of the openings you like to play, you can make your own tree diagrams showing the variations and sub-variations of those openings.  There are plenty of internet resources to guide you.  Old school players like me still read about the variations in books.

You should also plan to spend some time learning about the openings your opponents might use to prevent you from playing your opening,  For example, suppose you like to play the Scotch opening as White.   From the diagrams, you will notice that Black does not have to follow the path that leads to the Scotch.  After 1.e4 e5,  2.Nf3 Black does not have to play 2...Nc6.   Black can choose to play 2...Nf6 (Petroff Defense) or 2...d6 (Philidor Defense) instead.  Also, Black does not have to reply with 1...e5, but could choose any of the Semi-Open defenses instead.

I enjoy learning about the openings and I hope this information will help you get started improving your opening play.