The 8 Queen Problem in Computer Science - full Python code solutions
Автор: Bytes N Bits
Загружено: 2020-10-18
Просмотров: 22114
In the 8 queen problem you have a chess board and eight queens. You have to place all eight queens onto the board so that no two queens are attacking each other.
If you're not familiar with chess it's a game played on an eight by eight grid of squares (the same as draughts or chequers!). A queen is one of the chess pieces that can move in straight lines; horizontally, vertically or diagonally. A queen is attacking any other square that she can move to, so no two queens can be horizontally, vertically or diagonally aligned.
So we have to design a computer program that will find all the possible solutions to the problem.
Using brute force and just trying out every possible combination of placing the queens on the board results in having to test 4,426,165,368 combinations. If we can process 50,000 combinations per second that's going to take our computer over 24 hours to complete the task. We need a better solution!
We can start to work out ways of reducing this workload by examining the problem and optimising our algorithm.
In the video I'll walk you through designing the algorithm and then coding it. First we'll use a nested looping structure - placing for loops within for loops.
We'll then see how this lends itself to a solution using recursion. Don't run away at the mention of recursion! It's actually quite straight forward once you get the hang of it and drastically reduces the complexity of nested loop and tree structure based coding.
Make sure you visit the project page for this to download all the code used in the video.
https://bytesnbits.co.uk/the-8-queen-...
If you're interested in learning how to code in Python check out my beginners Python course at
https://www.udemy.com/course/learn-py...
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: