Showing posts with label tech tutorial. Show all posts
Showing posts with label tech tutorial. Show all posts

Sunday, August 7, 2011

Learning AI for Games

Understanding Artificial Intelligence

To understand AI for games you want to have a basic understanding of general AI. This will make it easier to understand and expand on later. Lets dive right into some basic AI!

Introduction to AI

AI, short for Artificial Intelligence is replicating the human thought process with computers. AI alone is a broad topic but luckily we are only focusing on game AI. Now to give a basic example of a simple thought process that's purely logical.

*Sorry for the small text in the diagram

This example is very simple and straight forward. Notice how it doesn't really act like a human necessarily would. It doesn't have any human emotion or feelings.

Lets aim at a more realistic approach instead. I show a more detailed human-realistic diagram below.

*Sorry for the small text in the diagram

With this little add-on we get a bit more complex as you or I would think. This extra decision gives it a better human thought. Now if you wanted to go more in depth you could add feelings. For example if you felt sick you wouldn't eat or if you were tired you would eat to gain energy. 

Now we will move onto AI in games and the types.

AI in Games

There are three general AI types in games. They each are for certain tasks such as following the player. The following three are game AI types.

  • Roaming AI
  • Behavioral AI
  • Strategic AI
Roaming AI

Roaming AI is basically AI that move certain ways. It makes decisions based on whats around it. Types of roaming AI are chasing, evading, and patterned roaming. Each have their own specialties.

Chasing

Chasing is a type of Roaming AI which chases another object. AN example of this is shown.

The square is coded to chase the circle where ever it goes. The circle is going in a circle making it harder for the square to get it. Now how this would work is the square would check the circles position and decide the quickest way to get the circle. In other words the square would check the circles x and y coordinates.  

Evading

Evading is much like chasing but opposite. An object avoids another object and attempts to get away. A quick example is as shown.

The square attempts to get away from the circle. What the square does is looks at the circles position and goes away from it.

Patterned Roaming

Patterned roaming is basically a set pattern of which an object follows. An example would look something like this.

The square is set to go in a figure eight while the circle goes in a circle. This is all that those shapes are coded to do.

That covers all roaming AI, next I will move onto behavioral AI.

Behavioral AI

Behavioral AI is basically roaming AI that`s much more complex. Instead of an object always following the same instructions it has multiple decisions. Here`s a basic example. 

The square has a 50% chance of chasing the circle, 10% to run away, and 40% to move around randomly. This gives a more complex approach offering decisions instead of one rule.

Aggressive and Passive Example

To give a better example I will show two different types of shapes. One being passive and one being aggressive.

The square is the aggressive shape and the circle is passive. Since the square is aggressive it is 50% likely to chase the circle. It still has 45% to wander and 5% to evade. While the circle is 50% to evade from the square and 40% chance of wandering. It also has a 10% chance of staying still. Each of these shapes are very different because one is aggressive and one is passive.

Next I will be moving onto strategic AI which is much more complex.

Strategic AI

Strategic AI is an interesting type of AI. This AI basically must follow rules of a game. This is the AI you would play against in a chess game. A good example is a game called Age of Empires 3. You could play against the AI but they had to play with the same rules you had so the game was fair. A really fun thing I used to do was open up the editor and watch two AI players vs each other. It was very interesting to see how the two AI interacted. Anyway back onto topic, strategic AI is much more complex because it has to play the game at the same level as thew gamer.

Deciding the Right AI

Now since you have an understanding of the types of game AI you may be looking to pick one for your game. Lets break down the types to make it easier to see.

Roaming - objects interacting with other objects by moving

Behavioral - objects with multiple decisions 

Strategic - follows same rules as player

Now it will be a bit easier to figure out which one you need. If none of the types I have talked about look to be what you want, search around the web.

Phew this has been a lot of typing. Hope you enjoyed it.


Understanding the Basics of the BIOS

You may be asking yourself, what is the BIOS? It stands for Basic Input Output System. The BIOS is embedded software which is in the motherboard that is executed when you turn on your PC.

The BIOS does many things such as dealing with RAM, detecting available hard drives, and dealing with the CPU. Once the BIOS had done what it has to do it starts the OS and lets the OS take control.

To access the BIOS turn on your PC and hit DEL, F1, or F2. If these options don't search it up.

In the BIOS you can tweak hardware such as RAM or the CPU. Be careful when doing this because you don't want to hurt your machine. If you start asking yourself questions research it. You then can improve the performance of your PC by overclocking you're hardware. When overclocking you can shorten the life of your hardware. To make things easier research a bit to find out how far your hardware can go! Remember to be careful when tweaking your hardware. Have fun!

Sunday, July 17, 2011

Learn the Binary Numeral System

Introduction


    Most of us have seen it, those zeros and ones. Those are called binary, a different way of counting compared to our traditional decimal numeral system. Instead of using 10 values (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) binary uses two (0, 1). Binary is used in computers with electrical pulses, one being on and zero being off.

Lets Start Learning


    First of all you read Binary right to left. Lets picture columns. We will start with 2 columns to get used to them.
                                         2    1
                                       | 0 | 1 |

    What do you think this number is? If you said 1 you are right! The second column is 0 (off) and the first column is 1 (on). When you add this up you get 1. Note that you are adding the top numbers, not the ones and zeros.

    Now lets get a bit more complicated. Lets extend the number of columns.

                                         64   32   16   8    4     2    1
                                        | 0 | 0 | 1 | 1 | 0 | 1 | 0 |         This equals 26!

    First of all to increase the number of columns if you ever needed more just double the last column. In this case it would be 64x2=128.

