develop-17 9403 March 1994
From the originals
13 scansMachine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.
These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.
Image 1
develop The Apple Technical Journal USING PROTO TEMPLATES ON THE NEWTON STANDALONE CODE ON POWERPC DEBUGGING ON POWERPC CONCURRENT PROGRAMMING WITH THE THREAD MANAGER WINDOW ZOOMING TRACKING QUICKDRAW GX MESSAGES CROSS-PLATFORM COMPATIBILITY AND MULTIPLE-MOVIE FILES TEN TIPS FOR GAME DEVELOPERS KON & BAL'S PUZZLE PAGE HISTORY OF THE DOGCOW MACINTOSH Q & A Issue 17 March 1994
A colorful cover illustration of overlapping tiled game boards with dot patterns, a yellow grid, tic-tac-toe marks, and a hand holding a stylus, with a white right column listing article titles.
Reading notes: Small caption-style icons at the bottom left have no legible text. The 'The Apple Technical Journal' tagline is small and spaced out; spacing reflects the original layout. Apple logo appears above the issue line but contains no text.
- Printed product names
- develop
- Printed dates
- March 1994
- Languages
- English
PDF page 1
develop The Apple Technical Journal USING PROTO TEMPLATES ON THE NEWTON STANDALONE CODE ON POWERPC DEBUGGING ON POWERPC CONCURRENT PROGRAMMING WITH THE THREAD MANAGER WINDOW ZOOMING TRACKING QUICKDRAW GX MESSAGES CROSS-PLATFORM COMPATIBILITY AND MULTIPLE-MOVIE FILES TEN TIPS FOR GAME DEVELOPERS KON & BAL'S PUZZLE PAGE HISTORY OF THE DOGCOW MACINTOSH Q & A Issue 17 March 1994
A colorful tiled background with torn paper overlays showing grids of colored dots, a hand holding a stylus at the bottom, and three round icons at the bottom left, beside a column of bold cover story titles on the right.
Reading notes: The small Apple logo above Issue 17 is a graphic, not text; the thin letter-spaced subtitle 'The Apple Technical Journal' is light and was read from the scan.
- Printed dates
- March 1994
- Languages
- English
PDF page 2
E D I T O R I A L S T A F F Editor-in-Cheek Caroline Rose Technical Buckstopper Dave Johnson Our Boss Greg Joswiak His Boss Dennis Matthews Review Board Pete (“Luke”) Alexander, Jim Reekes, Bryan K. (“Beaker”) Ressler, Larry Rosenstein, Andy Shebanow, Gregg Williams, Dean Yu Managing Editor Cynthia Jasper Contributing Editors Lorraine Anderson, Toni Haskell, Judy Helfand, Elaine Meyer, Rebecca Pepper Indexer Marc Savage A R T & P R O D U C T I O N Production/Art Director Diane Wilcox Technical Illustration Shawn Morningstar, John Ryan Formatting Forbes Mill Press Film Services Aptos Post, Inc. Prepress Production PrePress Assembly Printing Wolfer Printing Company, Inc. Photography Sharon Beals Cover Illustration Mark Jenkins of Rucker Huggins Design Online Production Cassi Carpenter develop, The Apple Technical Journal, a quarterly publication of Apple Computer’s Developer Press group, is published in March, June, September, and December. This issue’s CD. The develop Bookmark CD (or the Developer CD Series disc, Reference Library edition) for March 1994 or later contains this issue and all back issues of develop along with the code that the articles describe. The develop issues and code are also available on AppleLink and via anonymous ftp on ftp.apple.com. Note that some software and documentation referred to as being on this issue’s CD may be located on the Tool Chest edition rather than the Reference Library edition of the Developer CD Series disc. Macintosh Technical Notes. Where references to Macintosh Technical Notes in develop are followed by something like “(Memory 13),” this indicates the category and number of the Note on this issue’s CD. E-mail addresses. Most e-mail addresses mentioned in develop are AppleLink addresses; to convert an AppleLink address to an Internet address, append “@applelink.apple.com” to it. For example, DEVELOP on AppleLink converts to develop@applelink.apple.com on the Internet. To convert a NewtonMail address to an Internet address, append “@online.apple.com” to it.
Reading notes: No primary headline is clearly printed; the spaced-out 'E D I T O R I A L S T A F F' label is a section heading and was not treated as a headline. No advertised products or prices appear in the supplied copy; 'develop', 'Developer CD Series', 'Bookmark CD', 'Macintosh Technical Notes', 'AppleLink' and 'NewtonMail' are publication or service references rather than advertised products. Visual layout, artwork and column arrangement could not be verified from the supplied text alone. Month names 'March', 'June', 'September' and 'December' appear without a year in the publication schedule and were not listed as separate dates.
- Printed dates
- March 1994
- Languages
- English
PDF page 3
CONTENTS March 1994 1 © 1994 Apple Computer, Inc. All rights reserved. Apple, the Apple logo, APDA, AppleLink, AppleShare, AppleTalk, ImageWriter, LaserWriter, MacApp, Macintosh, Macintosh Quadra, MPW, MultiFinder, PowerBook, Reanimator, and SADE are trademarks of Apple Computer, Inc., registered in the U.S. and other countries. AOCE, develop, the dogcow logo, Finder, Moof, Newton, QuickDraw, QuickTime, Sound Manager, SourceBug, System 7, and TrueType are trademarks of Apple Computer, Inc. PostScript is a trademark of Adobe Systems Incorporated, which may be registered in certain jurisdictions. NuBus is a trademark of Texas Instruments. All other trademarks are the property of their respective owners. User interface excesses. 2 Floating windows corrections. 4 Using Proto Templates on the Newton by Harry R. Chesley For Newton developers, a sample game that uses proto templates to good effect; for everyone else, a flavor of what Newton development is like. 5 Standalone Code on PowerPC by Tim Nichols Standalone code is better and easier than ever before in the PowerPC environment. 36 Debugging on PowerPC by Dave Falkenburg and Brian Topping It’s a whole new world in there, but your hard-won debugging skills still work. 51 Concurrent Programming With the Thread Manager by Eric Anderson and Brad Post With both cooperative and preemptive threads, the possibilities provided by the new Thread Manager are nearly endless. 73 The Zen of Window Zooming by Dean Yu Everybody does it, but many still don’t do it right. Dean has some code to help you out. 101 Print Hints: Tracking QuickDraw GX Messages by Pete (“Luke”) Alexander MessageWatcher lets you spy on QuickDraw GX printing. 32 The Veteran Neophyte: Why We Do It by Dave Johnson Why do people like to program computers? The results of an ad hoc survey. 48 Somewhere in QuickTime: Cross-Platform Compatibility and Multiple-Movie Files by John Wang The title says it all. 70 View From the Ledge by Tao Jones Amazing advice about awful allies. 99 Ten Tips for Game Developers by Brigham Stevens Things you should know if you want to write games for the Macintosh — or even if you don’t. 114 KON & BAL’s Puzzle Page: When Maps Go Bad by Konstantin Othmer and Bruce Leak More Macintosh orienteering with KON and BAL. 130 History of the Dogcow: Part 1 by Mark (“The Red”) Harlan Here it is for the first time — the real story, from someone who was there. 135 Macintosh Q & A Apple’s Developer Support Center answers your questions about product development, postage stamp glue, and more. 119 137 I N D E X Q & A C O L U M N S A R T I C L E S L E T T E R S E D I T O R I A L
Reading notes: Page numbers and contents columns are interleaved in the extracted order, so the reading order of article titles and page numbers may be uncertain.
- Printed product names
- Apple · Apple logo · APDA · AppleLink · AppleShare · AppleTalk · ImageWriter · LaserWriter · MacApp · Macintosh · Macintosh Quadra · MPW · MultiFinder · PowerBook · Reanimator · SADE · AOCE · develop · dogcow logo · Finder · Moof · Newton · QuickDraw · QuickTime · Sound Manager · SourceBug · System 7 · TrueType · PostScript · NuBus
- Printed dates
- March 1994 · 1994
- Languages
- English
PDF page 4
Dear Readers, We’re excited to bring you, in this issue, develop ’s first Newton article. Even if you’re not set up for Newton development, you may find this article of interest. But it’s the article on zooming windows that inspired this editorial. The subject is user interface annoyances: those cases where the application doesn’t quite do what the user expects it to — as when a window zooms to an odd location — and the user has to adjust for it. So what’s the big deal? Well, it all adds up. Over time, the harm to the user from compensating for these problems can be physical as well as mental. You’ll end up with a customer who is suffering in more ways than one. As Joan Stigliani puts it in her forthcoming book, High-Tech Health: The Computer User’s Survival Guide : “Software can make you work hard and contribute to overuse if it requires a lot of mouse use — clicking and dragging, scrolling, moving the cursor back and forth across the screen — or a lot of complex key sequences or excessive keying. Software that is difficult or frustrating to use can increase stress and tension.” This especially struck a chord with me, since I suffer from tendinitis caused by excessive keying and mousing. So I’m going to take advantage of this opportunity to vent my frustration (isn’t that what editorials are for?). Mainly, I hope to have at least some small influence on how you design the interface for your applications in the future. Why do so many applications lack common sense? Why, for example, shouldn’t Print or Save work on my frontmost document even if the active window happens to be a dialog box? Why can’t I just type Command-F followed by text to be found rather than first have to select the text that the application (for some odd reason) didn’t choose to highlight in the Find dialog? Why, even on my two-page monitor, do I have to resize a teeny window for every piece of e-mail I receive, or read a mere eight lines at a time, scrolling repeatedly (excessively) to get to the end? Why, when I cut a double-clicked word and then paste it, do so few applications add spaces intelligently? The list of user interface superfluities goes on and on; these are only the problems I encounter most frequently each day. Please, give my hands (and my mind) a break! If I may make a few suggestions: • Don’t blindly follow what other applications have done: maybe they didn’t think it through well enough. There’s a place for d e v e l o p Issue 17 CAROLINE ROSE (AppleLink CROSE) started writing and programming at a company called Tymshare, where she thought at first that the terminal was the computer. (She was stunned to learn it occupied a huge room in another building.) By the time computers were the size of terminals, Caroline was on her way to Apple to write Inside Macintosh. She digressed to spend five years at NeXT, where she managed the Publications group, but returned to the Apple fold to edit develop. Caroline owes her love of the printed word to her father, who worked for the New York Daily News for over 50 years. There was no greater thrill as a child than to go to the office with him and see the copy desks, darkrooms, printing presses — and, of course, the editors. She’d like to take this opportunity to say thanks, Dad, and Happy 85th Birthday!• 2 CAROLINE ROSE
Reading notes: Line breaks and spacing in the source text are irregular, so the reading order of the sidebar about Caroline Rose may be imperfect. The phrase 'Happy 85th Birthday' is followed by a stray bullet and page number '2' that may belong to the layout rather than the copy.
- Printed product names
- develop · High-Tech Health: The Computer User's Survival Guide · Inside Macintosh · NeXT · Newton · Apple · Tymshare · AppleLink CROSE · New York Daily News
- Printed dates
- Issue 17 · 50 years · 85th Birthday
- Languages
- English
PDF page 5
guidelines and precedents, but don’t totally disregard common sense. • Use the application yourself for real tasks until you’re blue in the face. Be honest; what bugs you about it? Your users will be even less tolerant. • Do extensive user testing before first ship, of course — but even after you ship, solicit feedback and incorporate it into the next release. Be sure to get feedback from experienced users, not just first-timers. • Beware of creeping featurism: fix problems your testers or customers have with current features before adding new ones. These suggestions are based on my own experience as the user manual writer and ad hoc product manager for the first version of the WriteNow application. John Anderson, one of the authors of WriteNow, says he thinks interface problems stem from software being too hard to write (something his next product will address) and from the related problem of software teams being too large. With many specialized programmers on a project, no one person focuses on the overall picture well enough to make the requisite intelligent decisions about the interface. Given a large team, a good product manager can make all the difference in the world. Look for someone both knowledgeable about the market and able to grasp the technical issues. As I noted about technical writing in an earlier editorial, product management isn’t a job that just any smart person can do, or that CEOs or VPs should tackle in their spare time. So I guess the moral is that more is not always better — not when it comes to features in an application or programmers on a project, and certainly not when it comes to keystrokes and mouse clicks in an interface. Please, keep it clean. Caroline Rose Editor EDITORIAL March 1994 3 SUBSCRIPTION INFORMATION Subscriptions to develop are available through APDA (see inside back cover for APDA information), or you can use the subscription card in the back of this issue. Please address all subscription-related inquiries to develop, Apple Computer, Inc., P.O. Box 531, Mt. Morris, IL 61054 (or AppleLink DEV.SUBS).• BACK ISSUES For information about back issues of develop and how to obtain them, see the last page of this issue. Back issues are also on the develop Bookmark CD and the Developer CD Series disc.•
Reading notes: Page header and number '3' interleaved with subscription text; reading order may be uncertain Subscription information section appears to be a sidebar or separate block
- Printed product names
- WriteNow · AppleLink DEV.SUBS
- Printed dates
- March 1994
- Languages
- English
PDF page 6
FLOATING BUGS I liked Issue 15’s article on floating windows and have successfully implemented your routines. I did, however, find one bug. Your routine HideReferencedWindow can leave the process’s window list pointing to a deallocated window when there are no floating windows. — Chester Murphy Thanks for pointing this out. It’s fixed — along with some other small bugs — in the code on this issue’s CD. (It’s been fixed since Issue 16’s CD.) — Dean Yu PRAGMATIC SOLUTION Floating windows is one of my favorite subjects. I tried to compile your WindowExtension example, using THINK C 6.0. My first problem was with USES68KINLINES. THINK C checks the #pragma parameter with the function declaration. So I tried to use A1 and D0 as parameters, but then I needed a few more #pragmas for the activate handlers. I still don’t have a working version. Also, could you explain why we need CallUniversalProc? I’m quite happy with the C syntax. Thank you very much for doing such a good job on the article. — Robert Puyol The use of USES68KINLINES has changed since Issue 15 went to press. Currently, #pragma parameters aren’t used any more, so you shouldn’t have any problems using the header file with THINK C. Additionally, the new version of the floating windows code uses the universal header files that are discussed in the “Making the Leap to PowerPC” article in Issue 16 and are on this issue’s CD. We recommend using CallUniversalProc in your source code (or one of its specific variants, like CallActivateHandlerProc in the floating windows code) to allow for greater portability of your source code between platforms. For a detailed explanation of using CallUniversalProc and UniversalProcPtrs, check out the aforementioned article in Issue 16. — Dean Yu DESKTOP FILES REDUX I liked Issue 15’s Puzzle Page, about the damaged desktop files. I’ve seen this bug often, since I fix a lot of damaged hard disks. You probably know this, but if the desktop files get hosed in a certain way, rebuilding them in the Finder won’t fix them. You have to delete them (or rename them) to get the Finder to build new files from scratch. AutoDoubler comes with a little utility called Desktop Reset just for deleting the desktop files. — David Shayer I didn’t know this when I wrote that Puzzle Page, but you’re right. When the desktop file gets damaged to the point where the File Manager can’t open it, the Finder can’t rebuild the file, so you have to throw it away or rename it. Thanks for the feedback. — Konstantin Othmer d e v e l o p Issue 17 IF MORE OF YOU DON’T WRITE, WE’LL HAVE TO START MAKING THEM UP! We welcome timely letters to the editors, especially from readers reacting to articles that we publish in develop. Letters should be addressed to Caroline Rose (or, if technical develop-related questions, to Dave Johnson) at Apple Computer, Inc., 20525 Mariani Avenue, M/S 303-4DP, Cupertino, CA 95014 (AppleLink CROSE or JOHNSON.DK). All letters should include your name and company name as well as your address and phone number. Letters may be excerpted or edited for clarity (or to make them say what we wish they did).• 4 LETTERS
- Printed product names
- THINK C 6.0 · WindowExtension · USES68KINLINES · CallUniversalProc · CallActivateHandlerProc · AutoDoubler · Desktop Reset · HideReferencedWindow · THINK C
- Printed dates
- Issue 15 · Issue 16 · Issue 17
- Languages
- English
PDF page 7
Proto templates are a central feature of the Newton development environment. All Newton applications use built-in prototypes, and developers can also write their own application-specific prototypes. This article uses proto templates in the design of an application that plays a few simple games. For non-Newton developers it reveals some of the flavor of designing and writing Newton applications. An application often includes multiple instances of a design element, with only minor variations among them. In object-oriented systems, it’s possible to share the common portions of the design among several different pieces of the application by using inheritance. On the Newton, you can do this with proto templates , which let you reuse the definition of a particular type of view very efficiently. Since views are the basic visual and functional elements of the Newton user interface, proto templates give you a very powerful ability to share and reuse user interface features. Built-in proto templates supply most of the common views seen in Newton applications — push buttons, pop-up menus, checkboxes, radio buttons, and so on. In addition, developers of Newton applications can define their own proto templates. These templates allow for very compact designs, shorter development times, easier maintenance, and smaller finished applications. In this article we develop a game application for the Newton called TapBoard. TapBoard is actually three games, each with its own style of board, rules of play, and algorithm for computer-generated moves. The games have many elements in common, and these can be abstracted into a proto template containing the shared aspects of the design. You’ll find much of the code for TapBoard in the article; the complete source code can be found on this issue’s CD. If you’ve never written a Newton application, see “(Slightly) Inside Newton Programming” for an introduction to the development process and some of the Newton terminology that’s used in this article. USING PROTO TEMPLATES ON THE NEWTON March 1994 5 HARRY R. CHESLEY (AppleLink CHESLEY1, NewtonMail CHESLEY) has spent most of the last three years in subspace (see develop Issue 7, “The Subspace Manager in System 7.0”) working on PowerTalk templates. His return to Earth-normal space was accompanied by an interstitial stutter, resulting in a temporary doubling of his personality matrix. This allowed him to simultaneously finish PowerTalk and design and write the NewtonScript communications interface (protoEndpoints). He’s better now, but still occasionally repeats himself in social situations. If he should happen to tell you a story you’ve heard from him before, just humor him and pretend it’s all new stuff. Too much self-referential introspection could cause a substitial relapse.• HARRY R. CHESLEY USING PROTO TEMPLATES ON THE NEWTON
Reading notes: Author bio contains whimsical wording that may be intentional humor rather than factual biography Pull-quote heading text may be split across lines in the source
- Printed product names
- Newton · TapBoard · PowerTalk · NewtonScript · System 7.0
- Printed dates
- March 1994
- Languages
- English
PDF page 8
d e v e l o p Issue 17 6 Programming the Newton is different — and I mean that in a good sense. Once you digest the Newton documentation, you can create a simple application and have it running on a Newton in about 15 minutes. The Newton development process encourages lots of quick code/compile/debug cycles — good for those of us who need positive reinforcement on a regular basis — and the cycle is short enough that you don’t notice a delay. OVERVIEW Before I describe how a Newton program works, here’s an overview of the development process. To create a Newton application, all you need is the Newton Toolkit (available from APDA), a serial cable, a 68030 Macintosh with 8 MB of memory and 32-bit addressing, and a Newton. You create your program with the Toolkit, compile it, and then download it to a Newton that’s connected to your Macintosh through a serial port. Your completed application appears in the Extras drawer, just like any other third-party Newton application. Using tools from a floating window called the layout palette, you draw the layout of your application — what its screens should look like — in layout windows. Not only can you reuse the dozens of user interface definitions that the Newton Toolkit supplies, you can create your own custom proto templates (more on proto templates below). Each layout or custom proto template is stored as a separate file; all of these files, plus optional files that contain the Macintosh-style resources your program needs, are grouped into what’s called a project. Once you’ve drawn all your views, you can open a browser window (familiar to users of object-oriented languages like Smalltalk and LISP). In the browser window, you can add and modify both code and data associated with the objects in your program. The code you write is in a new language called NewtonScript, which is a simple but sophisticated symbolic language with a Pascal-like syntax. Most of the (usually short) routines you’ll write execute when triggered by a user action, like the user’s tapping a button or writing in a designated area, or by a system action. You’re already acquainted with this event-driven approach from your experience in programming for the Macintosh. And if you’ve been doing object-oriented programming, the idea of a network of cooperating software objects, rather than a hierarchy of routines executed by a processor that’s always in control, is also familiar to you. FRAMES AND SLOTS One idea you may not be familiar with, depending on whether you’ve used object-oriented languages, is that of frames. Artificial intelligence fanatics will probably kill me, but I think of a frame as just a record of data, and slots as what most of us call record fields. However, slots in NewtonScript are more versatile than record fields in several ways. First, slots aren’t limited to one type of data. (Like Newton variables, slots aren’t typed and can hold, for example, an integer one minute and a frame the next.) Second, you can arbitrarily add or remove slots from a frame at any time, including during program execution. Third, you can access slots indirectly through path expressions; these allow you to store part of a slot’s pathname in a variable, thus letting the contents of a variable determine which slot gets accessed. In NewtonScript, a frame looks like this: { slotname1: value1, slotname2: value2, ..., slotnameN: valueN } Slot names can be omitted or mentioned in any order. By using the slot names _proto and _parent, you can create data structures that exhibit Newton’s flavor of object- oriented behavior, as discussed later in this article. To access the data in a frame’s slot, you use the notation framename.slotname (SLIGHTLY) INSIDE NEWTON PROGRAMMING BY GREGG WILLIAMS
Reading notes: Possible running header or page number 'd e v e l o p' and '6' interrupts reading order Byline 'BY GREGG WILLIAMS' and the heading '(SLIGHTLY)' are printed in an unclear order relative to the body text
- Printed product names
- Newton Toolkit · Newton · Macintosh · NewtonScript · Smalltalk · LISP
- Printed dates
- Issue 17
- Languages
- English
PDF page 9
USING PROTO TEMPLATES ON THE NEWTON March 1994 7 For more information about views, see the “Views” chapter of the Newton Programmer’s Guide.• TEMPLATES, VIEWS, AND PROTOS Everything you see on the Newton screen is composed of views. A view can display, among other things, a picture, a paragraph of text, an area for writing or drawing, an on-screen keyboard, a calendar-month page, a pop-up list, or a gauge (which is like a horizontal thermometer). Many of the things that you see on the screen are standard prefabricated user interface elements built into the Newton ROM and available to every Newton developer. These are called proto templates, or protos for short, and they include six different kinds of buttons and checkboxes, protoSliders (like a linear slider light switch), protoRolls (which allow information to scroll vertically off the screen), and different kinds of labels, borders, and standard interface elements. Each tool on the Newton Toolkit layout palette allows you to lay out a view or a proto. Views can contain views inside them, and in fact, a proto is a predefined hierarchical grouping of views that behaves in a certain way. You can create your own custom protos by drawing them in layout windows. In NewtonScript, you can describe a view as a frame called a template; the Newton later creates a view from the template at run time. The slots in a template represent the view’s data and the functions that implement the behavior you have to add. (Most views and protos have behavior built in, and the built-in behavior of a proto is often quite extensive.) When your application executes, a template (which cannot be changed) is used to create the data structure in RAM that corresponds to the visual representation of the view — that is, what you see on the Newton’s screen. To send a message to a view (that is, to invoke one of its methods), the syntax is view:messagename(arg1, arg2, ..., argN) (The function involved is the method, while the name used to invoke it is the message. You send a message to an object, and that causes the associated method to execute.) SYSTEM MESSAGES As with the Macintosh, Newton applications are driven by user events — the user taps or draws on the Newton screen in different places — as well as by system events. The Newton sends your program system messages, which trigger their corresponding methods. In some cases, you let the built-in Newton methods do their work; in many others, you write your own. There are 25 or so system messages you need to know about. Here are a few of them, and when the corresponding methods execute: • viewChangedScript: executes when a view slot is changed using the SetValue function or when certain functions change a view directly • viewDrawScript: executes when a view needs to be drawn • viewStrokeScript: executes when a user writes inside a view • viewSetupFormScript, viewSetupChildrenScript, viewSetupDoneScript: execute at specific points during the setup of a view, before the view is displayed • viewIdleScript: executes periodically • viewQuitScript: executes just before a view is disposed of Some system messages pertain to particular views — for example, buttonClickScript (for buttons), keyPressScript (for keyboard views), and monthChangedScript (for the monthly calendar view). AND THAT’S JUST THE BEGINNING. . . There’s a lot more to programming the Newton. You can find out more by reading the manuals that come with the Newton Toolkit. Be sure to read any errata sheets, release notes, and “read me” files; I overlooked one and missed a piece of information that would have saved me several days’ work!
Reading notes: Running headers and page number may be mixed into reading order Hyphenation and line breaks in extracted copy could affect exact term spelling
- Printed product names
- Newton · Newton Programmer's Guide · Newton Toolkit · NewtonScript · Macintosh
- Printed dates
- March 1994
- Languages
- English
PDF page 10
GAMES WE’RE GOING TO PLAY TapBoard plays three games: Tic-tac-toe, Gomoku, and Reversi. The user chooses one of the games from a set of radio buttons, a game board is displayed, and the user moves by tapping a square on the board. The application responds with a countermove. This process repeats until one player wins or the game ends in a tie. When the user closes TapBoard, the application remembers the state of the board — which game is being played, where the pieces are placed, whose turn it is, and the game’s outcome. When TapBoard is reopened, it restores the state so that the user can continue the game where it left off. So, common elements shared by the games include the following: • displaying the board to the user • adding a new move to the board display • acknowledging the user’s tap with an appropriate sound • tracking the stroke to decide whether it ended on the same square as it started on • figuring out which square it was, and whether the move is valid • recording the move • checking it to see if it’s a winning or tying move • uncovering a good move when it’s TapBoard’s turn • saving the state of the board when the user closes the game • restoring the state when the game is reopened All these common actions can be abstracted into a prototype that each specific game can then inherit from (as described later in the section “The protoBoard Proto Template”). But since the games are different, each also has its own rules and possibly its own board, and each requires its own algorithm for finding good moves for the computer; details follow. TIC-TAC-TOE You undoubtedly know this game, but we’ll describe it briefly: Tic-tac-toe is played on a 3 x 3 board with players taking turns making X’s and O’s. The first player to get three in a row horizontally, vertically, or diagonally wins. If neither player gets three in a row, the game is tied. Figure 1 shows a typical game of Tic-tac-toe. X gets three on the diagonal and wins. Tic-tac-toe is a simple game to master. There are a few easy heuristics, such as always take the center square if you can, and with a little thought it’s not hard to see several moves ahead. d e v e l o p Issue 17 8
- Languages
- English
PDF page 11
TapBoard’s algorithm for determining a good Tic-tac-toe move involves doing a two- move look-ahead, combined with some simple heuristics. The look-ahead tries all possible moves, then tries all possible answering moves. The heuristic gives greater weight to taking the center and corner squares. This algorithm doesn’t play a perfect game of Tic-tac-toe, but this is actually an advantage, for two reasons: it pulls players into the game by giving the impression that the computer is an easy target, and it provides a game that’s playable by younger users (my five-year-old daughter loves it). GOMOKU Gomoku is played on an 8 x 8 board. Players take turns placing pieces on the board, and the first player to get five in a row horizontally, vertically, or diagonally wins. Figure 2 shows a short game of Gomoku won by white (a real game would of course be played more defensively than this one, which is for demonstration purposes only). Gomoku is more challenging than Tic-tac-toe. The larger game board and longer winning sequence make for many more combinations, and the game virtually requires that the winner “sneak up” on the loser, rather than just going for a simple sequence of five pieces, which the opponent can easily detect and prevent. TapBoard’s approach to finding a good Gomoku move involves making three passes over the board: the first looks for winning moves; the second looks for situations where the user has three or more in a row and tries to block those; the third looks for USING PROTO TEMPLATES ON THE NEWTON March 1994 9 • • • Figure 1 Tic-tac-toe • • • Figure 2 Gomoku
Reading notes: Running header 'USING PROTO TEMPLATES ON THE NEWTON' and page number 9 may be page furniture rather than body text.
- Printed product names
- TapBoard · Newton
- Printed dates
- March 1994
- Languages
- English