Added a display for the list of possible moves to the Beginner Chess Engine

Well, if you were wondering what I was doing with my spare time, this is it!

possibleMoves

I just added a TextView to display the move options that the computer had available. Not real fancy, but it allows me to “watch” what’s going on without the debugger running. You can check out the commit here:

https://github.com/alaskalinuxuser/BeginnerChessEngine/commit/c81721cc0d6e8d301e4924d4d2f0de233c06b744

Linux – keep it simple.

Advertisements

Added reset button to the Beginning Chess Engine app, but it doesn’t do what you think….

As you can see, I added a reset button to the app for the Beginning Chess Engine.

added_reset

Originally, I had intended to have the board simply reset back to the starting position. However, for some odd reason, when I would reset the board pieces, odd things would happen….

Like a rook would randomly turn into a king when you move the knight.

So, I decided to have the app close, and then call itself to be opened again a few milliseconds later. It’s a little odd, since the app “closes” and then “opens” again, so it looks like it crashed, only to pop up again.

If this were my chess playing app, I would need to focus in on that a little more, however, I am trying to focus on the engine itself, not the remnants that are somehow misconstrued during recreating the original board.

Here’s the commit:

https://github.com/alaskalinuxuser/BeginnerChessEngine/commit/3f6aae2c2e5327d341e15cb50c9d702dc4356fd7

And one issue closed! Only 9+ more to go!

Linux – keep it simple.

Beginner chess engine has a new repository!

The beginner chess engine has a brand new repository so I can more accurately track issues. Before, it was a small part of a larger repository holding different programs, but I have so many issues that I wasn’t to track, that it became difficult to use in that manner.

So, I’ve opened a fresh repository for it:

https://github.com/alaskalinuxuser/BeginnerChessEngine

Be sure to check it out and see all of the issues that I am tracking! Also, of you try it out, you are welcome to add issues as well.

Note: This beginner chess engine is just a simple chess engine that is programmed by a beginner (me), but also recognize that the goal is a drop in engine that is open source for other programmers to use to make their own chess games on Android (or perhaps other) devices.

With that in mind, the app is supposed to allow controls for the engine tester to try things out, and adjust settings for use in their projects. Not so much for the user to play chess, although I hope to make a chess playing app in the future as well.

Linux – keep it simple.

The trouble with knights….

The trouble with knights….

In the continuing saga of making my own chess engine for Android, I’ve run into a peculiarity: If the king is in check, and the only move is a knight to capture the enemy to save the king, the app crashes. So, I added a try/catch block to the command to keep it from crashing. Then, instead of crashing, it would give me an error of the string being out of bounds. I placed the below log.i commands in to see the value of each character, so I could find the problem.

What I saw was that the king piece has no moves, so it was returning no moves at all. Odd, because if I insert a bishop to solve the problem, it would. The real issue still lies with the knight not reporting a valid move. Ironically, if I removed all other pieces, the knight can capture the enemy piece. Very, very odd….

[QUOTE]
public static void makeMove(String move) {
/*public static void makeMove(String move) {
int xf,yf,xt,yt;
//x1,y1,x2,y2,captured piece
if (move.charAt(4)!=’C’ && move.charAt(4)!=’P’) {
{
xt=Character.getNumericValue(move.charAt(2));
}
yt=Character.getNumericValue(move.charAt(3));
xf=Character.getNumericValue(move.charAt(0));
yf=Character.getNumericValue(move.charAt(1));
}
}*/
Log.i(“WJH”, String.valueOf(move.charAt(1)));
Log.i(“WJH”, String.valueOf(move.charAt(2)));
Log.i(“WJH”, String.valueOf(move.charAt(3)));
Log.i(“WJH”, String.valueOf(move.charAt(4)));

if (move.length() < 4) {
Log.i(“WJH”, “That piece cannot move.”);
} else {

if (move.charAt(4) != ‘P’) {
chessBoard[Character.getNumericValue(move.charAt(2))][Character.getNumericValue(move.charAt(3))] = chessBoard[Character.getNumericValue(move.charAt(0))][Character.getNumericValue(move.charAt(1))];
chessBoard[Character.getNumericValue(move.charAt(0))][Character.getNumericValue(move.charAt(1))] = ” “;
if (“K”.equals(chessBoard[Character.getNumericValue(move.charAt(2))][Character.getNumericValue(move.charAt(3))])) {
kingPositionC = 8 * Character.getNumericValue(move.charAt(2)) + Character.getNumericValue(move.charAt(3));
}
} else {
//if pawn promotion
chessBoard[1][Character.getNumericValue(move.charAt(0))] = ” “;
chessBoard[0][Character.getNumericValue(move.charAt(1))] = String.valueOf(move.charAt(3));
}
}
} // End makeMove
[/QUOTE]

