Archive

Archive for January, 2012

Strategy Game AI

January 12th, 2012 2 comments

So I had an epiphany today. Up until this point I had been planning on using a Monte Carlo-like algorithm to create a near universal strategy game AI. I knew it was something I could do, but it would require a decent time investment and might take too long to run before it could actually generate a good quality turn.

Then I realized, I want the enemies to be zombies. And why should zombies have an intelligent AI controlling them? So I think I can make the AI in my game work in almost exactly the same way that my movement works. During the AI turn for each unit, I’ll start from what’s next to them and then fan out til I hit the first enemy. Then I’ll randomly pick one of the shortest paths to that enemy and move the unit as close as it can get during it’s turn. It’s so simple, but makes so much sense for zombies. I haven’t finished updating it for the AI, but here’s the code I have for determining the total movement area available for a given unit.

//******Set starting tile as character’s current position******
currentNewTiles.push(new Array(attachedCharacter.currentHorPos, attachedCharacter.currentVertPos));

if(startDistance == 0) {

moveSquares.unshift(new MoveSquare(new Array(), attachedCharacter.currentHorPos, attachedCharacter.currentVertPos, squareType));
this.addChild(moveSquares[0]);

}
mapCheckArray[attachedCharacter.currentHorPos][attachedCharacter.currentVertPos] = 0;

//******Iterate through each possible move******
for (var moveCount:int = 1; moveCount <= endDistance; moveCount++) {

oldNewTiles = new Array();
oldNewTiles = currentNewTiles;
currentNewTiles = new Array();

//******For each space that was reached during the last move******
for each (var oldCoord:Array in oldNewTiles) {

var oldHeight:int = Main.tileMap.mapArray[oldCoord[1]][oldCoord[0]].tileHeight;

//******For each posible direction******
for (var directionCount:int = 0; directionCount < 4; directionCount++) {

//******Set new coord equal to old + new direction, but won’t go off map******
var newCoord:Array = new Array(Math.min(Math.max(oldCoord[0] + xArray[directionCount], 0), Main.mapWidth – 1),
Math.min(Math.max(oldCoord[1] + yArray[directionCount], 0), Main.mapHeight – 1));
var moveBlocked:Boolean = false;
var oldMoveCount:int = mapCheckArray[oldCoord[0]][oldCoord[1]];
var isImpassable:Boolean = Main.tileMap.mapArray[newCoord[1]][newCoord[0]].impassable;
var movesRequired:int =
Main.tileMap.mapArray[newCoord[1]][newCoord[0]].movesRequired[attachedCharacter.moveType];
var newTeam:int;
var tempCharacter:Character = Character.getCharacterAt(newCoord[0], newCoord[1]);

if (tempCharacter == null) {

newTeam = -1;

}
else {

newTeam = tempCharacter.characterTeam;

}

if (isImpassable) {

moveBlocked = true;

}
else if((oldMoveCount + movesRequired) > endDistance) {

moveBlocked = true;

}
else if (newTeam != characterTeam && newTeam != -1) {

moveBlocked = true;

}

if (squareType != “MOVE”) {

movesRequired = 1;

if (moveCount >= startDistance) {

newTeam = -1;

}
else {

newTeam = characterTeam;

}
moveBlocked = false;

}
//******Check if tile was reached previously or impassable******
if (mapCheckArray[newCoord[0]][newCoord[1]] > (oldMoveCount + movesRequired) && !moveBlocked) {

bestPathArray[newCoord[0]][newCoord[1]] = new Array();

for each(var tempVar:String in bestPathArray[oldCoord[0]][oldCoord[1]]) {

bestPathArray[newCoord[0]][newCoord[1]].push(tempVar);

}
bestPathArray[newCoord[0]][newCoord[1]].push(“1,”.concat(directionArray[directionCount]));
if (newTeam == -1) {

var squareFound:Boolean = false;

for (var i:int = 0; i < moveSquares.length; i++) {

if (moveSquares[i].horPos == newCoord[0] && moveSquares[i].vertPos == newCoord[1]) {

squareFound = true;
moveSquares[i] = new MoveSquare(bestPathArray[newCoord[0]][newCoord[1]], newCoord[0], newCoord[1], squareType);

}

}
if(!squareFound) {

moveSquares.unshift(new MoveSquare(bestPathArray[newCoord[0]][newCoord[1]], newCoord[0], newCoord[1], squareType));

}

}
currentNewTiles.push(new Array(newCoord[0], newCoord[1]));
mapCheckArray[newCoord[0]][newCoord[1]] = oldMoveCount + movesRequired;

}

}

}

}

I’m using actionscript 3 for the code if you’re curious. And here’s the result of all that code.

What a beautiful movement area

If there’s anything you’re interested in learning about what I’ve done so far or about the game development process, let me know in the comments.

Categories: Programming Tags:

The Story So Far

January 12th, 2012 No comments

As this is my first post, I believe an introduction is in order. My name is Kyle McGuffin and I’m in the process of programming my first published game ever. I’ve got a degree in Mathematical Economics from the University of Michigan which started me off working as a budget analyst and a web developer. I’ve enjoyed playing video games since I was 4 and have always thought that a career as a game designer/programmer would be fun. This is the start of me realizing that dream.

For my first game I’ll be using Flash to create a web based game. I started off by using the Flash Shootorial on Kongregate to learn the basics of Actionscript 3. I don’t know how much money is really in flash games, but I’ve heard several stories of people publishing games through Flash Game License so I figured it was a good place to start. My game will at least be published, even if it’s not very profitable.

My current idea is a turn-based strategy game in a medieval setting. The gameplay should be similar to Advance Wars, but with a completely different set of units since it’s medieval instead of modern. So far I’m planning on calling the game “Medieval Tactics” with a possible subtitle depending on if I add zombie enemies or not. Here’s a screenshot of the game so far.

The First Image of My Work

Most of the artwork is temporary and lifted from Google image searches. I have a friend that is working on the actual art assets for the game. Until those are ready, the placeholder images will have to do.

I’ll try to post my progress regularly. Hopefully you find my insights into creating a game for the first time interesting.

Categories: Game Update, Personal Tags: