Learn VB .NET Through Game Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learn VB .NET Through Game Programming [Electronic resources] - نسخه متنی

Matthew Tagliaferri

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





Expanding the Cellular Automaton Games

As mentioned, cellular automaton programs serve as a popular topic in computer science discussions. There are dozens of variations of cellular automaton programs that you could create and add to this program by creating more subclasses of the CellularAutomataGame and CellularAutomataCell classes and adding abit of “wireup” code to make the main program aware of the new class (or you could go to the reflection-based self-discovery mechanism hinted at earlier).

One popular topic within the study of cellular automaton programs is optimizing them for speed so that a single tick executes as quickly as possible. Iintroduced one such optimization in the neighbor counting algorithm of the Life games—it turns out to be much more efficient to update neighbor counts of all living cells by 1 than it is to iterate through every cell counting living neighbors. Other algorithmic optimizations have been discovered, such as ones that identify blank regions of the lattice and skip the processing of those regions. You can find more information on such topics online. (Do a Google.com search on cellular automata to get started.)

The design of this chapter’s example program certainly warrants some refactoring if speed becomes your priority. This program redraws the entire lattice after each tick, for example. This isn’t always necessary depending on the type of game running. For example, it’s possible in the Voting Game for a turn to yield no change to the lattice. Why waste time redrawing it? You might also consider aregion-based redrawing algorithm, where only cells that actually change state are redrawn. This may or may not speed up the process. Others might argue that the entire class-based design of this example program would never be as fast as a more low-level data structure, such as a 22 array of integers, paired with some highly optimized functions for reading/writing this array. This structure of course defeats the purpose of the example—to demonstrate the object-oriented concept of polymorphism.

This cellular automaton program demonstrates polymorphism through inheritance. The subclasses of the CellularAutomataGame class can implement their functionality in many different ways, but the users of this class need to understand only the interface of the base class to use all of the subclasses effectively. Another major means of achieving polymorphism exists in the .NET Framework besides inheritance; it’s discussed in the next chapter.

/ 106