Fool’s Mate Friday: A Rook-ie mistake!

 

wr

The rook is believed to have once been the “rukh”, which was some sort of tower shaped carriage that was placed on top of an elephant. Supposedly, the rukh was the actual fortification itself, and the elephant was the means of carrying it around. In the top of this tower shaped fort was an archer who would rain arrows upon his enemies, able to control long open distances because of his archery. Other variants included men with long spears, who would attack from above. Over time, according to legend, the pieces evolved, and somewhere in Europe, where there are no elephants, the elephant itself was discarded, and the rukh remained, albeit changed to resemble the castle like towers which were common in the middle ages.

war_elephant

Now one can see why they are often erroneously referred to as “castles”. Technically, to castle is a move in chess, involving the rook and the king.

In either event, I set about to add the rook moves to my chess engine. Remember, my logical board is an array of characters. 64 characters arranged in a straight line. Each character is given a numbered spot in the array, so moving a “R” or “r” for rook (white and black respectively), is a matter of simple algebraic math.

To advance “up” a row is: rook current space + 8 = rook’s new space. Down is a minus 8, and to move side to side is +1 or -1. However, there is a catch. If a rook was in space 8 (a2) and did a move to the left (which would be an illegal off the board move), the rook would mathematically end up in space 7, which is h1. This can’t be allowed.

So, what we use is some elementary level math: rook’s current space / 8 = the rook’s row. Since integers are always whole numbers, 57 / 8 = 7.125, which the integer, being whole, always rounds down, which gives us 7. The rook is in row 7. Likewise, if we want the column, we use this formula: rook’s current space % 8 = the rook’s column. This is looking for the remainder after the division, so in the case of 57 / 8 = 7 with a remainder of 1, the rook is in column 1. Very simple to implement and use.

The trick was making sure that we properly use that information. Creating a simple while loop solved that issue. You can see the first rook commit here. However, in all of my “smartness” I made a rook-ie mistake! My mistake was this: there are 8 rows, and 8 columns, but it is not numbered 1-8, it is numbered 0-7! This lead to move errors, as part of my code said if you were in greater than row 1 or less than row 8, etc., which would allow pieces to “fall off” the board (actually creating an array out of bounds exception), or move from one row far column to the opposite column on another row! This is not acceptable! Fortunately, the fix was easy, and you can see it in the second and third rook commits. Yes, it took me two tries to fix my own Fool’s Mate!

Linux – keep it simple.

Advertisements

Edited Hourglass app manual time entry function.

ss5

Last week GitHub user spaetz brought forward a great idea for the Hourglass Android timer app that I made a while back. He recommended that the manual time entry be adjusted so that entering any number without a colon (:) would be counted as minutes. Here you can see his issue in the tracker:

https://github.com/alaskalinuxuser/app_hourglass/issues/7

After a quick review of the code, I came up with a simple fix, which you can see in my commit here:

https://github.com/alaskalinuxuser/app_hourglass/commit/fb28250c74e59582e887ede69cf75c1f061caf3c

Essentially, I just check to see if the entered time includes a colon. If it does, then I check it as usual. If not, then I take it as minutes only. Nothing spectacular here, but this is the main portion of the change:

