Showing posts with label ActionScript. Show all posts
Showing posts with label ActionScript. Show all posts

Saturday, June 19, 2010

AI For Video Games - Final Project

It has been almost two years since I took my "Artificial Intelligence for Video Games" course, but the topic still comes up quite frequently. I find myself using my blog as a resource for when I am talking with people about different concepts and programs. As a result of this, I decided to include a post where I actually show what the final game came out to be like.

I realize this kind of messes up my blog's layout. Since I am mostly interested in showing people the game, as opposed to my layout, I'm OK with this.





Click here for a full screen version.


It's been a while since I worked on my sheep herding game, and Jon Bradley is responsible for the code as much as I am (entirely for the sheep behavior). Please leave me a comment if you would like to talk about this.

Saturday, November 15, 2008

AI for Video Games Project Update

Today I spent about 5 hours at Starbucks working on getting the dog I jacked from this dude to follow a path in ActionScript. Right now, I solved the problem related to applying the points on the incorrect place and getting the dog to follow the points on the path. I still want to clear the path after the dog has finished following it, make the sheep run away from the dog and work on the dog's animation a bit. I think once I get the sheep running from the dog and the path cleared though, I am going to setup SVN and work on the splash screen and some other non-AI components of the game. My partner Jon has done an awesome job creating the AI framework, and we agreed to have him do a bit more AI and I would focus on the other structural points of the game. Our professors wanted to make sure all group members did AI related stuff, so path following seemed like a good place for me to work.





Click here for a full screen version.


Code is available here in case you want to see how I did path following in ActionScript. If you have any questions / suggestions, let me know. I see that a lot of people have been searching for algorithms and data structures related to ActionScript, but I never receive any feedback from you guys. Leave me a comment if this is useful.

Monday, November 10, 2008

AI for Video Games Final Project

For my final project, Jon Bradley and I decided to work together on a video game he has an idea for. The game is all about herding sheep. So far, Jon has done a huge amount of work. Today I made some progress on implementing path following in the ActionScript framework Jon developed. I still need to make something actually follow the path, as well as figure out why my path adding is getting messed up with regards to clicking on a sheep or the shepherd whenever you are trying to add a path.

Anyways, here is a sample of what we have coming. I'm going to hold off on posting any code until the assignment has been turned in. My path algorithm is the same one that Bill Klein implemented in Processing, which is probably the same one from "Artificial Intelligence for Computer Games" by Ian Millington.





Click here for a full screen version.


Number one is getting the points to be correctly placed when you click on the shepherd or sheep. After that, comes getting something that looks like a dog to following the path, then setting up SVN so we don't have to email our code back and forth. After that, I am going to work on an intro screen, a level loader, a sound track (hopefully just finding one) and the other animation sequences, probably in that order. Jon has already finished the brunt of the AI, I he's going to add some obstacles, make a pen for the sheep to go into, add a little bit of state information and make it so flocks can be broken up. As long as I can get my pieces done, there isn't a ton more to do, since Jon has been working so hard!!

Sunday, November 9, 2008

Finished A* Finally

Hello,

I finally implemented an OK heuristic (Manhattan distance / Taxicab geometry from the current node to the end node). Everything looks the same, but the code is a bit different.

My full implementation of A* in ActionScript is available here.

Wednesday, November 5, 2008

A* for ActionScript, with an incomplete heuristic function

I have finished my (first completely working) implementation of A* for ActionScript. However, the heuristic function is a constant function and thus not implemented, so 'A*' is just breadth first search. Technically, I believe it is correct to still call it A*, but I'm not certain since I'm not keeping track of my path cost, and my heuristic is more of an artful description of something that always returns the same value but has not been implemented... I suppose I am feeling a bit discouraged since the assignment is due tomorrow at 5 p.m. and it is 3:21 a.m. and I still have a bit to do in order to make it perfect. However, I think choosing which path to recurse down first based on a heuristic shouldn't be too big of an addition now that everything else is working well.

I feel very happy that I choose to implement this in ActionScript. I like being able to share my programs with people online and notice the Google search terms that bring others to my site. I gain satisfaction when I see that someone from China, Spain, or some other distant place, spent 20 minutes reading about some technical issue on my site.



Press space bar to switch between blocking off nodes, selecting a start position and selecting an ending position.

Click HERE to view this in it's own web page.


