Finding Victory Conditions

The if statements in aiTurn are where the bulk of the logic takes place. They determine whether either player has two tiles in a row. While the steps for each check are basically the same, we’ll focus on the first one: the check to see whether a computer player is one tile away from a win. To answer this question, you can build a method called rowCheck and a series of short, related functions:

  func rowCheck(#value:Int) -> [String]?{      var acceptableFinds = ["011","110","101"]      var findFuncs = [checkTop,checkBottom,checkLeft,checkRight,          checkMiddleAcross,checkMiddleDown,          checkDiagLeftRight,checkDiagRightLeft]      var algorithmResults = findFuncs[0](value: value) ...

Get Learning Swift™ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.