Queen, picoEngine?

picoEngineQueen

In my most recent commit, which you can check out in full at my GitLab, I added the ability for the queen to move to the picoEngine. This completes all of the major/minor pieces of motion, and only leaves the king and pawns to complete (believe it or not, these are the hardest to do, as they have many conditional clauses).

I actually was able to hammer this out in about 15 minutes, since it really is just a combination of the rook and bishop moves with a “q” instead of the respective letters. Since it is identical to those, I wont post much of the code here. If you are wondering, however, how I add them to the header files, it looks like this in Moves.h:

#pragma once
#include <cmath>
#include <string>
using namespace std;

class Moves {

private:
char m_theBoard[64] = {‘R’,’N’,’B’,’Q’,’K’,’B’,’N’,’R’,’P’,’P’,’P’,’P’,’P’,
‘P’,’P’,’P’,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,
‘-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,’-‘,
‘-‘,’p’,’p’,’p’,’p’,’p’,’p’,’p’,’p’,’r’,’n’,’b’,’q’,’k’,’b’,’n’,’r’};

bool m_whitesTurn = true;
bool m_Kcastle = true;
bool m_Qcastle = true;
bool m_kcastle = true;
bool m_qcastle = true;
bool m_enPassant = false;
string m_enPasPawn = “”;
int m_moveSince = 0;
int m_turnCount = 0;
// Public prototypes go here
public:

// All available moves.
string available(string boardPositions, bool whoseTurn);

// Best move.
string bestMove(string boardPositions, bool whoseTurn, bool styleRandom);

// Is the king safe?
bool isKingSafe(string boardPositions, bool whoseTurn);

// Black night moves:
string nightMovesB(string boardPositions, int i);
// white night moves:
string nightMoves(string boardPositions, int i);
// Black rook moves:
string rookMovesB(string boardPositions, int i);
// white rook moves:
string rookMoves(string boardPositions, int i);
// Black bishop moves:
string bishopMovesB(string boardPositions, int i);
// white bishop moves:
string bishopMoves(string boardPositions, int i);
// Black queen moves:
string queenMovesB(string boardPositions, int i);
// white queen moves:
string queenMoves(string boardPositions, int i);

};

After adding the command option to the header file, then I can actually create it in the Moves.cpp file:

string Moves::queenMoves(string boardPositions, int i) {
————– Abridged, see commit for details. ——————-
} // End white queen moves.

Object oriented programming (oop) is a really fun way to program. The top 2 programming languages used for video games today are Java and C++, which are both oop types of programming. Since Android devices now make up more percentage of the worlds operating system than any other operating system, and most Android games are written in oop like Java and C++, that makes sense. But even most desktop games are made with these languages as well.

Linux – keep it simple.

Advertisements

Bishops aren’t Bums…

picoengineBishop

Believe it or not, the bishops can now move! 3 of the 6 piece types now have the complete freedom of movement that they should have on the regular board! Things seem to be making steady progress, although I still see some issues with kingSafety, so I’ll have to work on that!

There is also an issue with odd positions. If you start a new game as normal. All is well for picoEngine, and it can track moves as usual. However, if you use the interface to adjust the piece positions, picoEngine will only track the first move, subsequent moves cause an illegal exception. So that needs to be looked into. Also, picoEngine does not like Chess960!

As always, the full commit is available on GitHub, if you’d like to see how the bishops get their move on. It is very similar to the rook motion, but diagonally placed.

Linux – keep it simple.

Uh, picoEngine? I thought you said the king was safe?

kingsafe

Except he’s not. That’s right. I big technical oversight on my part allowed the king to not be safe at all!