Exercises
Decode the columns below.


                                                      64   32   16   8    4     2    1
1.                                     | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 



                                                      64   32   16   8    4     2    1
2.                                     | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 



                                                      64   32   16   8    4     2    1
3.                                     | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 



                                                      64   32   16   8    4     2    1
4.                                     | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 




Here are the following answers to the earlier exercises:
#1 - 2
#2 - 15
#3 - 46
#4 - 127


    So lets review what we have learned. When decoding binary into decimal you add up the columns that are "on" to the the answer. Thanks for reading, hope you enjoyed this tutorial. Feel free to share!

Saturday, July 16, 2011

C++ code disassemble 1

Feel like starting a little series when I post basic C++ code and I disassemble it to easily understand. Enjoy.

The Guessing Game
I will be explaining how this code works. It is a basic number guessing game.
Code:


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;


int main()
{
srand(time(0));
int x, y = (rand() % 10) + 1;


do
{


cout << "Guess a number between 1 and 10." << endl;
cin >> x;


if (x == y)
cout << "You are right!" << endl;
else if (x>y)
cout << "Too high! Guess again." << endl;
else if (x<y)
cout << "Too low! Guess again." << endl;


}


while (x!=y)


;system("PAUSE");
  return 0;
;}


Now this is a poorly coded game but that isn't the point. Also to note this code will only work on Windows machines because of the system("PAUSE") code. Now time to disassemble the code!



#include <iostream>
#include <cmath>
#include <cstdlib>              Get the required libraries. 
#include <ctime>                

using namespace std;       Declare you are using namespace std.

int main()                           States main is an integer.
{
srand(time(0));                              \
int x, y = (rand() % 10) + 1;            -> Create a randomly generated number to guess.                                          
                                                              
do

{

cout << "Guess a number between 1 and 10." << endl;     Output the following.
cin >> x;                                                                                    Let the user input a guessing number.

if (x == y)                                                                                  Compare x and y.
cout << "You are right!" << endl;                                           Output the following.
else if (x>y)                                                                               If x > y do the following.
cout << "Too high! Guess again." << endl;                          Output the following.
else if (x<y)                                                                               If x< y do the following.
cout << "Too low! Guess again." << endl;                            Output the following.

}  Closing bracket for do statement.

while (x!=y)      While x doesn't equal y pause.

;system("PAUSE");    Pause code.
  return 0;                      Return 0.
;} Closing bracket for do while statement.


Hope you can use this code as a review. Thanks for reading!

Thursday, July 14, 2011

Simplicity of Blogging

Some tips and tricks from my experiences about blogging.

Content
    Content is a very important factor when blogging. You want to blog like you care, try not to make your posts short and empty. You want to try to fill the with information. But the information must be useful, you don't want to fill your blog with useless words that aren't needed.

    Now there is also another side to this. You don't want to give too much information. This will bore some of your audience. You want to keep them reading but not long enough to bore them!

Share
    To help promote your blog try creating a twitter account. I use twitter to let my followers know that I have blogged about something new. Doing this will keep them coming back without much effort. Somewhere on your blog try putting a link to your twitter account so your visitors have an easy option to follow you

    You can also let your family and friends know you have a blog. The more people know about your blog the more visitors you are likely to get.

Topic
    Make sure to pick a topic to blog about that you enjoy. This could be a hobby or just an interest. This will make it easier for you to blog without running out of things to blog about.

    Make sure to stick with your topic. Don't suddenly change your topic. This can make your viewers loose interest in your blog. If you have another topic you want to blog about make a new blog! This is an easy way to keep things organized and make sure your viewers are getting the information they want.

Money
    Yes, money can be made from blogging. A very simple way to get a little profit is to get an AdSense account and add some ads to your blog. But you never want to add too many ads, this will make your blog look like its only out for making money, causing visitors to leave. You don't want to have more ads then content!

Conclusion
    I think I covered about all the basic things about blogging. If your still reading up to here I thank you. Glad to have a couple viewers.

Wednesday, July 6, 2011

CrunchBang Linux Configuring Openbox menu.xml

To configure this file is quite easy. If you ever want to add something to the Openbox menu your at the right place.

First you want to locate the menu.xml file which can be located when you:

Right-click - settings - Openbox Config - Edit menu.xml

When you click that you will open the file and see the basic syntax for adding something.


<item label="NAME OF ITEM">// The name that will appear to the user to click
<action name="Execute">   // Stating to execute the following
<execute>
                 // what program to launch example: gedit
</execute>           // closing tag
</action>                 // closing tag
</item>                        // closing tag

In between the <execute> tags you will have to put a command to run the program. I found the exact command you need to run the program by right-clicking on the icon of the program you want to run. Then go to launcher and look for the command.

Icon - right-click - launcher - command

After you do all of this you want to restart Openbox, to do this follow these steps:

Right-click - Settings - Openbox Config - Restart

After this try it out, should work perfectly. Enjoy!

Thursday, March 17, 2011

Guide to Linux

I found a guide for Linux if anyone is interested in learning a bit of Linux. I've read a bit of it and so far have enjoyed it a lot. Pretty easy to understand and starts from the ground up. A good approach to tuturials. Anyway you can find the guide here.