Is it solid enough?
I finally started pursuing my long-awaited desire to learn KDE libraries. As a matter of fact, I learned Qt because I wanted to code for KDE. But hey, here I am, kind of doing it after 1 year. Anyhow, let’s get straight to the point, I wanted to talk about Solid a little bit. If you don’t know what Solid is, take a look at http://solid.kde.org. In a nutshell, it’s a library which let’s you interact with the hardware. For example, with Solid you can find out if the system has webcam or not, if it has storage drives, and if it does, what kind are they, and plus, if you find the right hardware, you can do ’stuff’ with it, like in case of storage drives, you can mount it and unmount it.
So, enough with the introduction. What I really want to talk about is how awesome Solid is. I will give you an example. Last night, I started reading the Solid documentation from techbase.kde.org and I looked at the tutorials. I started reading them at about 7pm and finished at around 8. As soon as I finished reading the tutorials I was able to write a simple app which looks and finds the memory stick that is attached to the computer. It was absolute mind-blowing for me! I never thought I could do that kind of stuff! But today, I sat down (literally for hours and hours) and wrote a backup app, and I called it KBackedUp. For the actual backing up, it uses a script (http://code.google.com/p/backed-up) as its backend, so it doesn’t do the actual backing up, but it doesn’t the rest.
In the mean time, I also learned about QProcess and KDEUI libraries (KXmlGuiWindow is plain awesome) which I might talk about later. But for now,
Happy holidays!
And here present, Tic-Tac-Toe 0.4!!
I has been sitting there in the svn for a few days now, but I didn’t have the time (school?) to pack it into a tarball (.tar.gz archives) and blog about it. So here it is, ummm among the (rather few) improvement, is a counter which keeps track of your scores for you! Also there are three more options for saving states of the game and the window and whether you want the counter to be shown on startup or not! And also I had to fix some layout issues for the counter. It’s mostly about the counter.
And I’m displeased to announce that I can no longer think about how to improve this game (I wish I could still work on it). So PLEASE (note the capital letters) if you can think of ANYTHING that would improve this game, post a comment or email me or report a bug/wish. It would be really appreciated!
and as always, the download link:
http://code.google.com/p/onlinetictactoe/downloads/list
P.S. By the way, I’m going to talk about SVN and how to use googlecode’s svn repository in the next post!!
autopoker, looking good!
Ladies and Gentlemen, I’m now presenting the most precious invention of mankind ever!!!
ok, don’t take it seriously, I finally managed to gather all the code into one file ( it’s now 4 files! ). Now you can take a look and see what I did so far. If you have any questions or you don’t understand some parts, just comment and I’ll get to you
here’s the link to download a .txt file
change the extension to .cpp and use it
back to our bubbling!
For some time I wasn’t blogging due to some “things” that was going on in my life. Primarily in school! Anyway, the autopoker can now deal the cards, and also is able to detect what you have in your hand ( or each player ) except straight, straight flush, and royal flush. In fact, just the straight one is left. That being finished, the other two ( straight flush && royal flush ) are done.
Now, I wanted to tell you about an interesting thing I learned ( and keep up here and post comments, I will be posting stuff I learn ). It’s a timer. Apparently it’s in “iostream” library or ctime I think. What it does, is that it delays the execution of next command for N seconds/microseconds/nanoseconds depending on you.
This is how you use it:
sleep( N );
where “N” is the number of seconds.
you can also use it this way:
usleep( uN ); //uN is the number of microseconds
nanosleep( nanoN ); //I’m not sure how to actually use this one, but seems to follow other ones. nanoN is the number of nanoseconds.
also, if you want to take the current time for randomization purposes you do:
time( 0 );
which is good for:
srand( time( 0 ) );
I think they are in “ctime” library or “cstdlib” ( cstdlib for randomizing and ctime for time() )
rewriting everything, top to bottom
I finally know how to use classes
yay, the only trick is that you should put it BEFORE int main() which I didn’t know and I used to put it AFTER int main(). The result? error: no “Something something1;” has not type! where Something is a class and something1 is an object. Anyway, I did it and therefore, I rewrote every single line of autopoker.cpp and also created a new header file player.h for it. Today, however, I was talking to my friend on the phone and he accidentally brought up a good point. He said that I can make a card class and instantiate ( create ) 52 objects of that class. Just think about it, FIFTY TWO OBJECTS!!! O_O that’s a lot and takes a lot of time! I might do that though, but first I try to fix the current one!
God bless OOP
I’m still having difficulty implementing OOP ( stands for Object-Oriented Programming ) into my sources. But if you think about it, OOP makes life much easier and faster! Well it doesn’t make life faster but programming at least. And that, in turn, makes life more “enjoyable” specially when you don’t have compile-time errors as I just had! I don’t know why it just doesn’t work! OOP I mean. And that is exactly why I’m passionately waiting for my book C++ How to Program ( a great book by the way ) to come. Its early classes approach is what I was looking for. I doesn’t really make you wait years ( figuratively ) to know what is a class and what is an object, which are, in fact, what make C++, a real C++. Anyway, I gave up on classes and OOP for now till my book comes and I can finally see how to work efficiently with objects. For now, I think the development of autopoker.cpp ( refer to previous posts && the same as poker.cpp just changed the name ) is in a soft freeze
because of the fact that I can’t think of ANY way to continue it without classification ( implementing OOP ). And because I don’t know how to work with objects, therefore, it’s stalled!
first bits of poker.cpp
It’s going well, I’m working on the first bits of it. Some starting points such as just shuffling and dealing a deck of cards.
This is what I’ve got so far:
//put random numbers in slots
#include iostream
#include ctime
#include cstdlib
#include iomanip
using namespace std;
int main ()
{
const int totalCards = 52;
const int deckRows = 4;
const int deckColumns = 13;
int deck[ deckRows ][ deckColumns ] = { 0 };
char *suite[] = { “Hearts”, “Clubs”, “Diamonds”, “Spades” };
char *face[] = { “Ace”, “Two”, “Three”, “Four”, “Five”, “Six”, “Seven”, “Eight”, “Nine”, “Ten”, “Jack”, “Queen”, “King” };
srand( time( 0 ) );
for( int card = 1; card <= totalCards; card++ ) {
int randrow = rand() % deckRows;
int randcolumn = rand() % deckColumns;
while( deck[randrow][randcolumn] != 0 ) {
randrow = rand() % 4;
randcolumn = rand() % 13;
}
deck[randrow][randcolumn] = card;
}
/*
//print the deck
for( int i = 0; i < deckRows; i++ ) {
for( int j = 0; j < deckColumns; j++ ) {
cout << setw( 5 ) << deck[ i ][ j ] << ” “;
}
cout << endl;
}
//check for wrong numbers
for( int x = 0; x < deckRows; x++ ) {
for( int y = 0; y 52 || deck[ x ][ y ] < 1 ) {
cout << “INVALID NUMBER DETECTED IN LOCATION: ” << x << “, ” << y << endl;
}
}
}
*/
for( int card = 1; card < totalCards; card++ ) {
for( int i = 0; i < deckRows; i++ ) {
for( int j = 0; j < deckColumns; j++ ) {
if( deck[ i ][ j ] == card ) {
cout << face[ j ] << ” of ” << suite[ i ] << endl;
}
}
}
}
}
again, add the indentation yourself!
It essentially shuffles a deck of cards and deals all 52 cards and says what they are in order! If you don’t understand part of the code, just let me know by writing a comment!
put random numbers in slots!
I did it finally! a very easy thing but quite annoying because I didn’t know my mistake and I still don’t know it. Here is the code I was “working on” for the last 2 days:
//put random numbers in slots
#include iostream
#include cstdlib
#include ctime
#include iomanip
using namespace std;
int main ()
{
const int totalCards = 52;
const int arrayRows = 4;
const int arrayColumns = 13;
int array[ arrayRows ][ arrayColumns ] = { 0 };
srand( time( 0 ) );
for( int card = 1; card <= totalCards; card++ ) {
int randrow = rand() % arrayRows;
int randcolumn = rand() % arrayColumns;
while( array[randrow][randcolumn] != 0 ) {
randrow = rand() % 4;
randcolumn = rand() % 13;
}
array[randrow][randcolumn] = card;
}
//print the array
for( int i = 0; i < arrayRows; i++ ) {
for( int j = 0; j < arrayColumns; j++ ) {
cout << setw( 5 ) << array[ i ][ j ] << " ";
}
cout << endl;
}
//check for wrong numbers
for( int x = 0; x < arrayRows; x++ ) {
for( int y = 0; y 52 || array[ x ][ y ] < 1 ) {
cout << "INVALID NUMBER DETECTED IN LOCATION: " << x << ", " << y << endl;
}
}
}
}
Anyway, this doesn’t have any mistakes but it uses a very very very poor algorithm of “retry if it’s taken.” Well, I know that, but I will try to work on a better algorithm for it! Or maybe make it into a bigger thing! Programming is fun, but up to when you don’t have any mistakes. Leave comments if you are thinking of a better algorithm ![]()
And by the way, I finished my math exam last Thursday, it was easy as always! Looking forward to next semester when I have Physics 12
must be better than Physics 11 I had this semester!
Also, indent this code yourself, this blog doesn’t show indentation! and put “” around cstdlib, iomanip, ctime, and iostream!
Don’t forget to comment!