Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Konik
- //
- // Created by Jędrzej Dudzicz on 05.09.2017.
- // Copyright © 2017 Jędrzej Dudzicz. All rights reserved.
- //
- /*Przydład
- 46 51 36 57 44 59 38 31
- 35 56 45 52 37 32 43 60
- 50 47 54 33 58 39 30 23
- 55 34 49 40 53 24 61 42
- 48 13 16 25 62 41 22 29
- 17 4 11 14 1 26 63 8
- 12 15 2 19 6 9 28 21
- 3 18 5 10 27 20 7 64
- */
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int skoczek[9][9];
- int x,y,n;
- void wypisz(){
- for(int q=0;q<8;++q){
- for(int j=0;j<8;++j){
- printf("%d ",skoczek[q][j]);
- }
- printf("\n");
- }
- }
- bool skok(int ktury,int x,int y,int&a,int&b){
- if(ktury==1){
- a=x+1;
- b=y-2;
- }
- if(ktury==2){
- a=x+2;
- b=y-1;
- }
- if(ktury==3){
- a=x+2;
- b=y+1;
- }
- if(ktury==4){
- a=x+1;
- b=y+2;
- }
- if(ktury==5){
- a=x-1;
- b=y+2;
- }
- if(ktury==6){
- a=x-2;
- b=y+1;
- }
- if(ktury==7){
- a=x-2;
- b=y-1;
- }
- if(ktury==8){
- a=x-1;
- b=y-2;
- }
- if(0<=a&&a<8&&0<=b&&b<8&&skoczek[a][b]==0)return true;
- return false;
- }
- bool konik(int x,int y,int n){
- int a,b;
- skoczek[x][y]=n;
- if(n==64){
- wypisz();
- return 1;
- }
- else {
- for(int i=1;i<=8;i++){
- if(skok(i,x,y,a,b)==true)
- if(konik(a,b,n+1)==true)
- return true;
- }
- skoczek[x][y]=0;
- }
- return false;
- }
- void start(int i,int j){
- konik(i,j,1);
- }
- void czysc(int** skoczek){
- for(int i=0;i<8;i++)
- for(int j=0;j<8;j++)skoczek[i][j]=0;
- }
- int main() {
- start(0,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement