O'Reilly logo

Learning Swift™ Programming by Jacob Schatz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required