Time for action – the final four

That leaves us with four more functions to write: Win(), Block(), CreateTrap(), and PreventTrap(). Note that for the remainder of the chapter, we'll be using the word "row" to refer both to a horizontal line, and to three squares in a line regardless of their orientation, as in "in-a-row".

A very interesting thing happens if we carefully work out what needs to happen in each of these functions. Take the Win and Block functions first.

To determine whether we can win , we need to look at three spaces in a row. If two of the spaces in a row contain our piece, and the third is empty, we can win the game.

To determine whether we can block , we need to look at three spaces in a row. If two of the spaces contain the ...

Get Unity 4.x Game Development by Example Beginner's Guide 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.