Thursday, February 27, 2014

Chess Coding Challenge - Part 2 - Scala infrastructure source code (and two encoder/decoder implementations)...

Part 1 - How I Leveraged Scala and FP to Find a Solution
Part 3 - Scala solution source code (and interim encoder/decoder implementations)

The Scala code (dropbox public folder share - I SO love this) defining the infrastructure for experimenting with different encoder/decoder pairs. Included the first two coder implementations; SquareBits4 (constant 256 bits) and PieceExistsBitMapPlusSquareBits4 (max of 192 and reduces by four bits for each piece captured)

Honestly, I don't have time to go into much detail this evening. So, below is the 1,000 foot view. The root folder contains two folders; DataSets and eclipse_workspace. The DataSets folder contains a text file containing the "test" boards. It ought to be mostly self-explanitory. The eclipse_workspace folder contains the Eclipse .project. I'll reference that a bit later. All of the Scala files all stored in a single package; org.public_domain.chess_coding_challenge:

  1. This is a fantastic mechanism for "forming" code dynamically. The code you see there is recompiled and run every time you save the file. All the text in the columns to the right are the output from each of the lines. This way of developing is beyond awesome.
  2. Main.scala: This is the root class that is run. It is the Scala analog to any Java class containing a public static main method.
  3. Definitions.scala: All interface definitions. Everything can be understood in terms of the interfaces.
  4. Implementations.scala: All the factories which instantiate implementations of the interfaces in Definitions.scala.
  5. ConvertBits.scala: A helper class to facilitate twiddling bits.
  6. Coders.scala: This is where the actual encoder/decoder pairs are implemented. And this is where the SquareBits4 and PieceExistsBitMapPlusSquareBits4 implementations are defined.
If you are interested in the minimum fuss way of checking this out, I would highly recommend downloading the free Eclipse + Scala-IDE as it is entirely Scala self-contained; i.e. no need to download various Eclipse and Typesafe installs and work to get them all configured and working. You do need to have (the free) JDK7 installed first as Eclipse and Scala both depend completely upon it. You can also use JDK6, but I don't recommend it both for security as well as performance reasons.

Once you have Eclipse installed and have started it...:

  1. Eclipse will want to be pointed at an Eclipse Workspace - select the eclipse_workspace folder (using "Browse" to navigate to it if needed)
  2. Once Eclipse comes up, it will be blank - using the main menu, select File/Import
  3. On that dialog, open the General item which will show a list of items
  4. Select the item "Existing Projects into Workspace" and click "Next"
  5. Next to the "Select root directory", select "Browse" and immediately hit "Okay"
  6. Click "Finish" and the project will be loaded and ready to explore

Have fun! And please let me know if you end up experimenting with writing some encoder/decoder pairs yourself. I am hoping to find more time this weekend to post at least the initial Huffman encoding that launched me onto this tangent/fixation/whatever on Super Bowl Sunday!

No comments:

Post a Comment