// We wrap this in try, so the app can’t crash if they put in some weird number….
 try {
 –
 + int sec,min,math;
 // Alright, let’s split that time based on colon.
 – String[] foundSplit = manualTime.split(“:”);
 + if (manualTime.contains(“:”)) {
 + String[] foundSplit = manualTime.split(“:”);
 + // Testing only // Log.i(“WJH”, foundSplit[0]);
 + // Testing only // Log.i(“WJH”, foundSplit[1]);

 – // And let’s get the seconds from the split.
 – String seconds = foundSplit[1];
 + // And let’s get the seconds from the split.
 + String seconds = foundSplit[1];

 – // And the minutes from the split.
 – String minutes = foundSplit[0];
 + // And the minutes from the split.
 + String minutes = foundSplit[0];

 – // Then we convert them to integers.
 – int sec = Integer.parseInt(seconds);
 – int min = Integer.parseInt(minutes);
 + // Then we convert them to integers.
 + sec = Integer.parseInt(seconds);
 + min = Integer.parseInt(minutes);
 + } else {
 + sec = 0;
 + min = Integer.parseInt(manualTime);
 + // Testing only // Log.i(“WJH”, String.valueOf(min));
 + }

 // And do some basic math to turn them into milliseconds.
 – int math = (min * 60 * 1000) + (sec * 1000);
 + math = (min * 60 * 1000) + (sec * 1000);

Note that the – symbol is a line deleted, and the + symbol is a line added.

But that’s what’s great about open source apps. Not only could someone suggest a change, someone could also make changes and offer up improvements. Either way, the Hourglass app is better for it with this addition.

Linux – keep it simple.

Fool’s Mate Friday: A knight’s tale.

bn

Now that we have a visual board to display, and we’ve called for the engine to check for all available moves, we need to actually add moves for each piece. Today we are going to start with the knight. I started with the knight because I thought it would be the most difficult.

A fun fact about knights: knights have the advantage of being able to control squares of either color, unlike a lone bishop, however, a lone bishop can trap (although it cannot then capture) a knight on the edge of the board, or rim, especially in the endgame.

I ended up doing the knights move in two stages. I first made the knight’s moves, and later realized a way to make it better.

If the knight is on whichever side of the board, it can make the appropriate L or T shaped move in the opposite side of the board. Since our board is made of number squares, it really was just a mathematical problem. In every case, it is the following four algebraic equations:

  • Move to (m) = Knight (n) +/- number.
  • m = n +/- 17
  • m = n +/- 15
  • m = n +/- 10
  • m = n +/- 6

Pretty cool, huh? Be sure to check out the commits here and here.

Linux – keep it simple.

CompTIA Mobility+ certificate to be retired on December 15th.

One of the many things that my work requires is various IT certificates. In particular, they require Network+ for the job I am currently filling, and A+, Security+, and Linux+, for various other simulators at my work. So, I make an effort to keep my certifications current, and to have as many as possible, in the event that a position opens up to which I want to apply.

Now, there are a lot of certificates out there, and while I’m not intending to talk about them all here, I would mention that there are other great programs out there, other than CompTIA. For instance, I do hold an LPIC certification, as well as a SLES, and a LFCS. Two of the great things about CompTIA, however, is the fact that they are an industry standard, and that they have a pyramid hierarchy, which allows you to make current and hold numerous “lower” tier certifications by only taking the top level test.

It was a surprise to me to learn that they are retiring the Mobility+ certificate before the close of this year. Here is their take on why they should retire this certificate:

CompTIA Mobility+ certification will officially retire on December 15, 2017. The main reason for this retirement is that the job role for Mobility+ continues to merge into the Network Administrator role, and much of the Mobility+ content is covered in CompTIA A+, Network+ and Security+.

What surprised me, though, was that this is the only certification from CompTIA, and one of the few certifications in general, that covered cellular data and infrastructure.

Sure, A+ does cover a lot of hardware, but it doesn’t seem to cover cellular towers, WiMAX, or even Satellite components, which are a part of Mobility+. Here in Alaska, with many wild and untamed areas of the state, various forms of wireless communications are utilized to get internet connectivity into remote locations.

Granted, Network+ does cover the majority of TCP/IP protocol stack, but cellular devices typically use odd protocols to control the transmission and reception of the TCP/IP data. The radio portions of Mobility+ helped differentiate between the various types of frequency shifting, hopping, and cells that are an integral part of the mobile world.

Of course, Security+ covers most aspects of authentication, authorization, and accounting, but in a more general sense. While it does cover wireless access, it only focuses on the typical 2.4 and 5 MHz bands and associated equipment, not covering the special needs of cellular devices. When it comes to MDM (Mobile Device Management), Security+ treats it as a footnote in section 4, in which all of section 4 is covered by less than 15% of the test. In Mobility+, however, Mobile Device Management alone is 28% of the exam!

It would seem to me that any cellular or satellite internet provider would make Mobility+ a mandatory requirement. Places like Verizon, T-Mobile, or AT&T would all be encouraging their technical employees to certify in this field in order to maintain their network.

What does that mean? I certainly think that the Mobility+ certificate is one worth keeping, but apparently CompTIA believes otherwise. Since it does not make logical sense to me, I can only believe that either too few people are taking the test to make it worthy of updating, or CompTIA is not earning enough revenue from Mobility+ sales to warrant it’s continued operation.

It could be that cellular technologies will be rolled into A+, Net+ and Sec+, negating the need for Mobility+, but I just renewed my Network+ and Linux+ certifications, and didn’t see any cellular references on the exam. They say that CompTIA certifications are led by the industry, and not the other way around. In a world that is becoming increasingly more mobile, I just can’t see getting rid of Mobility+.

Linux – keep it simple.

Fool’s Mate Friday: Getting “board” already?

chess_board

They say that the folding chessboard was invented by a priest who was forbidden to play chess. This priest found a way to hide his game by making a folding chessboard. When folded together and put on a bookshelf, it looked like two ordinary books. Wow! The lengths people will go through, just to play chess!

As we continue adding to our engine, we actually don’t need a visual representation of the board for the engine to work. However, by including it, other open source users who want to use the engine can see how it is implemented. It also makes testing the engine easier. Well, at least more fun, because instead of looking at boring logs that are displaying the board as text, the board is visually represented and we can make sure it is working correctly.

The fourth commit in our series is where we added the graphical pieces. I’d like to take a moment to cite my sources and thank them for creating this really great artwork! Not only that, but they are sharing it under the cc license!

The graphical images of the chess pieces came from:
https://www.behance.net/gallery/10018309/Chess-Artwork-Pieces-and-Board-Art-Assets
https://creativecommons.org/licenses/by/4.0/
https://www.behance.net/DaniDiLena

Then, our fifth commit shows how we draw the board through java, rather than through the xml. This allows for dynamically updating our board at any given time. Notice that after “arranging” the board in the layout file, we assign each block a unique id. With this id, we can put alternating color squares, and then top them with either blanks or pieces.

public class TheUserInterface {
 
 
 
public static void drawBoardPieces() {
 
 
 
for (int i=0; i<64; i++) {
 
 
 
switch (theBoard[i]) {
 
case '*': chessImage[i].setImageResource(R.drawable.empty);
 
break;
 
case 'P': chessImage[i].setImageResource(R.drawable.wp);
 
break;
 
case 'R': chessImage[i].setImageResource(R.drawable.wr);;
 
break;
 
case 'N': chessImage[i].setImageResource(R.drawable.wn);;
 
break;
 
case 'B': chessImage[i].setImageResource(R.drawable.wb);;
 
break;
 
case 'Q': chessImage[i].setImageResource(R.drawable.wq);;
 
break;
 
case 'K': chessImage[i].setImageResource(R.drawable.wk);;
 
break;
 
case 'p': chessImage[i].setImageResource(R.drawable.bp);
 
break;
 
case 'r': chessImage[i].setImageResource(R.drawable.br);;
 
break;
 
case 'n': chessImage[i].setImageResource(R.drawable.bn);;
 
break;
 
case 'b': chessImage[i].setImageResource(R.drawable.bb);;
 
break;
 
case 'q': chessImage[i].setImageResource(R.drawable.bq);;
 
break;
 
case 'k': chessImage[i].setImageResource(R.drawable.bk);;
 
break;
 
}
 
} //Done for loop for drawing board.
 
 
 
} // End draw board pieces
 
 
 
}

Above is the magic that makes adding the pieces a breeze. All this method does is “read” the board, and place an appropriate piece on the number square based on what symbol was in it’s block. For example, the chessImage[] array is holding the unique id of each square of the physical board. It then reads each square of theBoard[] array with the logical board representation, and places white knights on the N squares, and black queens on the q squares. Really simple, really quick. This works well for a style where you don’t have to “move/drag” the pieces, but simply “transport” them from square a to square b.

Linux – keep it simple.

What exactly constitutes as open source hardware (OSHW)?

oshw-logo-200-px

There is a lot of buzz around the net on this idea of open source hardware (OSHW). However, the deeper that I look into it, the more tangled the web seems to be. I’ve been noticing that some sites tout equipment as OSHW because they have SOME open source hardware on-board. In other cases, the pieces/parts are all closed source hardware, but the schematic of the use of those parts is open, so that makes it open source hardware. It gets a little confusing.

Some of you are reading this, thinking, “What IS open source hardware, and why does it matter?” I guess it is time to get technical, here is the definition from https://www.oshwa.org:

Open Source Hardware (OSHW) is a term for tangible artifacts — machines, devices, or other physical things — whose design has been released to the public in such a way that anyone can make, modify, distribute, and use those things.

Well, that clears up the first part of our question. I guess now the second part to answer is: “Why does it matter?”

For the educated, you will find them placing tape over their computer cameras, using tor clients, chatting through XMPP, and generally taking a strong stance to protect their privacy.  You see, with all of this great technology, come great risk. That risk is this: someone could be spying on you.

Take, for example, Carrier IQ. (If you doubt that this is real, you can look it up on Google or any other search engine, because it does exist.) It was a great program designed for cell phone manufacturers so that they could get reports on what went wrong for the end user while using their phone. Say the camera app crashes, it could send a detailed report to the carrier (such as T-Mobile, AT&T, Verizon, etc.) to let them know that a user is having camera problems. As they collect this data, they can see statistically that all the users having this camera app crash are all using software version blah-blah.blah, and it trips on this line of code because of a kernel issue. Now armed with this information, the carrier can make modifications to the kernel, push out an update, and solve that issue for their phone users who want to take pictures with their camera.

Overall, the above paragraph sounds great. The end users get the camera working properly, and the carriers get happy customers, so everybody wins. Here’s where it gets touchy. What people came to realize is that the Carrier IQ software could also do things like: log every keystroke, take a picture and upload it to some carrier server, record audio, view your phone logs, etc., etc., etc. That’s where people took issue.

Granted, the example above was for software, and we are talking about hardware. However, hardware often faces similar issues. For troubleshooting purposes (we will give them the benefit of the doubt….) hardware will often have “back doors” or be “magic black boxes” that you don’t really understand or know about. Because the drawing, schematics, and software that runs on these smaller hardware items, such as modem chips, SoC’s, etc., are closed source, hidden from your view, you don’t know what is really going on under the hood.

So, a fictitious example:

What if you bought a *Name your car company* model: ZuperOne. Let’s say that, unbeknownst to you, every mile you drive, it sent your GPS position to the car factory, as well as what radio station you were listening to at the moment, what speed you were driving, if you were wearing your seat belt, and record from the microphone in the car, etc., all without letting you know.

What would they want that information for? Well, who knows, really. Perhaps they want to build better ZuperOne’s, or see what radio equalizers they should put in the next model. Maybe they want to evaluate engine performance by region compared to the recorded temperatures. That’s great, I guess.

But, what if they decided to sell your radio preferences to local stations? Or turn you over to the police for speeding? Or record your conversations in the car? Whoa! That would be bad, obviously. Your private life is just that, private, and it should stay that way.

The problem is that your privacy is being invaded, but you don’t even know it. Seems far fetched, but now replace that car with your cell phone. Built in hardware that is below the system level, available for the hardware manufacturer to use at their leisure.

So, back to the real world. What if the ZuperOne car was made OSHW? E.g., every part was specifically spelled out in the documents and drawing, all of the software was available for review, and you knew everything about the car? Then you would be informed that they are spying on you. You might not drive the same way, or go the same places. Or, you might ask your programming buddy to reprogram the source code to not transmit some (or all) of that data to the factory. Now you are not only informed, but you have modified it so you will not be spied on at all.

That is the goal of open source hardware. The OSHW stamp *SHOULD* mean that every part of something has been open sourced, allowing you to at least know what it is doing. In general, because they are open, they do not include any kind of spy ware, since you will obviously see it and not use it for that reason. Notice that it does not actually mean that there is no “back door” nor spyware, it just means that you are able to look at the code yourself and can see those issues, and that you have the means and permission to change them, if you want to.

So, what’s the issue? The problem that I’ve been running into is that some hardware is being manufactured, claiming to be open source hardware, only to find that it is *mostly* open source hardware. The question becomes, how much of a product needs to be OSHW for the entire product to be marked as OSHW? In my mind, it is black and white. To procure a OSHW stamp of approval and sale, the entire product must be made OSHW, and all of the components must be OSHW. But apparently, there are more than one opinions on that.

However, on the plus side, I have found one website that sells OSHW, and closed source hardware as well. However, they appear to be very diligent in marking and marketing each product as to it’s open source hardware status. I’ve also checked with a few other sites who have reviewed their products (since I’m not an engineer), and found them to be very reputable on what they mark as OSHW or not. That website is Olimex. There are probably others as well. If you know of one, be sure to drop a line in the comments. Although a little dated, there is also a wiki list of open source hardware projects that you can view.

Do I wear a tinfoil hat to bed every night? No. Just on Tuesdays (just kidding). But it would be nice to live in a world where your hardware wasn’t built to spy on you.

Linux – keep it simple.

Fool’s Mate Friday: the Just Chess Engine is just getting started…..

There are only 20 first moves in any standard game of chess. 20 choices, 20 options. Statistically, only 10 of those options regularly result in a win, or at worse, a draw among experienced players. 10 of those moves statistically result in a draw or loss. So, choosing that first move is actually one of the most important things you can do in the game of chess. If we extrapolate that, I’m sure there are a lot of tie ins to life itself.

Likewise, when starting to create a chess engine the opening moves are going to set the stage for the remainder of your work. Here’s how I am getting started:

Back to the basics, getting started on the Just Chess Engine. I decided to save my work sequentially to GitHub as I meander through this process to make it easy to follow. This also has bailed me out numerous times when I royally messed up my code, and I simply reverted back with my commits.

The first commit was just making a blank app in Android Studio. In the second commit, I added the board, logically. By logically, I mean what the engine holds as the board. This can differ than what is displayed physically to the user. Depending on the set up of the Android app, whomever is using this engine may also retain their own copy of the board, and simply feed data into the engine.

One might wonder why we would do that, but this could be quite handy. For instance, if I enable the Universal Chess Interface, the app creator may use a Beginning Chess Engine style of board for player interface, or a bitmap board, or whatever style they choose, and just ask the engine for a move suggestion from the computer. So, you need a way to ask the engine what it thinks, and then the engine needs it’s very own board to work with. So, keeping the logical board separate from the physical board is (to me) a good idea.

Finally, the third commit is adding a way to call for a move. At this point, the move call is empty. It doesn’t actually return anything, but sets the stage for when we start populating move options. Here, we call for the engine to tell us “all available moves”. The engine then searches through the 64 squares of the board, and for each character that matches a given symbol (k for king, r for rook, etc.) it will call a method() to check for that pieces available moves.

So far, our engine really doesn’t do much, but we are really just laying the foundation to build the engine from the ground up.

Linux – keep it simple.

 

Error: TARGET_USES_UNCOMPRESSED_KERNEL is depreciated!

While starting my new attempt at an Oreo build for the H811/H815 (T-Mobile LG G4), I ran into an error, right off the bat:

Error: TARGET_USES_UNCOMPRESSED_KERNEL is depreciated!

I took a look at the make files that build the kernel. You can find them in the tasks folder under vendor/lineage/build/tasks/kernel.mk, which has a very lengthy explanation on how to name the kernel to build uncompressed images. Here is the pertinent part:

# BOARD_KERNEL_IMAGE_NAME = Built image name
# for ARM use: zImage
# for ARM64 use: Image.gz
# for uncompressed use: Image
# If using an appended DT, append ‘-dtb’
# to the end of the image name.
# For example, for ARM devices,
# use zImage-dtb instead of zImage.

So all I had to do was remove this line from my device/lge/g4-common/BoardConfigCommon.mk file:

TARGET_USES_UNCOMPRESSED_KERNEL := true

Because my kernel has the naming convention like so:

BOARD_KERNEL_IMAGE_NAME := Image

Which alludes to an uncompressed image already. I love it when the solution is easy!

Linux – keep it simple.

Fool’s Mate Friday: The JustChessEngine

Sometimes, you just have to step out in a new direction. In the 1920’s, chess players began to hold to a new style of play, then called hypermodernism. In this phase, conventional moves were called into question, and they began to invent interesting new ways to control the center of the board, without moving the king’s or queen’s pawns. Similarly, I need to re-evaluate the beginner’s chess engine. Question the conventional method that I am currently using, and step out in a new direction. Is that good or bad? Only time will tell.

While writing the Beginner’s Chess Engine, I came to realize that there were a lot of changes that needed to be made to that engine to really speed it up. These changes would be extremely time consuming to implement by direct editing, and called for a whole new engine scheme. Again, I wanted to create a chess engine that was open source, for anyone to use, as well as keep it simple, small, and workable for Android cell phones. Thus enter the JustChessEngine.

Ironically, if you build it from the repository, it will look identical to the Beginner Chess Engine graphically, as I used the same graphical material to create it. However, under the hood is a whole new animal.

You can check out the new repository at https://github.com/alaskalinuxuser/JustChessEngine.

The big change from the git-go is ditching the array of string arrays that make up the board. Arrays are slow in general, and having them in this immutable fashion required multiple rewrites of the board while making a move. So an array is slow, and the Beginning Chess Engine has 8 arrays arrayed in one for the board. This is slow x 8, inside of a slow array. So, I ditched that and started with one array of characters.

Char[] (character arrays) can be edited on the fly, without rewriting the whole array again. As of this writing, the JustChessEngine outperforms the Beginning Chess Engine in speed tests at various ply by three to one! That’s a big gain! Be sure to check it out and feel free to leave comments.

Linux – keep it simple.

RWE: Ejabberd failed to start in Debian Wheezy

I had an old laptop that I decided would make a good toy for playing around with some lightweight server applications. It was a great candidate for several reasons. For one, I’m not using it for something else. Second, it was free. Third, it has a built in battery backup. Seemed like a win-win for me.

I’ve mentioned before that I am a member of SDF, the Super Dimensional Fortress (sdf.org), a free to the community Unix server that allows remote log in and numerous other goodies. Among those extras is the free jabber (XMPP) service for members. It’s really great, especially for free, but on several occaisions, it has been down for maintenance when I was waiting to receive a message to someone. That is a bit annoying. Obviously, server maintenance needs to happen, and I am really thankful to sdf.org for providing the service. I was just thinking that this would be a good excuse to try setting up my very own XMPP server.

Thus enter ejabberd. Ejabberd is an open source XMPP server that is available on most GNU/Linux distributions, including Debian Wheezy, which was already on my laptop. I looked up several tutorials on-line, and they all seemed to indicate that it would be super easy to set up, and I could get it up and running in a few minutes.

Screenshot_20171030-085330.png

Two days latter…..

I finally got it set up and running. No matter which tutorial I followed, none of them worked. It took hours of research (in between being a dad, husband, working person, etc.), but I finally figured out the problem. Not too many people are planning to set up their own XMPP server, and this problem is probably specific to Debian Wheezy, but I figured that I would show you the REAL steps to get this going.

The problem was that after installing ejabberd, even with the default settings, it would say:

starting service: ejabbered………………………………………………………..FAILED.

And there was no rhyme or reason why! I was only able to figure it out by running ejabberd live, so the output came to the terminal, and then I could see the issue.

# apt-get install ejabberd

If you are like me, it will fail after install.

# dpkg-reconfigure ejabberd

Set up your server name, admin, etc.

# ps axc|grep beam

# ps axc|grep epmd

Now kill both of those processes.

# nano /etc/default/ejabberd

Uncomment the ERLANG_NODE=ejabberd line, or add it if it does not exist. Save and exit that file. Not having this line caused my first failure.

Edit your  /etc/hosts file to look like this:
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Essentially, you need to delete any “extra” hosts in the file, just leave the localhost ones. Later, more can be added to the file once ejabberd is running, but for some reason, having extra hosts in this file cause my second failure.

Now you can start ejabberd. I recommend that the first time, you start it “live” so you can see what is happening under the hood:

# /etc/init.d/ejabberd live

But in the future, you can just start it with the usual services tags:

# service ejabberd restart

You should now have a running instance of ejabberd! Of course, now you need to add a user, if you didn’t already. Here is an example:

# ejabberdctl register userName xmppServerAddress.net superSecretPassword

And there we go! At least for me, that was enough to set up a fully functional XMPP server with ejabberd on Debian Wheezy. Of course, this still needs tuning and enabling features like blocking, encryption, etc., but hey, at least now you have something to work with!

Linux – keep it simple.