Last Good Quote: Son's are the seasoning on our lives. - Someone on Facebook

Thursday, October 30

Path Finding in Javascript

I went back to the Lab (cause I needed to get my mind off the job). I decided to write a path finding algorithm in javascript.

I used my typical map setup. I found some pseudo-code for the A* path finder. I did the best I could (there was a heuristic in that pseudo code that I could not quite duplicate)

Anyway, it seems to work nicely. It does not find the shortest path, but it does find a path.


Feel free to use it for your own usage.

One Note: It uses a recurring function, I limited it to 40 loops. If you have a large map, you may need to up this a bit.

Take a Look

Source Code

Tuesday, September 9

Display All Images in a Directory

The following php code will allow you to display/show all images in a folder. Be careful as if there is an executable file in this folder it will get executed.

(Just cause I'm tired of searching for it every time I want to do it)

$dir=dir("./images/.");
while($filename=$dir->read())
{
if($filename != "."
&& $filename != ".."
&& $filename != ".."
&& $filename != "Thumbs.db" )
{
print $filename . " - ";
}

Tuesday, July 29

Future Books and Dreams

I'm interesting in writing and think that I have a lot to share. (Although my wife and brothers would tell you differently.) Here is a list of books I would like to write and why:

Programming for High School Kids
I currently volunteer time teaching kids in grades 9 - 12 how to build basic web pages in ASP and .Net. I've done that for about 4 years now. I really enjoy doing it and I learn a lot about my development processes each year that I teach. The kids that I teach walk into my class with no computer programming or web design skills and 8 months later they are able to build full scale web applications.

This is done through the BDPA organization with the HSCC program.

Game Building with PHP
A book about how to build web based php game. This would cover some of the newer techniques like AJAX and map display, movement and stats. I also have read a lot of interesting things on game modeling and building addictive games. I think writing this book would be a great learning experience for myself.

Pseudo Auto-biography
I've always wanted to write about my family and my past. I have pretty interesting background, I have 3 brothers and 2 sisters, a white mother, a black father who spent 20+ years in the military, is a vet and a Buddhist. I also was raised in a very religious environment which I broke out of when I got older. I never watched TV or listened to music till I turned about 16. Because of this I can read a 300+ page book in about 2 hours. I've a collection of over 1000 sci-fi books and can remember almost every chapter of all of them. All of this gives me, what I think is a unique view on race, religion, ethics and life in general.

Why I raised my Sons the way I did
I really want to write this one just for my boys. I have a 2 and 9 year old and I think that they would appreciate some insights on why and how I made the choices I am now making in regard to how they are raised. Again I think this book would be educational both for myself and for them, but the most interested reader of this book would be my wife. *grin* Love ya Babe!

Anyway, just a few things that were on my mind. If you feel like it leave me a comment on which one I should start first.

Friday, July 11

Cleaning out the Code Closet

I was going through my PC backups and looking at all those old projects I have out there. It's interesting how much stuff I've worked on "Just for Fun"

I figured I'd list them here so, if you are interested in any of the code let me know. I'm usually happy to share. But keep in mind, these are all projects that I did just to see what can be done, so they are mostly proto-types.

  1. myAI - A php based neural net project, gives a visual display of how an AI neural net works. 95% completed.
  2. Great Browser Based Games - An engine to allow people to post their PBBG games, I did this in an interesting AJAXy way. 75% completed
  3. Card - An RPG card game, wrote in PHP, browser based, currently in Alpha. 99% complete. (No I won't share source on this one)
  4. RPG Game Template - A template that will allow other novice developers to build a web based RPG. 50% completed
  5. mobLIB - My library of javascript functions for moving things around, doing AJAX and other funky stuff.
  6. Monster Football League - A php and javascript based american football game. This was kind of neat, but I ran into some processing problems, evidently trying to calculate the position of 24 players and a football on a 100 yard field is a bit more then javascript can handle. But it was fun to try.
  7. Horse Racing VR - I was collobarating with someone to do a Horse Racing VR game, sadly I got caught up in real life stuff that pulled me off that project and my partner disappeared.
  8. Stock Analyzer - A program that analyzes 3000 stocks and gives you the top 3 - 5 potentials each day. 90% complete, working towards a release. (No source code available on this one)
  9. Blade of a Mage - Another browser based PHP game, I used to run a long time ago. Took it offline because I didn't have the time to manage it...looking at putting it back online.
  10. Star Fighter - A flash game, simple top down plane game. Graphics are ugly as hell, so I didn't deploy it.
  11. Tactics - A flash game, imagine chess, but with RPG characters that have stats and abilities. Completed but took too much effort to maintain code wise (I don't enjoy working with flash). It had a php backend.
  12. Ships - A flash game, this was based on all the PBBG space games out there, except with this one you could see the movement of your ships and what not. Ran it online for a while but it ended up, hogging some server resources.
  13. Worlds of War - An isometric Mech battling game, I loved this game. But some moron hacked it and crippled my server. I fixed the hack but I worry about putting the game back online. (irrational fear, but look at what number it ended up being on the list...13...its a sign I tell you!)
  14. Battle Forces Online - Fully deployed operation game, RPG isometric top down view. I like it but I think it needs a lot of tender love and care to turn it into the real thing.
Well that is my list...of course that's just on this PC, who know what I have on my other one.

Thursday, July 3

Dominating Keyboard Controll in Javascript

A great blogger at Lost Garden, setup a development challenge. The challenge was to build a game incorporating shadows.

While not exactly in line with his rules, I wrote a javascript game. While building this I had to figure out how to move a character around the screen using javascript.

For those who just like to look at code, here is the source and a demo.


I started by placing a div tag which had absolute positioning. This allowed me to move the div around the screen.


<div id="unit"
style="position:absolute;
top:0px; left:0px;
height:20px;width:20px;
margin:0px;padding:0px;"><img src=man.gif width=30 height=30></div>


The next step was to capture any key presses for that div, there are a number of ways to do this but I did it with the following javascript:

controlledObj = document.getElementById("unit");
document.onkeydown = keypressed;


The first line let's me know which div I am controlling, the second line captures all key events to the keypressed function.

The key pressed function watches for arrow keys and moves the controlledObject in the appropriate direction:
function keypressed(event)
{
if(event.type == 'keydown' && event.keyCode == 38)
{
//up
dir="N";
pos = findPosOfObject(controlledObj);
controlledObj.style.top=pos[1]-5;
}

if(event.type == 'keydown' && event.keyCode == 40)
{
//down
dir="S";
pos = findPosOfObject(controlledObj);
controlledObj.style.top=pos[1]+5;
}


if(event.type == 'keydown' && event.keyCode == 37)
{
//west
dir="W";
pos = findPosOfObject(controlledObj);
controlledObj.style.left=pos[0]-5;
}

if(event.type == 'keydown' && event.keyCode == 39)
{
//east
dir="E";
pos = findPosOfObject(controlledObj);
controlledObj.style.left=pos[0]+5;


}
}

There is a special function, findPosOfObject(), used in that bit of code, that gives me the precise location of a div tag. This is something I googled, I'm not sure where it came from but it's a pretty simple piece of code. It looks at an object, goes up the DOM tree to find all its parents and finds the exact top and left of the object. It then returns those values in an array.

function findPosOfObject(obj)
{
var curleft = curtop = 0;
if (obj.offsetParent)
{
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent)
{
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}

return [curleft,curtop];
}




And that is how I moved an object around on the screen.

You can see the end results Shrooms
and the code can be downloaded here.

Enjoy!

Thursday, June 26

Gaming with a Guest Account

You've got 10 min...you know of this great game, you want to test it but as you visit the site you realize you have to register.

*sigh* you walk away, telling yourself you'll come back tomorrow.

As a game builder that's an expierence I don't want to give my potential players. Thus I've started creating a guest account feature for all my new games.

The guest account gives a player a quick easy way to evaluate the game.

For the time being the guest accounts on my games are not persistant, they stick around for a few hours or days then disappear. As a matter of fact, once you logout the game, you can not log back into the guest account.

Remember the goal is to convert the user to a player, thus if they play as guest but don't feel emotionally attached enough to create their own account. They won't be playing the game for very long.

Wednesday, June 25

A Quest to Find Intelligence

A Quest to Find Intelligence

I've decided that if I'm going to research and explore Artificial Intelligence (A.I.) it would be wise to define in my words what I am trying to find.

I am searching for a computer program that has the following capabilities:
  1. It must be able to create tools.
  2. It must be able to identify the usefulness of a tool.
  3. It must be able to set its own goals.
  4. It must be able to determine when a specific goal has been met.
  5. It must be able to be acted upon by its environment.
  6. It must be able to act upon its environment.
If a program is able to accomplish these things I would consider it intelligent and useful. In addition to this, the more complex it's environment the more intelligent I would find the Agent.

What's a tool?

A tool, to my AI, would be any function or program which accepts a number of inputs and delivers a number of outputs.

For example, an add function might take 2 numeric inputs and output one numeric number. In this case a single function acts as both the input and the output.

add(1,2) -> 3

This would be a simple tool. A more complex tool might be a map object which has a number of functions (inputs) that allow you to modify the appearance of the map (output)

map.createMap() - sending inputs
map.viewMap() - getting outputs
0 0 0
0 1 0
0 0 0

map.moveUp() - sending inputs
map.viewMap() - getting outputs
0 1 0
0 0 0
0 0 0

Identifying the usefulness of a tool

In order for the AI to understand the usefulness of the tool, it must be able to make an accurate prediction of the output of the tool.

For example, after examining and testing the add function mentioned above, the AI will be able to identify that if it puts 3 and 5 as inputs it will get back 8.

This is NOT the same as saying that the AI knows the implementation of the add function, rather it can anticipate the response of the tool.

This will allow the AI, when given a goal, to choose one specific tool to use from a variety of tools.

Note to self: This means that the AI must maintain some type of meta-data about tools. IE: When a goal using the word "addition" this should key the AI to consider the add function as part of it's procedures.

Setting a goal

As stated before one of the requirements is that the AI be able to set its own goals. This is needed because as more and more difficult tasks are requested of the AI it will have to set a sequence of steps together to achieve the tasks. I consider each of these sub steps as a goal that the AI must recognize and achieve before completing the final tasks.

For example if AI is asked to provide the tasks of moving itself 5 spaces up on a map, it must understand that it's first goal is to move a single space. It must then choose a tool that will do that and execute that tool 5 times.

This may result in the AI creating a new tool which moves it 5 spaces. Which brings us to our next point...

Creating tools

At some point the AI will need to build its own set of tools, as a tool may not exists (or be at its disposal) that will accomplish the overall goal.

In a simplistic sense, since tools are functions or objects, as the AI builds more tools it becomes "smarter"

Again the AI will need some method for determine when and how to create a tool.

Acting within the Environment

Finally and most importantly, the environment that the AI "lives" in will have to interact with the AI. And vice versa the AI will have to be able to interact with the environment.

This is most important as the "richness" of the environment that the AI can interact with will dictate the "intelligence" of the application.

For example:
Let's say an AI, agent's, environment consists of a label, text box and submit button. This is the agents environment. It is what the agent can act on and it is how the agent will be acted upon.

An agent can enter text into the text box and submit the text using the submit button. This would be the agent acting on the environment.

The environment would act upon the agent by placing text into the label.

Certain characters in the label, "That is correct" would affect the agent in some manner.

This is a simple environment and the agent behind it would be considered to have "lesser intelligence"


A More Complex Example

The environment consists of a 3d world, like "Worlds of Warcraft". The agent (AI) would be a character in that environment.

As the agent performs actions in this environment, attributes of the agent would respond accordingly. IE: health, level, skills, etc...

The next few post will go into each of these functions in more detail.

Tuesday, June 17

Online Game Programming Book

I have not posted in ages, however I ran across this link and thought it was a good resource.

This book is about programming games in Python. Seems to be a good starting place for all those new to game programming.

It's available as a PDF download.

http://pythonbook.coffeeghost.net/book1/index.html

Wednesday, March 19

2005 Table Partition - Optimization Test

On the job we decided to implement table partitioning with SQL Server 2005. I wanted to get an understanding of the increases and decreases that we would see with a partitioned table. Below is documentation of my tests.

Tables Involved
Step 1:
Create Table called 'nonPartitioned'
No Primary Key
16 varchar(50) fields
1 bit field called 'activeFlag'

Step 2:
Populated table with random text
Created 250,000 rows

Step 3:
Mark a sizeable portion of the table as active.
I took 50,000 rows and marked them as active.
I took rows that cotained an 'a' in 'fieldG'

Step 4:
This table is partitioned on the activeFlag, 1 or 0
Create Partition Function
Create Partition Schema
Create Partition Table

Step 5:
Copy Data from 'nonPartitioned' to 'partitioned'

Step 6:
Create table called 'smallTable'
This holds only active records
Populate with active records only

Step 7:
Create table 'selected'
This will hold data that we select from either partition

Some important metrics to note at this point:

52,689 where ActiveFlag =1
197,311 where ActiveFlag =0

35.51 MB - Partitioned Table Size
36.17 MB - Non Partitioned Table Size
7.45 MB - Small Table

First Test - Selecting from Small Partition
The first test is to select data and see if we have a speed increase.
  • Truncate the 'selected' table
  • Perform the following 1,000 times
  • Select 10 random records from the nonPartitioned Table where activeFlag = 1
  • Insert it into the selected table
4:53 (4 min, 53 seconds) - NonPartitioned Table
3:39 (3 min, 39 seconds) - Partitioned Table
3:55 (3 min, 55 seconds) - Small Table

Second Test - Selecting from Large Partition
The first test is to select data and see if we have a speed increase.
  • Truncate the 'selected' table
  • Perform the following 1,000 times
  • Select 10 random records from the nonPartitioned Table where activeFlag = 0
  • Insert it into the selected table
13:23 - Partitioned Table
12:59 - NonPartitioned Table
00:00 - Small Table (no select available of large set)

The following code was used for those tests:
truncate table selected
declare @count int
set @count = 0
while @count < activeflag="0" count="@count+1">
Third Test - Updating 1,000 rows
I now want to test the update statements to these partitions. I used the following logic
  • Truncate the 'selected' table
  • Perform the following 1,000 times
  • Select 1 random records from the nonPartitioned Table where activeFlag = 1
  • Update one field (fieldB) for this record
5:03 - Partitioned Table
9:56 - NonPartitioned Table
4:57 - Small Table


Third Test - Updating 5,000 rows
I now want to test the update statements to these partitions. I used the following logic
  • Truncate the 'selected' table
  • Perform the following 5,000 times
  • Select 1 random records from the nonPartitioned Table where activeFlag = 1
  • Update one field (fieldB) for this record
33:17 - Partitioned Table
49:25 - NonPartitioned Table
24:27 - Small Table

Conclusion

If you must have all the data in one table, then partitioning the table will greatly increase your performance in all areas.

However if you can pull the data out of the table into a smaller table, this will give you the greatest performance during transactional processing.

Caveat

This is my own home grown test, as always perform your own test before making production relavant decisions. Your data may give you different results.

Friday, March 14

Battle Forces Online: Bounce Rates and Visits

Battle Forces Online: Bounce Rates and Visits

Interesting .... Between Feb 15, 2008 and Mar 14, 2008.

Low Bounce Rates:
* freegames.au - 39 visits, 20% bounce rate
* internetgames.org - 1 visits (prev 7)
* onlinegamesinn.com - 10 visits (prev 19), 30% bounce rate
* pbbgblog - 42 visits, 40% bounce rate
* onrpg.com - 133 visits (prev 37), 27% bounce rate (prev 30%)
* forums.indiegamer.com - 13 visits (prev 97), 30% bounce rate (prev 62%)

Most Visits From
* onrpg.com - 133 visits (prev 37), 27% bounce rate (prev 30%)
* community.bbgamezone.com - 49 visits (prev 59), 35% bounce rate (prev 45%)
* forums.indiegamer.com - 13 visits (prev 97), 30% bounce rate (prev 62%)
* pbbgblog - 42 visits, 40% bounce rate

I know that this past month I have posted a lot of entries on pbbgblog.com....evidently they have been working. The bounce rate is a bit high but it seems worth while.

Mental Note: Check out onrpg.com, it may be worth while to post a few things over there as it seems, they have a great bounce rate for my visitors.

Followers