JustNotes – when your notes are too long to read!

A user of my open source app, JustNotes, made an interesting observation… if your note gets too long, you can’t read it because it goes below the keyboard and you can’t scroll it upward. You can read the bug tracker issue on my GitHub for the full story. This is a really great point. I guess I had always thought of using this app for small, short notes, but it is conceivable to make a list or note that was longer than the top half of your screen.

Fortunately, I’ve progressed a bit in my programming skills since then, so I was able to fix it in about ten minutes. Essentially, I just added a scroll field for the text, like so:

justnotes_gif

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_writenote"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.alaskalinuxuser.justnotes.writenote"
    tools:showIn="@layout/activity_writenote">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top|center"
        android:orientation="vertical">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="textMultiLine"
        android:ems="10"
        android:gravity="top|left"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/multiTextView" />

    </LinearLayout>
    </ScrollView>

</RelativeLayout>

As you can see, I just implemented a ScrollView around the LinearLayout. Simple. Functional. Just the way I like it!

Linux – keep it simple.

Fool’s Mate Friday: En passant checkmate!

According to legend, Gary Kasparov once checkmated via en passant in an on-line game. However, I couldn’t actually find a detailed reference to that specific game. I was, however, able to find an article that expressed the only officially logged game in which an opponent was check mated via en passant. It was a game between Gunnar Gundersen and A H Faul during a Christmas tournament in 1928. Here was the move list:

1.e4 e6 2.d4 d5 3.e5 c5 4.c3 cxd4 5.cxd4 Bb4+ 6.Nc3 Nc6 7.Nf3 Nge7 8.Bd3 O-O 9.Bxh7+ Kxh7 10.Ng5+ Kg6 11.h4 Nxd4 12.Qg4 f5 13.h5+ Kh6 14.Nxe6+ g5 15.hxg6# 1-0

enpassantcheckmate

Certainly an interesting prospect. In this case, the en passant move doesn’t actually check the king, but prevents the king from retreating from the now discovered check of the rook. In any case, en passant is a very important part of playing chess, which makes it all the more vital that I fix it in my JustChessEngine and make it usable in my JustChess game.

The fix was not an easy one, but it came down to a few mathematical errors on my part, as well as a huge technical oversight. The program used to work like this:

If doing en passant for white:

place pawn to new square (+7 for right/up, and +9 for left/up). Remove taken pawn.

However, it would end up with two white pawns and remove the attacked pawn. So I edited it to be proper, like so:

If doing en passant for white:

place pawn to new square (+9 for right/up, and +7 for left/up). Remove taken pawn. Remove pawn from old square.

So, both the math was wrong on which side to go to, but also the pawn was never “removed” from it’s old square, just a new pawn was placed where it was going to! The fix was simple in principle, complex in actuality, but you can view the whole set of changes here: https://github.com/alaskalinuxuser/app_JustChess/commit/3053591df42473577e557b860ad639485841051f

I’m just glad it’s finally fixed!

Linux – keep it simple.

Fool’s Mate Friday: Is the King safe from pawns?

Pawns can be scary things. They can en passant, they can form chains and islands, they can promote to the all powerful queen. Not to mention they can checkmate you. That’s right. Even Magnus Carlsen has been checkmated by a pawn (vs. Tal Baron)*. So, if the current world chess champion can get the ax from a pawn, I, being far, far, far (add a few more far-s in there) lesser player, should watch out for them too.

On that note, while testing out my now playable JustChess app, I’ve come to realize a major blunder in the programming! A blunder in regards to my pawns when it comes to king safety! By complete accident, rather than say that a pawn is a threat when forward and diagonal of you, I made pawns life threatening to the king when abreast him!

pawnsafety

Don’t worry, though, I fixed it with this commit. Essentially, I had to change 4 lines, and move the pawn problem from row +/-1 to +/-7 and 9. Now the king can move appropriately when responding to pawns.

// King check // Don't move next to another king! // Also includes pawns.
if (h < 7 ) {
    if (theBoard[z+8]=='k') {
        return false;}
    if (g > 0) {
        if (theBoard[z+7]=='k' || theBoard[z+7]=='p') {
            return false;}}
    if (g < 7) {
        if (theBoard[z+9]=='k' || theBoard[z+9]=='p') {
            return false;}}}
if (h > 0 ) {
    if (theBoard[z-8]=='k') {
        return false;}
    if (g > 0) {
        if (theBoard[z-9]=='k') {
            return false;}}
    if (g < 7) {
        if (theBoard[z-7]=='k') {
            return false;}}}
