Thursday, July 24, 2008

Multiplayer Game Basics

Multiplayer games come in all kinds of formats, genres, and languages. In this article, I will discuss the bare-bone concepts of a multiplayer game and even give step-by-step intructions for making a multiplayer backend (server) with Java. While I will only be discussing Java specifically, all the concepts apply to all programming languages. The general concepts require no real prior programming knowledge, though the Java tutorial accompanying this article requires a basic understanding of how Java works.

Multiplayer games can be put into one of two basic structures: Client-to-Client or Client-to-Server. In Client-to-Client games, the client communicates directly with another client, while in Client-to-Server, clients communicate with a server without ever having to talk directly to the other clients. This article will discuss Client-to-Server communications as this is usually the more preferred type for multiple reasons, which are outlined in the following table.

Advantages of
Client-to-Client vs. Client-to-Server
Client-to-Client

  • Low to no cost of operation to publisher
  • No reliance on publisher
  • Individual modifications
Client-to-Server

  • Security of clients
  • Slower clients dont slow down others
  • Centralized statistics
  • More quickly updated
  • Clients experience the game the way it was meant to be


All of these advantages and their inherited disadvantages can be traced to the simple fact that Client-to-Client games are individually owned and maintained by those who play them, where the Client-to-Server games are based around a "centralized" system of computers that are all maintained by the game publisher or others who are given permission to do so by the publisher. Before we begin the in-depth portion of the article, I want to clarify what a server is. A server in multiplayer games refers to a variant of the game or a related program that allows clients to communicate with it, and subsequently relay those communications to other clients who are connected to the same server. This web of client connections is called a network. Ironically, even in Client-to-Client structures a server exists. The server in this structure is more commonly referred to as the host, since their computer is not dedicated to serving the network.

Connections between computers over networks (i.e. the Internet or LAN) is usually accomplished with a system of sockets. A socket is a pipeline linking the server and client through a computer port. Each client shares a unique socket with the server, so no other clients can read data meant for other clients. Data traveling between computers is referred to as a packet. Most programming languages support the use of sockets and packets. The servers job is to listen to a socket, take in packets, do what needs to be done with it, and possibly reply to the client with another packet, or even broadcast packets to other clients currently connected.

Now that we understand the technology involved, its time to get down and dirty with Java. We will be creating a simple Java application that listens for incoming connections, designates the connection to a socket, and replies to each packet sent by the client after that. Programming in Java requires a text editor (I use good ole Notepad), the Java Runtime Environment (JRE), and Java Development Kit (JDK). Both the JRE and JDK can be downloaded from Sun's website. Java source code is saved with the extension .java. After compiling, the resulting programs are saved with the extension .class.

I have already programmed and tested the Java applications. You can download MplayServer.java and MplayClient.java from SNR, along with a simple client named MyTalker.java. To compile and run the server, navigate to the directory you saved the source files to with command prompt, then use the following commands:

javac MplayServer.java
java MplayServer 8087


To compile and run the simple client, use the same commands as above, except replace MplayServer with MyTalker.

Edit: The full step-by-step tutorial is done. You can find it at http://www.subnetroot.com/source/j/Basic/tutorial.txt.

Wednesday, July 16, 2008

The Importance of Pictures

In presentations, pictures and visual aids are vital to keep the audiences attention and more effectively convey your points. In blogging, visual aids can be just as important. While the focus of blogging is on delivering raw information to the viewers, it can sometimes seem overwhelming to have an ocean of text with no means of visually presenting your information. I am admittedly guilty of this. I dont use images very often in any of my online pubications. In the future, I will try to include pictures in my blog posts so that visitors and subscribers dont get detered by all the reading.

On an unrelated subject, my last post on AI Design was the first in a series of entries about game design. The next one will be about multiplayer structures and will include an example written in Java showcasing how to use sockets to communicate between two or more computers. If you would like to suggest a topic for this series, or just something else youd like to read about, use the Contact Us form on BlakeNet or email me. blake.oxx@gmail.com (remove the dot)

Thursday, July 10, 2008

AI Design

I decided that Artificial Intelligence in the gaming world is something that is often glossed over when talking about game design in the sense that there are tons of pages detailing various dynamics of games a designer should consider, and even a couple discussing what exactly AI is. However, I am disappointed that there is a lack of publications describing the aspects of AI a game designer should know about when they decide to add some bots to their programs. While this post focuses on the impications, aspects, points of interest, etcetera specifically in AI for games, the concept can also be applied to Artificial Intelligence as a whole.