while (boardPositions[k] == ‘*’ && notI) {

Needed to be changed to:

while (boardPositions[k] == ‘-‘ && notI) {

That’s right! A – is what my board uses for empty spaces. But the Java board I wrote for JustChessEngine used an * instead. I guess I got confused when looking at the code and put it in the wrong way! Too much copy and paste from my Java work I suppose. Either way, the king is safer now!

Linux – keep it simple.

picoEngine is such a rook-ie!

picoEngineRook

Now the rooks can move too!

While it is only a small improvement, the rooks can now also be moved by picoEngine, which is a great step forward. Overall, that leaves 2 of 6 pieces complete for motion, or about 33% complete. Technically, when that is done, the engine will be completely playable, however, much work will be needed to make it “intelligent”.

While there are probably better ways to do this, I followed a pretty simple pattern for making the rook moves:

// Up moves
bool notI = true;
int j = 1;
int vert = 8;
int k = i;
if (i < 56) {
k = i + (vert * j);
}
while (theBoard[k] == ‘-‘ && notI) {
theseMoves.push_back(k);
vert += 8;
if (k < 56) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it’s empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.

// Down moves
notI = true;
j = -1;
vert = 8;
k = i;
if (i > 7) {
k = i + (vert * j);
}
while (theBoard[k] == ‘-‘ && notI) {
theseMoves.push_back(k);
vert += 8;
if (k >7) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it’s empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.

That is for “up” moves, and the pattern repeats for down, left, and right. As always, you can check out the full commit on my GitLab.

Linux – keep it simple.

Happy New Year Everyone!

Happy New Year everyone!

I’ve done a lot of posts the last year, and thanks to those of you who read them, like them, follow/subscribe to them as well. Last year I also started a YouTube channel where I do my best to help others learn how to compile Android from source, as well as build apps and make custom roms and recoveries.

I hope this year will bring other new and interesting developments as well. I recently received my ham radio license, so I hope that I can incorporate some neat ham radio projects as well as continue to work on Android and other electronics like Arduino.

Thanks again, and have a great new year!

Linux – keep it simple.

BLU Life XL (L0050UU) TWRP Complete!

I was fortunate enough to be given a used BLU Life XL (L0050UU) from my sister when she upgraded her phone. The great part about having a new toy is getting to build Android for it from scratch, since no one has made custom roms for it yet. But to God be the glory, today I just completed making TWRP for it, so it will have a custom recovery to make backups and flash the new roms I’m hoping to make.

You can download the TWRP image here: http://www.mediafire.com/folder/vh3urh1yuybmn/Life_XL_(L0050UU)

And, as always you can check out the device tree on my GitLab!

Linux – keep it simple.

Make a move picoEngine….

picoEngineMoves

For the first time ever, picoEngine made it’s very own move.

While no where near as important as my children taking their first steps, it was really a monumental moment for me when picoEngine made it’s very first move using UCI commands while loaded in Arena. That’s right, after several hours of tinkering, I loaded the picoEngine into the chess application called Arena, and let it make it’s very first move!

Of course, at this point, the only thing it can move is the knight, since that’s all I’ve programmed it for, but still, it was a monumental step in the direction of C++ chess engine programming for me!

While I’ve made two chess engines in Java, for various Android apps, this is different. Not only am I programming in C++, but my goal is to use the Universal Chess Interface so my chess engine can be loaded into any chess program. That is making things a bit tough. But now that I have successfully made a move, hopefully it will be smooth sailing from here on out.

string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom){
string candidateList = Moves::available(boardPositions, whoseTurn);
string chosenMove = “”;
if (candidateList.size() > 0){
//if (styleRandom) {
srand((int)time(0) + candidateList.size());
int r = (rand() % (candidateList.size()/5));
for (int a = 0; a < 4; a++) {
chosenMove += candidateList[(5*r)+a];
}
//} else {

//}
}
return chosenMove;
}

The check for available moves and king safety are things we already covered, so essentially, I just needed to make it choose the best move of the ones available. In the future, this will hopefully be a weighted decision, but for now, I’m just passing a random choice of the available moves in the list, which, of course, only features the knights at present.

As always, you can check out the full commit on my GitLab.

Linux – keep it simple.

Merry Christmas To You!

Once again, it is Christmas day, and I want to wish you a very merry Christmas! I pray that God would bless you as he did me and everyone else when he sent his son!

The First Noel the angel did say
Was to certain poor shepherds
in fields as they lay;
In fields as they lay, keeping their sheep,
On a cold winter’s night that was so deep.

Noel, Noel, Noel, Noel,
Born is the King of Israel.

They looked up and saw a star
Shining in the east beyond them far,
And to the earth it gave great light,
And so it continued both day and night.

And by the light of that same star
Three wise men came from country far;
To seek for a king was their intent,
And to follow the star wherever it went.

This star drew nigh to the northwest,
O’er Bethlehem it took it rest,
And there it did both stop and stay
Right over the place where Jesus lay.

Then entered in those wise men three
Full reverently upon their knee,
and offered there in his presence
Their gold, and myrrh, and frankincense.

Then let us all with one accord
Sing praises to our heavenly Lord;
That hath made heaven and earth of naught,
And with his blood mankind hath bought

Linux – keep it simple.

picoEngine meets Bob Seger….

nightmoves

Okay, so not really. Bob Seger once had a hit called “Night moves” which is what I just added to my picoEngine: knight moves. As always, you can check through the whole commit on my GitLab. Once again, I borrowed from my Java engine, justchess engine but had to do quite a bit of work to convert this method into C++. For instance, in Java, I make an array, but in C++ I had to set up a vector.

Overall, the code is cleaner and more compact for C++ than it was for Java. I’m not sure if it is because I am getting better, or just the language differences, but I’ll take it! I’m still a bit fuzzy about comparing signed and unsigned commits, so I have to keep editing my loops like so:

for(int l=0; (unsigned)l<theseMoves.size();l++) {

Making sure to put the parenthesis and unsigned before the integer. But, it seems to work, so I’ll go with that for now, perhaps later I can study up on it a bit more and see why this is needed.

Linux – keep it simple.