My sister would be proud of my photoshopping skills on the waving hand. I also have to give a shout-out to Michael Baczynski for the cool data structures library (I didn't have to write my own FIFO thanks to him.)

As always, my complete source code is available. Please don't hesitate to contact me if you have any questions. I plan on making it more of an actual A* implementation, and if time permitting, possible using Michael Baczynski's graph data structure and implementing A* in his (very well designed) framework. I did not plan on doing that from the beginning, even though I'm sure it would have saved me time, since I did not see him code until after I already made my own graph, and adjacency list, management routines.

Thanks for Laurie Phillips for finding a bug in my code.

Monday, November 3, 2008

A* for ActionScript

For my class titled "Artificial Intelligence for Video Games" I have been working on an implementation of the algorithm A* in ActionScript. I've been pretty happy that the professors allow us to use ActionScript, instead of Processing, because it makes sharing my work on the Internet much easier. In addition, I think having substantial ActionScript skills is a marketable quality, as opposed to skills in the programming language "Processing." Hopefully I also will develop skills in artificial intelligence, to transcend any of the language-specific focuses I may have in mind.

As of this post, I have no actually implemented A* in ActionScript. What I have done is to implement a mechanism to draw and manipulate a relatively straighforward graph. This graph has the edges layed out in a regular, rectangular, pattern.

Here is a SWF of what I have so far:





Click to block/unblock a node, and press space bar to alternate between different modes of selecting a node. Eventually, the blue square will be for the starting position, and the green square will be for the ending position. Once I finish implementing A*, the path between start and end will be drawn in red squares.

Most likely if you are reading about my implementation of A* in ActionScript, you are interested in seeing my code. At this point, the most interesting thing will be how I keep track of adjacency lists for each node.

I will make another post when I finish everything, but I like making things available as I work so I can view my own progress. Here is a .zip of all the files for my project so far. I ask that if you use them, please somewhere link to my blog and email me so I can get some satisfaction.

Thursday, April 24, 2008

ActionScript Update

Today I have been working on my ActionScript front end for Mark Olah's molecular spiders a ton. In addition to moving the scene around, I completed a bit of some scene resizing code. Check it out below.






For this version, you should be able to move the entire scene around by clicking, holding, and moving your mouse around. This version ALSO supports resizing by using the scroll wheel, but my Blogger stuff seems to be getting in the way of it. You can also check it out directly by clicking here. If you are so inclined to take a look at my code to see how I accomplished this, I packaged it up for everyone here.



If you are interested in how I added mouse listeners to my flash file, check out the com\identityMine\documentClass\DocumentClass.as file. Since I started doing Flash as a programmer, everything is implemented in classes.

Sunday, April 13, 2008

ActionScript Parsing

I've been helping Mark Olah out on some molecular computer visualizations in ActionScript and we are moving towards getting an actual front end for his simulator. In order to do that, we need to have some mechanism of communicating between his software and the ActionScript I have been working on to draw the pictures.

Mark suggested we have a fairly simple format that looks something like this:

//Hello World! This is Brian J. Stinar reading in a file with Adobe AIR.


Begin Surface
-1, -1, 2, 2
1.0, 1.0, 0, A
1.0, 2.0, 1, A
1.0, 3.0, 2, A
1.0, 4.0, 3, A
2.0, 1.0, 4, B
3.0, 1.0, 5, B
4.0, 1.0, 6, B
5.0, 1.0, 7, B
End Surface

Begin Spider
brian_spider_1, 4, 1
brian_spider_2, 4, 3
brian_spider_3, 4, 1,
End Spider
// Here is another comment

Begin Trace
Body Move brian_spider_1
LegAttach brian_spider_1, 1, 0
Spider Detach brian_spider_1

End Trace


If you would like to test out my parser with this file, the file I am parsing is available here.

Then, I will read in this file and generate graphics accordingly. After working today for a few hours, I think I have parsing down in ActionScript (Adobe AIR, actually?). The regular expression syntax is just like Perl, and well documented by Adobe.

Here is the code I came up with :


package com.identityMine.filereader
{

import flash.filesystem.*;
import flash.display.MovieClip;

// The extention here is to make it so that I can independently test these routines
public class FILEREADER extends MovieClip {


// Constructor - loads in the input file we are reading
public function FILEREADER(){
// Create a file object and let our app know where the file
// exists

// have we seen the "Begin Surface" command yet?
var inSurface : Boolean = false;
var inTrace : Boolean = false;
var inSpider : Boolean = false;
var inMove : Boolean = false;

// This is the file we are reading
var myFile:File = File.applicationDirectory;
myFile = myFile.resolvePath("mySampleFile.txt");

var fileStream : FileStream = new FileStream();
fileStream.open(myFile, FileMode.READ);

// Everything inside our file
var fileContents : String = fileStream.readUTFBytes(fileStream.bytesAvailable);

// Split our entire file based on newlines
var splitString = fileContents.split("\n");

// this prints out everything in my fileContents string
// trace (splitString);

// iterate through each element in the array
// each represents a piece of information necessary to construct our
// visualization

// looping variable
var i : int;
// splitting variable
var split_val : int;

// Regular Expression for matching a string of 1 or more digits
var re1 = new RegExp("[0-9]+");

// Regular Expression for matching a sequence of alph characters
var re2 = new RegExp("[a-z]*[A-Z]*");
var re3 = new RegExp("[//s]*LegAttach");

var SubVals;

for (i = 0; i < split_val = "Begin Surface" insurface =" true;" i =" i" insurface ="="" subvals =" splitString[i].split(',');" split_val = "End Surface" insurface =" false;" split_val = "Begin Trace" intrace =" true;" split_val = "Begin Spider" inspider =" true;" split_val = "End Spider" inspider ="="" inspider =" false;" inspider ="="" subvals =" splitString[i].split(',');" split_val = "Body Move" inmove =" true;" split_val = "Spider Detach" inmove ="="" intrace ="="" inmove =" false;" split_val = "End Trace" intrace ="="" intrace =" false;" split_val = "LegAttach" intrace ="="" inmove ="="" subvals =" splitString[i].split(',');">













Code Available Here



This is a TERRIBLE solution to my problem of not being able to display code well on my blog. As an actual solution, I should make my blog wider (and yes, adjust the images that came with the template.)


As of yet, I still need to check to see how error resilient my code is. I think my regular expressions might accept too much stuff. For the next small increment, I am going to actually print out the corresponding function call I plan on making. For testing purposes, I added a bit of junk into my trace file and my program spit it out.



Thursday, March 27, 2008

ActionScript Project

Since I am getting some hits regarding my ray tracer, I thought it would be cool to include progress on my other projects as well.

I am working on a molecular visualization project regarding molecular 'spiders' that a research group here at UNM is working with. Many, many people are working on getting these molecules to walk around a surface and *hopefully* compute something useful. Primarily, I work with ActionScript in an attempt to get some flashy visualizations online.

In addition to messing with ActionScript, I read papers on molecular visualization to try and figure out how other people are approaching this problem. I hope to use this blog to show some of my progress, post ActionScript for everyone to view, and place my thoughts on academic papers I read regarding molecular visualization.








Please leave me a comment if you find any of this useful.