Book Image

TypeScript Blueprints

By : Ivo Gabe de Wolff
Book Image

TypeScript Blueprints

By: Ivo Gabe de Wolff

Overview of this book

TypeScript is the future of JavaScript. Having been designed for the development of large applications, it is now being widely incorporated in cutting-edge projects such as Angular 2. Adopting TypeScript results in more robust software - software that is more scalable and performant. It's scale and performance that lies at the heart of every project that features in this book. The lessons learned throughout this book will arm you with everything you need to build some truly amazing projects. You'll build a complete single page app with Angular 2, create a neat mobile app using NativeScript, and even build a Pac Man game with TypeScript. As if fun wasn't enough, you'll also find out how to migrate your legacy codebase from JavaScript to TypeScript. This book isn't just for developers who want to learn - it's for developers who want to develop. So dive in and get started on these TypeScript projects.
Table of Contents (16 chapters)
TypeScript Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Chapter 9. Playing Tic-Tac-Toe against an AI

We built the game Pac Man in the previous chapter. The enemies were not very smart; you can easily fool them. In this chapter, we will build a game in which the computer will play well. The game is called Tic-Tac-Toe. The game is played by two players on a grid, usually three by three. The players try to place their symbols three in a row (horizontal, vertical or diagonal). The first player can place crosses, the second player places circles. If the board is full, and no one has three symbols in a row, it is a draw.

The game is usually played on a three-by-three grid and the target is to have three symbols in a row. To make the application more interesting, we will make the dimension and the row length variable.

We will not create a graphical interface for this application, since we have already done that in Chapter 6 , Advanced Programming in TypeScript. We will only build the game mechanics and the artificial intelligence (AI). An AI is a player...