Lets start by defining what constitutes as Artificial Intelligence. AI is the ability of an object to make decisions that ultimately complete a set goal. This encompasses many things in a game, from bad guys shooting at you, to rival racers trying to beat you in a race. I like to split this definition into two types: Dumb AI and Smart AI. It might seem a little ironic that we call any amount of intelligence "dumb" or "smart", but it actually makes sense to classify AI as such. Imagine the classic game of Pong, where you play one paddle, and the bot (run by AI) plays the other. Each player tries to bounce the ball away from their side of the screen and past the other player. We classify this bot as having Dumb AI since it has a simple job of checking where the ball has moved to, and moving to match its position on the appropriate axis. There are no extra factors involved -- The bot doesnt check for where the player is, what kind of angle the ball should be bounced off at, or some other possibly critical decision-making datum. On the opposite side of the spectrum, imagine a game like Need For Speed, where the player is chased by police cars controlled by AI. This sort of AI is much more exciting in that the AI has to not only follow the player, but anticipate his next turn, dodge obstacles, and work together with other police cars to stop the player. This is a prime example of Smart AI. Dumb AI, while being effective in some situations, makes for very stale gameplay, or sometimes even frustration due to the bot being unbeatable.

Smart AI is what everyone wants to see more of. However, it comes with its own cons as well. A bot that is hardset on fulfilling a specific goal without factoring anything else in can lead to an unbeatable bot, which makes this type of AI just as terrible as the previous one. Since your average developer doesnt have a supercomputer residing in their moms basement, they arent capable of creating life-like intelligence that factors in human miscalculations and other realistic errors. This brings us to the next talking point; "Flawed" AI. To make sure a bots AI isnt infalible, many developers purposefully flaw their AI by adding a random chance that the AI will do the opposite of its goal, freeze up for a given amount of time, or something else that gives the player a chance to actually beat the bot. This sort of approach is completely in the wrong direction. The developer should not dumb down the AI for playability's sake. Now we get to the real meat behind this article. Lets examine two of the alternatives to purposefully dumbing down Smart AI, and figure out what Flawed AI really is.

First of all, consider what makes actual intelligence so manageable. Nature didnt create random counters that decide when an animal should eat and when it shouldnt. So what is stopping it from eating all of the food it can? The answer is a technique called prioritization. By prioritizing objectives, the animal can do what is most important at the time first, then doing the next most important thing. We can incorporate this into our AI in many different ways. Given that our game is a real-time strategy game like Age of Empires or Empire Earth, we can see how our gatherer-builders no longer gather until their "source of resources" is empty. Instead, they gather only when they need the resources and use the rest of the time to build vital structures.

Our second alternative is a business school classic called risk-benefit analysis. In this technique, the risk of a situation is compared to the possible benefits or perceived value. Risk-benefit analysis can be used in the previous example with similar effects. The further away a gold mine is from a guard tower, the more likely it is that the gatherer will be killed. In short, the further from defense, the higher the risk, and the less likely the gatherer will venture out to get that gold. To give another example, recall the Need For Speed police AI. The more police cars the player has damaged or totaled, the further back the other police cars will follow, and the less likely they will be to try to fish-tail the players car.

Flawed AI is an intelligent, objective-based approach to making AI more realistic and the gaming experience more enjoyable. Weve looked at just two alternatives to throwing our perfectly good Smart AI out the window. There are many more ways of achieving the same effect, but for now, Ill leave it at just these two. I might post about some more in a future article. Until then, enjoy building your worlds. If you have any games youre proud of, dont hesitate to post a link in the comments (Yes, comments are back up ;p ) or send them my way. blake.oxx@gmail.com (remove the dot)

Wednesday, July 02, 2008

HopeLine Promotion



Im subscribed to The PostSecret Project. PostSecret is like a catalog of human emotion. Every day, random people send in anonymous post cards with their most closely guarded secrets on one side of them, and every Sunday, a couple are selected to be posted on the PostSecret site. It is a truely great concept and I believe its one of the best credits to humanity. A couple of my friends and I have sent in some secrets of our own. Its a great feeling to know youre being listened to without judgement.

Recently, PostSecret asked those of us with the ability to promote HopeLine to do so if possible. Im doing my part. All of my websites now feature the above video on the front page. Its my way of saying thanks. Thank you HopeLine, thank you Post Secret, thank you for all that you do.