Then, I decided to disable the kingsafe() check protocol, as seen here:
[QUOTE]
public static String posibleN(int i) {
String list=””, oldPiece;
int r=i/8, c=i%8;
for (int j=-1; j<=1; j+=2) {
for (int k=-1; k<=1; k+=2) {
try {
if (Character.isLowerCase(chessBoard[r+j][c+k*2].charAt(0)) || ” “.equals(chessBoard[r+j][c+k*2])) {
oldPiece=chessBoard[r+j][c+k*2];
chessBoard[r][c]=” “;
//if (kingSafe()) {
list=list+r+c+(r+j)+(c+k*2)+oldPiece;
//}
chessBoard[r][c]=”N”;
chessBoard[r+j][c+k*2]=oldPiece;
}
} catch (Exception e) {}
try {
if (Character.isLowerCase(chessBoard[r+j*2][c+k].charAt(0)) || ” “.equals(chessBoard[r+j*2][c+k])) {
oldPiece=chessBoard[r+j*2][c+k];
chessBoard[r][c]=” “;
//if (kingSafe()) {
list=list+r+c+(r+j*2)+(c+k)+oldPiece;
//}
chessBoard[r][c]=”N”;
chessBoard[r+j*2][c+k]=oldPiece;
}
} catch (Exception e) {}
}
}
return list;
} // End possible knight moves.
[/QUOTE]

By disabling kingsafe(), the knight was then able to move and capture the enemy piece that was threatening the king. Odd. Very odd. In the kingSafe() function, it is split for bishop/queen, and rook/queen, so I thought I would check to see if this is a bishop/queen problem, or a more general issue. Turns out it is not a specific bishop/queen attack problem, because a rook/queen attack also does not allow the knight to capture the attacker.

If I disable the kingSafe() check for the knight, then I proved the knight would move to capture a rook, only to open up an attack from a bishop. That obviously will not do. However, a very, very careful review of the rook’s code, versus the knight’s code revealed the mistake! See the code here:

[QUOTE]
++++++++++++++++++ KNIGHT +++++++++++++++++++++++++++
try {
if (Character.isLowerCase(chessBoard[r+j][c+k*2].charAt(0)) || ” “.equals(chessBoard[r+j][c+k*2])) {
oldPiece=chessBoard[r+j][c+k*2];
chessBoard[r][c]=” “;
//if (kingSafe()) {
list=list+r+c+(r+j)+(c+k*2)+oldPiece;
//}
chessBoard[r][c]=”N”;
chessBoard[r+j][c+k*2]=oldPiece;
}
}
++++++++++++++++++ ROOK ++++++++++++++++++++
if (Character.isLowerCase(chessBoard[r+temp*j][c].charAt(0))) {
oldPiece=chessBoard[r+temp*j][c];
chessBoard[r][c]=” “;
chessBoard[r+temp*j][c]=”R”;
if (kingSafe()) {
list=list+r+c+(r+temp*j)+c+oldPiece;
}
chessBoard[r][c]=”R”;
chessBoard[r+temp*j][c]=oldPiece;
}
[/QUOTE]

