This sample demonstrates how to use the GKMinmaxStrategist class to implement a computer-controlled opponent for turn-based, adversarial games. As part of this demonstration, the sample shows how to structure gameplay model code for use with the minmax strategist using the GKGameModel protocol and related APIs.
Tap in a column to drop a chip of your color there. (Red moves first, Black moves second.) Get four chips in a row -- horizontally, vertically, or diagonally -- to win.
This project builds a game in stages:
- The
AAPLBoardandAAPLPlayerclasses implement a generic model for a Four-In-A-Row game. Use theFourInARowTestsunit test case to exercise the generic game model. - The
AAPLViewControllerclass adds a UI for playing the game on an iOS device. With theUSE_AI_PLAYERmacro left undefined, the game is for two human players. - The classes and categories in
AAPLMinmaxStrategy.handAAPLMinmaxStrategy.mextend the generic game model to support using GameplayKit for opponent AI. - With the
USE_AI_PLAYERmacro defined, theAAPLViewControllerclass replaces user control for the second player (black chips) with an AI opponent using theGKMinmaxStrategistclass.
For a more thorough discussion of this project, see the chapter "The Minmax Strategist" in GameplayKit Programming Guide.
Xcode 7.0, iOS 9.0
iOS 9.0
Copyright (C) 2015 Apple Inc. All rights reserved.