Book Image

Swift Cookbook

By : Cecil Costa, Cecil Costa
Book Image

Swift Cookbook

By: Cecil Costa, Cecil Costa

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The best checker movement


If you have some experience with programming, you know that sometimes we need to proceed step by step with the code, mainly when we have those kinds of issues that nobody knows how it happened.

In this recipe, we will learn how to debug with Xcode and Swift. To do this, we will recycle our checkerboard. In this case, we will make the best movement using the white pieces. We will also leave the app ready for a second version; this app can also make use of kings.

We will not create the right algorithm in the beginning; the idea is to debug and find where the issue is, and then, we will correct the issues later.

Getting ready

Open your playground project from the previous chapter where you have the checkerboard. Leave it open because we will reuse this code. Once it's open, create a new project called Chapter 7 checkerboard. Let's start coding.

How to do it...

Follow these steps to visualize a checkerboard:

  1. Create a new file called CheckersBoard.swift. Start coding by importing...