Moving In for the Win

By using rowCheck and a few related functions, you’ve taught the AI how to scan the game board for a winning tile. The next step is teaching it how to take action, marking a tile to secure victory. The rowCheck method includes many moving parts, so to speak. If you’re not entirely sure how it works, consider reviewing the previous sections before moving forward. When you’re ready to continue, step back and look at rowCheck in the context of aiTurn:

    if let result = rowCheck(value: 0){        println("computer has two in a row")        var whereToPlayResult = whereToPlay(result[0], pattern: result[1])        if !isOccupied(whereToPlayResult) {            setImageForSpot(whereToPlayResult, ...

Get Learning Swift™ Programming 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.