Notice that the rook “flow chart” as it were:
if the enemy is a bad guy, or blank, then {
write down what was there.
make the rook’s previous position empty.
place the rook in the new position.
NOW CHECK IF KING IS SAFE.
IF IT IS, MAKE THAT A PERMANENT MOVE.
IF NOT, PUT IT BACK.

Now look at the “flow chart for the knight:
if the enemy is a bad guy, or blank, then {
write down what was there.
make the knight’s previous position empty.

NOW CHECK IF KING IS SAFE.
IF IT IS, MAKE THAT A PERMANENT MOVE.
IF NOT, PUT IT BACK.

So, as you can see, the knight is not in the “new” position, thus the old piece is still there! With a quick re-write of that portion of code, then the knight worked as expected!

[QUOTE]
public static String posibleN(int i) {
String list=””, oldPiece;
int r=i/8, c=i%8;
for (int j=-1; j<=1; j+=2) {
for (int k=-1; k<=1; k+=2) {
try {
if (Character.isLowerCase(chessBoard[r+j][c+k*2].charAt(0)) || ” “.equals(chessBoard[r+j][c+k*2])) {
oldPiece=chessBoard[r+j][c+k*2];
chessBoard[r][c]=” “;
chessBoard[r+j][c+k*2]=”N”;
if (kingSafe()) {
list=list+r+c+(r+j)+(c+k*2)+oldPiece;
}
chessBoard[r][c]=”N”;
chessBoard[r+j][c+k*2]=oldPiece;
}
} catch (Exception e) {}
try {
if (Character.isLowerCase(chessBoard[r+j*2][c+k].charAt(0)) || ” “.equals(chessBoard[r+j*2][c+k])) {
oldPiece=chessBoard[r+j*2][c+k];
chessBoard[r][c]=” “;
chessBoard[r+j*2][c+k]=”N”;
if (kingSafe()) {
list=list+r+c+(r+j*2)+(c+k)+oldPiece;
}
chessBoard[r][c]=”N”;
chessBoard[r+j*2][c+k]=oldPiece;
}
} catch (Exception e) {}
}
}
return list;
} // End possible knight moves.
[/QUOTE]

Believe it or not, that was actually the most fun I have ever had programming in Java! Now I just have to solve the other ump-teen problems! Be sure to check out the commit here: https://github.com/alaskalinuxuser/apps_small/commit/0cd506f76578267c027b742e0de40fda392fd163.

Linux – keep it simple.

Beginner chess engine

As I continue to work on my java chess engine for Android, I’ve decided on a name for it, “beginner chess engine”. I just posted the latest commits here:

https://github.com/alaskalinuxuser/apps_small/commit/cda1b197c7d48b71f45b6ce001cfa6a9482a1ba0

It’s not quite finished yet, and still needs more adjusting, changing, and tweaking. A large portion of the engine is based off of Logic Crazy’s tutorial on building chess engines. I have made some modifications and adjustments, mainly to get it working in Android, but also some adjustments of the engine parameters. I will be making more adjustments as time goes on.

So far, here is what the engine allows you to do:

Using the command in the MainActivity.java file, you can request the list of possible moves, as well as the alpha-beta determined next best move.

The move possibilities are handled in the thinktank.java file, and the rating.java file handles the rating, or score, of each move. The userinterface.java file controls moving the pieces and drawing the board.

Here are the current problems:

-Castle, currently to castle is not a move possibility.

-Promotion, currently, the pawns can capture and advance to the final row, but I need to fix the promotion to another piece.

-There is something wrong with knowing the king is in check. The engine knows the king is not safe, but it doesn’t have a problem with the fact that the king could be killed. Obviously, that is not right.

And here are some of my goals for this engine:

-To allow moves to be entered by standard notation.

-To report moves in standard notation.

-To allow time determined moves.

-To fix the problems. (Obviously)

-To allow engine control by standard international chess engine commands.

-To allow user adjustment controls.

-To provide an open source chess engine for other Android chess developers or game makers.

-To have fun, and learn more about chess!

So far, I’ve built the app that you can grab from the repository that is literally just a visual way to test the engine. As you can see, you can adjust the ply, and have the engine make the next move.

Warning: Every ply is a multiple of available moves, averaging about 20. So 4 ply is 160000 moves to calculate in the alpha beta tree. Most cell phones that I have can only calculate 3 ply without crashing. In the Android Studio AVD manager, I can load up the emulator and calculate about 6 ply. Hopefully I can streamline the process a bit so it takes less power to calculate.

Also, the more ply, the longer it takes to think. So, on my Galaxy S4, 2 ply takes about 8 – 10 seconds, and 3 ply takes 30 – 60 seconds, with 4 ply (if it doesn’t crash) taking up to 3 minutes.

Hope you enjoy the engine, and hopefully I can one day get it polished enough for gamers to use!

Linux – keep it simple.

Google’s Play Console App

Most people who are placing their apps on the Google Play Store are already aware of the Android version of the Play Console App. It’s an app to monitor the distribution of your apps. At first I was a bit skeptical of why I would need this tool, but I have to admit, it is a pretty handy to for keeping track of your apps which are on the Play Store.

It is a fairly straightforward and intuitive tool. Click on the app that you want to see and you will be instantly greeted with all the usual statistics you need. One one page they have placed the latest installs/uninstalls as well as your feedback and ratings. They even included your recent crashes that were reported to Google. That’s a lot of information in one spot.

By the way, if your version doesn’t look like mine, you might want to try out substratum for theme options. Here I am using Pitch Black Origins.

Some of the greatest features are the instant alerts if you want to know the minute that someone leaves you a review. For instance, you can select to know when you get any review, or if you just want reviews for 1 or 5 or any other number of stars. I can see how that might actually get annoying, if you were to develop an app that millions of people download, but for a small time app maker like myself, it doesn’t happen often enough to be a problem.

Another great feature is being able to read the reviews and respond to them. I was sure to show you one of my all time favorite comments that I received. But, for better or worse, it is nice to get a notification and an opportunity to respond to your customer feedback.

One thing I have noticed, though, is that there is a delay between collected data, and data pushed to your device. The ratings and customer reviews seem to happen instantly, but the data for the statistics seems to be one to three days behind. That’s not much of an issue for me, my apps stats are changing so slowly that it is easy to catch up, but if you needed the moment by moment charts, you might be better off by logging into the Play Console website instead.

While I haven’t searched out the depths of the Play Console App, I think it is a pretty neat tool overall. It’s great to get all of those statistics at a glance for your app.
Linux – keep it simple.

SanDisk Sansa: Rockboxed!

A while back my brother gave me a SanDisk Sansa. It’s a great little music player about the size of a zippo lighter. In and of itself, that would be pretty cool, but in this case he stepped it up a notch by not only giving me the gift, but also taking the time before hand to Rockbox it!

If you have never heard of Rockbox, it is an open source firmware specifically designed for mp3 players, iPods, and other music listening devices. Essentially it replaces the entire operating system (or dual boots, in some cases) with a new operating system with games, applications, file managers, and a music player. Pretty cool stuff! You can read more about it here: https://www.rockbox.org.

As for my Sansa, it is a great little unit with a belt clip, volume, home, power, and a four way directional pad. It also includes an SD card slot for micro cards, an earphone jack and a USB plug. With Rockbox installed, I can play chess, blackjack, and even doom (although doom is hard to play on this small screen). Applications include a clock, alarm clocks, calculator, calendar, dictionary, text editor, stop watch, and more!

Of course, the main feature is the music player. I’ve been using it allot in my truck, hooked up to the stereo to listen to the Bible while I drive. The controls are intuitive and simple, and everything seems really well laid out. You can even adjust all the usual settings, like bass, treble, etc., which is great for when I switch to jazz, like Lady Day (Billie Holiday).

Even the display is adjustable with themes. I loaded the cabbiev2 theme, as you can see in the pics. There are lots of themes to chose from on the Rockbox website, or you can make your own.

Road testing the unit seems to be going really well. The battery is phenomenal on this thing, as I have only had to charge it every couple of weeks, although I usually only use it about 30-40 minutes per day, but that seems pretty good to me! If you are looking for a music player, be sure to check out Rockbox and get something compatible, is day it is worth it!

Linux – keep it simple.

Android Studio emulator stopped launching after upgrade in Ubuntu 16

I don’t usually re-post something that someone else figured out, but it took me a long time to figure this out, so I thought I would share here.

The problem I had was relating to Android Studio and the emulator. I was using the emulator to test out various programs that I was working on, but it stopped working after an update. I didn’t realize it right away, as I often use my actual cell phone, rather than the emulator. I find that I can tap faster with my finger than I can click with the mouse.

Either way, some time after I did an update, I decided to use the emulator. Unfortunately it didn’t work. Not only did it not work, there were no errors. I actually had no idea of why it stopped functioning. Thus started my search for an answer. I tried just about everything before finding the right answer.

The first thing I tried was deleting and remaking a device with the AVD. Still no luck. Other people were suggesting that I move my entire Android Studio folder into the SDK folder. That didn’t work either.

Still others were deleting the AVD folder and then creating new emulators. This still was not the solution. Finally, though, I found a solution that worked:

$ cd ~/Android/Sdk/emulator/lib64/libstdc++/
$ mv libstdc++.so.6 libstdc++.so.6.bak
$ mv libstdc++.so.6.0.18 libstdc++.so.6.0.18.bak
$ ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ~/Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6
$ ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 ~/Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6.0.22

Lest that you think I came up with this on my own, I didn’t. I found it here on Stack Overflow, by user¬†Martin Revert. How he came to this conclusion is beyond me, but I’m glad that he shared it, because it was just what I needed!

Hopefully, that will save someone from trying everything under the sun to fix this problem.

Linux – keep it simple.

Making an Android chess app….

begginerchess

Lately I’ve been amusing myself in my spare time by learning how to make a chess engine. I don’t want anyone to think that I came up with this on my own, I’m taking a tutorial through Youtube videos by a man called Logic Crazy. Be sure to check out the link for his tutorial, I’ve found it to be fun and informative!

Logic Crazy seems to have a website with several other variants of chess engines, as well as engines for a couple of different games. And that is also worthy of a good long look. For myself, I’m just trying to learn the basics of Java programming.

Logic Crazy’s design is for an actual Java program to be run on your computer. I on the other hand, am adapting it for an app to be used on an Android phone, which I’m hoping will be fun, but also a great learning experience. My free time is a little bit limited these days, but hopefully you’ll be seeing more posts about it soon.

Linux – keep it simple.

MechDome just got a whole lot more expensive….

I was really excited as an Android developer (probably an insult to real Android app makers, but I try…) when I heard about MechDome. If you read any of my earlier posts about MechDome, you can see that it is a really neat converter, which takes your finished APK, and turns it into an iOS program for iPhones. That in itself is pretty cool. One thing they also did, was create a program for open source users, making a purchase cost of $25 per open source app which is converted.

Recently, they have opened up their website and now are allowing subscriptions to be purchased by developers who wish to convert their apps. Unfortunately, it looks really expensive. According to the displayed price when I checked on my open source app, having a Pro subscription costs a little over $1500 per month! That is quite a bit more than I was thinking. Certainly way more than I was hoping for when it came to prices. Actually, I’m not really sure that I know any groups of developers that can afford that price.

At a cost of $1599, per the advertisement, you can convert one app 3 times per month, and up to 5 times per week in the simulator. Essentially, you can test it every workday in the simulator, but only 3 times a month can you actually convert your one app to a file which is useful on iOS devices. These guys are really, really smart, but I’m not sure that is going to work.

There is a “basic” package, however, it is not selectable for me when I click on it. That says to me that it requires me to put in my credit card information first, or that option is not available yet. Either one doesn’t bode well with me. Presumably, since the Pro package is 3 conversions per month, the basic package must only be one conversion per month, or perhaps a one time, one conversion cost.

Consider a few metrics in the finance department: If your app sold for $1.99 on the Apple store, you would need to sell 800 app downloads per month, and that only covers your MechDome expense, let alone the Apple play store fees. If you are banking on add revenue, with a HIGH revenue of .10c per playtime in advertisements, you would need 159900 people to play your app every month just to break even.

If you consider the yearly cost, you are planning to pay just under $20000 per year for that app to be on the Apple play store. If you took that $19, 200, you could easily pay for an app to be converted the “old fashioned” way, and then have all of the source code available for future work. If you use MechDome, and ever decide to stop, you are out all of your money with no way to continue development.

There certainly are apps out there that easily meet that criteria. Big apps will probably quickly overshadow that market. However, if you have an app that generates that much revenue, then you probably want to hire someone, or a team for iOS development. Mainly because there are some quirks with the converted apps. For instance, in my simple app tests, some of the colors are not the same in the converted app. If you are designing a big ticket app, then you will have a team of people making sure that your app looks “just right” on iOS as well. Let alone that you can’t use certain types of resources or libraries in your app, like libGDX, the graphics engine used in tons of games.

To be honest, I thought MechDome would have the best market share targeting midrange to low range applications. Apps that are too small to have a full iOS development team, but that are big enough to generate revenue on an iPhone market. This may sound laughable, but I was figuring on prices that were much cheaper, something in the $300 range. Actually, when I saw the price, I thought that was a Pro account price for multiple apps, but $1600 per month for just one app?

I’ve been wrong before, though. I only have one app that garnered more than 800 downloads, and that certainly is not per month! And my app was free! It just seems to me that if you have a great app which is making you enough money on Android that you want to put it on iOS, you could take this huge chunk of money and make much wiser decisions with your resources. It is a bummer, because I still think MechDome is one of the coolest tools/ideas of the decade when it comes to mobile app development.

I do still appreciate that they have reached out to open source developers with a one time conversion fee of $25, because that seems pretty reasonable. How well will their pricing work out in the future? Well that remains to be seen, but I wish them the best, I certainly would not be able to afford their new prices.

Linux – keep it simple.