Chapter 6. Computer AI

In this chapter, I will show how to create a computer player that can play a decent game of air hockey. I will investigate the different behaviors of a human player in order to come up with a strategy that the computer can follow. This logic will tweaked to allow for different difficulty levels of play. Multiple levels of play will allow people to start at an easier level so they can learn how to play and then progress up in difficulty. The first thing you will need to do is create a title screen for the game so the player can choose to play against the computer or play the two player mode that has already been implemented.

Computer Player Menu

You have only been using one view controller that is in charge of the gameplay. You will now introduce a new view controller to manage the title screen. You need to create a new view controller just like you did for the Paddle and Puck objects, by Control-clicking the Paddles folder in the Navigator and selecting New File... from the pop-up menu. Instead of selecting the NSObject subclass, you will select UIViewController instead, and then click Next. Name the Class TitleViewController, make sure the “Targeted for iPad” option is not checked, “With XIB for user interface” is checked, and then click Next. Make sure the new class is being created in the same location as all the other files and click Create. Xcode has created TitleViewController.h, TitleViewController.m, and TitleViewController.xib files and added them to ...

Get Tap, Move, Shake now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.