if (g > 0) {
    if (theBoard[z-1]=='k') {
        return false;}}
if (g < 7) {
    if (theBoard[z+1]=='k') {
        return false;}}
// End white king is safe.

Linux – keep it simple.

* Some imply Tal Baron may have cheated to win this game. This was brought to my attention, so I added the link above for explanation. I’m not sure, I don’t know the man, and have no desire to in any way slight his character. In any event, Mr. Carlsen lost by checkmate to a pawn, either from Mr. Baron or an engine, and most likely Mr. Baron, due to the blitz game being less than 3 minutes. My point in this article still proves true: pawns are dangerous!

Ubuntu Touch: Make your own Jabber/XMPP app in 10 minutes…

You probably think that I’m joking, but I’m not. You can actually build a jabber/xmpp app in less than 10 minutes if you have a good internet connection, and have already set up your system with “clickable”. If not, be sure to check out my last post about it.

Are you ready to get started? Okay, here we go!

The magic that makes this work is that someone (or rather a group of someones) has already made a javascript xmpp client called convers.js. Head over to their website (https://conversejs.org/) and download it, or more directly, just click here: https://github.com/conversejs/converse.js/archive/v3.3.4.zip

Now jump over to your downloads folder and unzip it, or extract it if you grabbed the tar version. Great job, we are 20% done!

Open up your terminal and start typing:

$ mkdir xmmpapp
$ cd xmmpapp/
$ clickable init
Available app templates:
[1] pure-qml-cmake – Pure QML App (built using CMake)
[2] cmake – C++/QML App (built using CMake)
[3] python-cmake – Python/QML App (built using CMake)
[4] html – HTML App
[5] webapp – Simple Webapp
Choose an app template [1]: 4
Generating new app from template: HTML App
You’ve cloned /home/alaskalinuxuser/.cookiecutters/ut-app-html-template before. Is it okay to delete and re-clone it? [yes]: yes
Cloning into ‘ut-app-html-template’…
remote: Counting objects: 28, done.
remote: Total 28 (delta 0), reused 0 (delta 0), pack-reused 28
Unpacking objects: 100% (28/28), done.
Checking connectivity… done.
title [App Title]: xmppapp
description [A short description of your app]: xmpp app.
app_name [appname]: xmppapp
app_full_name [appname.yourname]: xmppapp.alaskalinuxuser
version [1.0.0]: 1.0.0
maintainer_name [Your FullName]: Alaskalinuxuser
maintainer_email [email@domain.org]:
Select open_source_license:
1 – GNU General Public License v3
2 – MIT license
3 – BSD license
4 – ISC license
5 – Apache Software License 2.0
6 – Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 5
Your new app has been generated, go to the app’s directory and run clickable to get started
$

All we did was make a directory, run clickable, and choose to make a html app. Notice that this is not a web-app, which is basically a shortcut to some web site. This app is all on the users phone and just opens up an html file. We are now 40% done!

Open up your file manager. Find the downloads folder with your extracted convers.js files. In my case it is ~/Downloads/c/converse.js-3.3.4. Be sure to be in the folder, so you see the files like dev.html. In another tab or window, open up the place that you made your new app, in may case it is ~/ubports_apps/xmmpapp/xmppapp. Be sure to be in this folder so that you see the www folder.

Open the www folder, and drag all of the contents of the converse folder into it. It will ask you if you want to overwrite index.html, say yes. You are 60% done! Five minutes down, five minutes to go!

Now back to you (hopefully) still open terminal. You should still be in the folder outside of the folder of the app you just made. Change directory to your app, like so:

$ cd xmppapp/
$ ls
clickable.json manifest.json www xmppapp.desktop
LICENSE README.md xmppapp.apparmor
$

Typing the ls command should show the same files I have, if you named the app the same as I did. Plug in your phone and be sure developer mode is enabled with Settings->about->Developer mode. You are 80% there!

All you have left to do is type:

$ clickable

 

Copied files to temp directory for click building
Successfully built package in ‘./xmppapp.alaskalinuxuser_1.0.0_all.click’.
3724 KB/s (3190648 bytes in 0.836s)
Installing files [=========================]
Finished [=========================]
Installing files [=========================]
Starting [=========================]
Finished [=========================]
Installed xmppapp.alaskalinuxuser-1.0.0.all (installed:click,removable=1,app_name=xmppapp) summary goes here
$

And you are 100% done! If all went as well as it did here, you should see this:

And now you can start jabber-ing! Obviously, you need an account somewhere. Currently, with this setup, you are using conversjs.org’s BOSH server, and you can connect to your xmpp server. However, this should only be done for testing purposes.

To really utilize this app, you should set up your own BOSH server, and perhaps your own XMPP server. I use ejabber2, so it is an XMPP server and a BOSH server all in one. In the index.html file is this line:

bosh_service_url: ‘https://conversejs.org/http-bind/&#8217;,

which should point to your BOSH server. But for testing purposes, the above line works flawlessly. Just recognize that since you are borrowing their BOSH server, it may be down at their leisure, or they can give your sessions the boot if they so desire.

As is, this app will run a non-encrypted conversation with no issues at all. Encryption does work, but it seems a bit funky. I was able to have one successful encrypted conversation, and two that were failures at encrypting. One other issue is that when you close the app, your encrypted “tunnel” ends, so you need to re-establish encryption after that, and I think you have to make sure that the other user turns off encryption so you can re-encrypt with them again.

Big thanks to the convers.js team for making such a great java script that we could drop into our app!

Linux – keep it simple.

Fool’s Mate Friday: 8 minute moves….

2-1.Bernstein-alex.1958.L02645391.IBM_ARCHIVES.lg

They say that the first complete chess playing program was written by Alex Bernstein in 1957. There were earlier renditions that could not play a complete game, but could solve tactics puzzles or make move suggestions, however, the Bernstein Chess Program was the first computer program that could actually completely evaluate and play a game of chess. For grins, I looked it up, and it was played on an IBM 704 computer, which was an entire room. It took about 8 minutes to make each move, before printing out the board on a piece of paper. You can check out a video of him playing the machine on YouTube.

My JustChess game is not so glamorous, but it is getting more interesting with each passing reiteration as I work on it’s programming. Last week, I talked about how you can now actually play against the phone/computer or against a person in pass and play mode. There were several bugs that still needed to be ironed out. In particular, making a move by the computer sometimes erroneously rearranged pieces on the board.

I found a quick and dirty work around for that. What I changed in this latest commit was that of how moves are made. What appears to be happening, as the ply goes up, the phone runs into a problem where the threads of various potential board positions are getting moved or mixed up. Probably due to poor code on my part. Either way, it then makes moves on boards that were not the actual play board, but that were hypothetical boards and pieces moved during it’s multi-ply search. I think.

So, to avoid this problem, I have changed the order of things, and added a step to copy down the board as it is, before a move is calculated, and then use that copy of the board to make the move with. Here’s a breakdown:

  1. Write down a copy of the board, as it is.
  2. Calculate the multi-ply best move with the original board.
  3. Write down the best move.
  4. Re-write the original board with the backed up copy, just in case it got messed up.
  5. Make the best move that it wrote down.

This seemed to work pretty well, most of the time. It completely fixed the issue of messed up or mixed up board pieces. However, it now has another new problem, where it can occasionally get “stuck”, and the program will hang until it is closed by Android. This seems to happen randomly, and doesn’t happen every game. So, more work to be done for sure.

I’ve also been “tuning” the JustChessEngine as well. But that’s another post….

Linux – keep it simple.

Ubuntu Touch: Making a new app

Realizing that there are a few apps missing from the Ubuntu Touch OpenStore, and being an Android app developer, I thought I would try to bridge the gap. Rolling up my sleeves proved to be a bit harder than I thought, though. I came to realize that UT doesn’t use java – at all. The Mir interface doesn’t support the java commands to display or draw things on the screen, so I was a bit stuck.

However, wanting to press on, I did manage to learn how to make a basic “hello world” app. While there are a few tutorials available, it got overly complicated, and I ran into some snags, so I thought I’d share the simplified version here. This is the pertinent info from the UBports website:

 

  • Add the PPA to your system: sudo add-apt-repository ppa:bhdouglass/clickable
  • Update your package list: sudo apt-get update
  • Install clickable: sudo apt-get install clickable
  • Configure docker for clickable: clickable setup-docker

After learning how this works, creating a new, blank or empty app is simple:

alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps$ mkdir newapp
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps$ cd newapp/
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$ clickable init
Available app templates:
[1] pure-qml-cmake – Pure QML App (built using CMake)
[2] cmake – C++/QML App (built using CMake)
[3] python-cmake – Python/QML App (built using CMake)
[4] html – HTML App
[5] webapp – Simple Webapp
Choose an app template [1]: 4
Generating new app from template: HTML App
You’ve cloned /home/alaskalinuxuser/.cookiecutters/ut-app-html-template before. Is it okay to delete and re-clone it? [yes]: yes
Cloning into ‘ut-app-html-template’…
remote: Counting objects: 28, done.
remote: Total 28 (delta 0), reused 0 (delta 0), pack-reused 28
Unpacking objects: 100% (28/28), done.
Checking connectivity… done.
title [App Title]: newapp
description [A short description of your app]: this is my newapp
app_name [appname]: newapp
app_full_name [appname.yourname]: newapp.alaskalinuxuser
version [1.0.0]:
maintainer_name [Your FullName]: alaskalinuxuser
maintainer_email [email@domain.org]:
Select open_source_license:
1 – GNU General Public License v3
2 – MIT license
3 – BSD license
4 – ISC license
5 – Apache Software License 2.0
6 – Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 5
Your new app has been generated, go to the app’s directory and run clickable to get started
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$

After creating a directory to store your app, you just run the command “clickable init” to create a new app. The prompts will ask you for your name, version number, email address and license type for the app. Pretty straight forward. Then you can edit the created app files to your liking, and just run clickable to build it:

alalaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$ clickable
No clickable.json was found, using defaults and cli args
Auto detected template to be “pure”
Copied files to temp directory for click building
Successfully built package in ‘./newapp.alaskalinuxuser_1.0.0_all.click’.
337 KB/s (15836 bytes in 0.045s)
Installing files [=========================]
Finished [=========================]
Installing files [=========================]
Starting [=========================]
Finished [=========================]
Installed newapp.alaskalinuxuser-1.0.0.all (installed:click,removable=1,app_name=newapp) summary goes here
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$

And voila! If your phone is plugged in, and developer mode is enabled, it can install it and run it on your phone. I also found it useful to use:

$ clickable –desktop

when you want to test it out on your computer, rather than put it on the phone. It seems to work rather well. As a side note, the first time you run it, clickable will download about 500 MB of UT files. This only happens once, not once per app, just once on your machine.

There is also the Ubuntu-sdk, although not supported, it is available if you would like a gui, rather than command line when making your apps. You can install it like so:

sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
sudo apt update && sudo apt dist-upgrade
sudo apt install ubuntu-sdk
sudo reboot # or logout/login

ubuntu-sdk

I’ve tried it out, and to be honest, I prefer the command line, but I might just need to play with it a bit more to get the hang of using it. Hopefully, this will help you if you are trying to get started on app making. I plan to go over how to make an app for XMPP soon.

Linux – keep it simple.

Fool’s Mate Friday: One Player or Two?

It was interesting to me that white did not always move first in chess. Apparently, in 1857, a master of chess, Mr. Lowenthal made a recommendation to the First American Chess Congress that white should always move first as a rule. However, that rule was not actually enforced until sometime in the 1900’s. Supposedly, they used to toss coins to see who went first, and that player could choose either color.

red

It might also be noteworthy that the pieces were not always black or white, as some old sets used red as one of the colors. Obviously, today you can get a chess set in any style or color imaginable.

In either event, JustChess is now one or two player! You can choose to play as black or white. Currently, the game is pretty rough around the edges, with a few notable bugs. You can check out the commit at my GitHub.

At present, the JustChessEngine is not very bright, to say the least. But currently, there are issues with the moves sometimes making an erroneous change to the board. Two player mode works as expected, however, en passant still needs to be fixed.

Perhaps when I iron out those bugs, I can release a 0.1 version.

Linux – keep it simple.

Fool’s Mate Friday: Pawn Promotion Possibilities!

Back in the middle ages, there were several different renditions of pawn promotion. Originally, the pawn would promote to the queen piece, but back then the queen could only move one space, like the king. Then there was the rule that the pawn could promote only to a captured piece. So if there were no captured pieces, the pawn would sit there on the end row until one was captured, which would immediately replace the pawn.

Perhaps the most interesting rule, though, was that of the pawn being promoted to the piece on which it’s rank was. E.g, the queen’s bishop’s pawn (c2) would promote to a bishop, a knights pawn a knight, and a king or queens pawn, to that of a queen. This would definitely change the face of a chess match as we know it!

The two player functionality of my chess app, in pass and play mode, is getting closer and closer to completion! Today I had a few minutes and I still had several obstacles to fix, so I decided to tackle one of them.

if (myMove.contains("P48")||myMove.contains("P49")||myMove.contains("P50")||
        myMove.contains("P51")||myMove.contains("P52")||myMove.contains("P53")||
        myMove.contains("P54")||myMove.contains("P55")) {
    if ( minusNum == 8) {
        myMove = "Pu" + promoteToW + played + String.valueOf(theBoard[number]);
    } else if (minusNum == 9) {
        myMove = "Pr" + promoteToW + played + String.valueOf(theBoard[number]);
    } else if (minusNum == 7) {
        myMove = "Pl" + promoteToW + played + String.valueOf(theBoard[number]);
    }
}

if (myMove.contains("p08")||myMove.contains("p09")||myMove.contains("p10")||
        myMove.contains("p11")||myMove.contains("p12")||myMove.contains("p13")||
        myMove.contains("p14")||myMove.contains("p15")) {
    if ( plusNum == 8) {
        myMove = "pu" + getPromoteToB + played + String.valueOf(theBoard[number]);
    } else if (plusNum == 7) {
        myMove = "pr" + getPromoteToB + played + String.valueOf(theBoard[number]);
    } else if (plusNum == 9) {
        myMove = "pl" + getPromoteToB + played + String.valueOf(theBoard[number]);
    }
}

pawn_promote

Essentially, I just added a check to see if it was a pawn promotion when you choose what you are trying to do. Fortunately, there is only one row for black, and one row for white where this maneuver can be done. Be sure to check out the commit for the comparison of the changes.

Linux – keep it simple.

Fool’s Mate Friday: Now with moving pieces!

According to the Guinness World Records, the biggest playable chess set was made in Canada in 2009, with a king that was about 4 feet tall! Try moving that chunk of wood! Fortunately for me, moving these “wooden” chess pieces doesn’t require much by way of heavy lifting!

twoplayer

It isn’t exactly a walk in the park, either though. Making this game two player and movable was actually pretty simple:

public void moveablePiece (View view) {

    // Get the clicked squares tag to see what number it is.
    int number = Integer.parseInt(view.getTag().toString());
    String played;
    if (number < 10) {
        played = "0" + String.valueOf(number);
    } else {
        played = String.valueOf(number);
    }

    if (firstClick) {

        firstClick=false;
        String myMove = tryMove + played + String.valueOf(theBoard[number]);
        Log.i("WJH", myMove);
        moveOptions= terminal("availMoves,"+String.valueOf(wTurn));

        String[] separated = moveOptions.split(",");

        if (Arrays.asList(separated).contains(myMove)) {

            String query = terminal("myMove,"+myMove);
            Log.i("WJH", query);
            drawBoardPieces();
            wTurn = !wTurn;

        }
        tryMove = "";
        myMove = "";
        mCtv.setText(moveOptions);

    } else {

        firstClick=true;
        tryMove = String.valueOf(theBoard[number]) + played;
        Log.i("WJH", tryMove);
        String query = terminal("pieceMoves,"+ String.valueOf(theBoard[number]) +
                "," + played);
        mCtv.setText(query);
    }

} // End clicked piece.

But the problem that I have now is that the method I use to move the pieces doesn’t work well with the engine when it comes to castling, promoting, or en passant. So I may need to adjust the JustChessEngine to be more of a FEN style input/output. We’ll have to see.

Linux – keep it simple.

Fool’s Mate Friday: Identifying the board square by number.

Identification please! Did you know that there have been numerous cases of mistaken identity for the masters of chess in print? There are so many that websites have even devoted entire pages to these mix ups! You can check out some good ones here, where among others, Bernhard Kagan was confused for Alexander Alekhine!

A case of mistaken identity is a bit of a problem. A problem I hope to avoid in my JustChess app. Particularly, I am referring to the pieces that you click on. My next goal of the app is to make it possible to have a human player challenge the JustChess Engine. To do so, I need the player to be able to move the pieces.

clickedjustchess

In retrospect, there may be better ways to do this, but for now, I have tagged all 64 squares of the board, and made them “clickable”. When clicked, the board now returns the tag number. This tag number can simply be cross referenced with the virtual board’s character array to find the corresponding piece. Here’s a break down of the code:

public void moveablePiece (View view) {

    // Get the clicked squares tag to see what number it is.
    int played = Integer.parseInt(view.getTag().toString());

    Log.i("WJH", "clicked sqaure "+ String.valueOf(played));
    Log.i("WJH", "clicked piece "+ theBoard[played]);
    moveOptions= terminal("availMoves,"+String.valueOf(wTurn));
    mCtv.setText(moveOptions);

} // End clicked piece.

What?! Pretty simple isn’t it. All that transpires is the clicked square (which is a view) calls this function and returns it’s own tag. The tag equates to the square number and that number is cross referenced with the board.

Now that the piece is properly identified, I can cross reference it with available moves, highlight those squares, and make it an option to move there, or not move at all. Easy right? Let’s hope so!

Linux – keep it simple.