by date
While the cats away..
While the cats away..
| Name: | Phil Carlisle | ![]() |
|---|---|---|
| Date Posted: | Jun 25, 2006 | |
| Rating: | Not Rated | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Phil Carlisle |
Blog post
So Thomas is off with his family having a good time in florida, watching space shuttles take off and all.
So while he's away, I thought I'd spend a sunday doing some work on my tennis game (while we're getting ready for the big push on Air Ace).
So one thing I've been waiting to get to, is a way to get the AI on the game to play better. A few posts ago I posted about my playfield class which contains a number of "zones" and which you can query for the centroid etc. This is part of a bigger plan to make a sports franchise and the required tools.
One of the biggest issues I ran into is that I needed some way of telling the AI where it needed to be based on the position of the opposing player (you'd think it would be better to follow the ball, but actually its better to consider the angles available to the enemy player if they return the ball).
What I needed, was a way to say "if the other player is in X position, then move to Y". At this point I started thinking of making an editor to make my life easier.
So given that I'd given myself the task of learning C# and windows forms programming (and .net programming) over the summer. I figured I'd break out C# and try doing an editor in it!
Well, I can say its been an interesting experience. Very much remeniscent of Borland Builder and Visual Basic in many ways. So after a day or so of programming (I dont have the damn MSDN CD's at home, so I've had to muddle through on web refs) I have my first C# app and my AI editor for the Tennis game fully functional.
What does it do?
It allows me to visually represent the tennis court as a grid of cells. In this case, the grid is 16x32 which happily leads onto a really simple and nice data structure. If you think about it, for each position on one side of the court, you have to encode a position on the opposing side. Well, if each side has a 16x16 grid, it just happily fits into a byte!! So I figured, for each cell in one side, I simply need to know the cell in the other side. So I have to fit 256 (16x16) positions. But those positions are all 0..255, so basically I only need 256 bytes for all the information (as one side becomes the index into the data stored as the corresponding position.
So for each top position X, I simply need to lookup myposition[x] in the byte array to find the cell index to stand in!
Now it would be a bit stiff if I simply took a cell position Y every time the other player moved to X, plus it doesnt really work for different play styles to just use one table.
So what I've done in the AI, is use several tables of 256 bytes each, essentially denoting different play styles, agressive, defensive, front court, middle court, rear court etc. Then take a weighted average of them based on the current state of the player. If they are aggressive, then clearly the aggressive positions are weighted more. This is also "fuzzified" a little to make it a little less distinct.
I'll show some videos of the resulting gameplay soon. But suffice to say its moving onwards. I expect we'll have it there at IGC for some test play!
I doubt it'll be ready for wimbledon though :)
And what would a plan be without the obligatory shot?
Here is the editor in all its glory. Ok, its not much visually, but it does the job and the code was relatively easy to knock out. Once I get .net 2005 and the help files installed, I expect to throw out a few more sports game editors (in particular, I want to actually make a playfield editor and some editors for the next sports games to make them a lot more data-driven).

What you see here, is the court, with a 16x32 cel grid overlay. You can click on the court and if you click the top half, it sets the "current index". This is mirrored in the edit spinners on the left (I figured it would be good to have more precise control and a way to test my editing values). The "current index" is the index into an array of byte values which are positions in the bottom 16x16 part of the grid. When you click the top half, it shows the red dot on the corresponding cel of the bottom half. If you click on the bottom half, it sets the values at myposition[currentindex] to the cel you click.
So essentially the save file (.tns) is just a 256 byte array of values :)
I'm quite happy with the result, given that it does the job and doesnt have any frills. Its been pretty quick to put together. Next app should be a lot quicker to get done, especially considering I'll have the docs :)
Til next time!
So while he's away, I thought I'd spend a sunday doing some work on my tennis game (while we're getting ready for the big push on Air Ace).
So one thing I've been waiting to get to, is a way to get the AI on the game to play better. A few posts ago I posted about my playfield class which contains a number of "zones" and which you can query for the centroid etc. This is part of a bigger plan to make a sports franchise and the required tools.
One of the biggest issues I ran into is that I needed some way of telling the AI where it needed to be based on the position of the opposing player (you'd think it would be better to follow the ball, but actually its better to consider the angles available to the enemy player if they return the ball).
What I needed, was a way to say "if the other player is in X position, then move to Y". At this point I started thinking of making an editor to make my life easier.
So given that I'd given myself the task of learning C# and windows forms programming (and .net programming) over the summer. I figured I'd break out C# and try doing an editor in it!
Well, I can say its been an interesting experience. Very much remeniscent of Borland Builder and Visual Basic in many ways. So after a day or so of programming (I dont have the damn MSDN CD's at home, so I've had to muddle through on web refs) I have my first C# app and my AI editor for the Tennis game fully functional.
What does it do?
It allows me to visually represent the tennis court as a grid of cells. In this case, the grid is 16x32 which happily leads onto a really simple and nice data structure. If you think about it, for each position on one side of the court, you have to encode a position on the opposing side. Well, if each side has a 16x16 grid, it just happily fits into a byte!! So I figured, for each cell in one side, I simply need to know the cell in the other side. So I have to fit 256 (16x16) positions. But those positions are all 0..255, so basically I only need 256 bytes for all the information (as one side becomes the index into the data stored as the corresponding position.
So for each top position X, I simply need to lookup myposition[x] in the byte array to find the cell index to stand in!
Now it would be a bit stiff if I simply took a cell position Y every time the other player moved to X, plus it doesnt really work for different play styles to just use one table.
So what I've done in the AI, is use several tables of 256 bytes each, essentially denoting different play styles, agressive, defensive, front court, middle court, rear court etc. Then take a weighted average of them based on the current state of the player. If they are aggressive, then clearly the aggressive positions are weighted more. This is also "fuzzified" a little to make it a little less distinct.
I'll show some videos of the resulting gameplay soon. But suffice to say its moving onwards. I expect we'll have it there at IGC for some test play!
I doubt it'll be ready for wimbledon though :)
And what would a plan be without the obligatory shot?
Here is the editor in all its glory. Ok, its not much visually, but it does the job and the code was relatively easy to knock out. Once I get .net 2005 and the help files installed, I expect to throw out a few more sports game editors (in particular, I want to actually make a playfield editor and some editors for the next sports games to make them a lot more data-driven).

What you see here, is the court, with a 16x32 cel grid overlay. You can click on the court and if you click the top half, it sets the "current index". This is mirrored in the edit spinners on the left (I figured it would be good to have more precise control and a way to test my editing values). The "current index" is the index into an array of byte values which are positions in the bottom 16x16 part of the grid. When you click the top half, it shows the red dot on the corresponding cel of the bottom half. If you click on the bottom half, it sets the values at myposition[currentindex] to the cel you click.
So essentially the save file (.tns) is just a 256 byte array of values :)
I'm quite happy with the result, given that it does the job and doesnt have any frills. Its been pretty quick to put together. Next app should be a lot quicker to get done, especially considering I'll have the docs :)
Til next time!
Recent Blog Posts
| List: | 09/18/08 - Tell me I'm not going crazy!! 12/05/07 - The importance of good tools for productivity 11/17/07 - Using the way back machine. 09/21/07 - Juggling cats. 09/04/07 - End of Summer. 08/27/07 - Come work with me!! 08/14/07 - The changing nature of entertainment 07/25/07 - Someone stole my notes!! |
|---|
Submit your own resources!| James Thompson (Jun 25, 2006 at 20:18 GMT) |
| Tom Eastman (Eastbeast314) (Jun 25, 2006 at 21:25 GMT) |
Hopefully that made sense. It might not matter depending on how the game mechanics work anyway. I can't wait to see a movie of the AI in action!
| Phil Carlisle (Jun 25, 2006 at 21:43 GMT) |
As it is, there are a few weighting factors to determine the position. Simply marking out a new set that covers different angles and including that in the weighting is relatively painless.
You must be a member and be logged in to either append comments or rate this resource.



Not Rated


