From the course: Code Clinic: Ruby
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Hints, tips, and tricks
- [Voiceover] In this movie, I'll give you some guidance that can help you to approach this challenge. The first thing that we'll need to do is to define our chess board and our queen. In Ruby, these will each be a class. We'll have a Ruby class for board and a Ruby class for queen. Those classes can be instantiated into objects. We can create a new instance of our board class and then we can create eight new instances of our queen class in order to place them on the board. Those classes are going to have some intelligence. They're going to have methods to find on them, they will allow them to know things, to do things, and to interact with each other. So one of the first choices we'll need to make is to decide if the board or the queen is going to be in charge of detecting safe positions. I've seen this programmed both ways. Much of the direction that your solution takes will depend on this early fundamental choice. Now this is the eight queens problem and we are using a standard…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Eight Queens problem1m 46s
-
Hints, tips, and tricks3m 54s
-
Overview of my solution5m 55s
-
Queen and board classes6m 10s
-
Displaying the board7m 1s
-
Determining safe positions6m 48s
-
Using loops7m 8s
-
Loops with backtracking5m 12s
-
Loops with smarter backtracking6m 2s
-
Recursion primer3m 45s
-
Using recursion6m 52s
-
Finding all possible solutions5m 46s
-
Further exercises3m 56s
-
-
-
-