Advertisement
jedrzejd

parametryzacja skoczka

Sep 5th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  Konik
  4. //
  5. //  Created by Jędrzej Dudzicz on 05.09.2017.
  6. //  Copyright © 2017 Jędrzej Dudzicz. All rights reserved.
  7. //
  8. /*Przydład
  9. 46 51 36 57 44 59 38 31
  10. 35 56 45 52 37 32 43 60
  11. 50 47 54 33 58 39 30 23
  12. 55 34 49 40 53 24 61 42
  13. 48 13 16 25 62 41 22 29
  14. 17 4 11 14 1 26 63 8
  15. 12 15 2 19 6 9 28 21
  16. 3 18 5 10 27 20 7 64
  17. */
  18. #include <iostream>
  19. #include <cstdio>
  20. #include <algorithm>
  21. using namespace std;
  22. int skoczek[9][9];
  23. int x,y,n;
  24. void wypisz(){
  25.     for(int q=0;q<8;++q){
  26.         for(int j=0;j<8;++j){
  27.             printf("%d ",skoczek[q][j]);
  28.         }
  29.         printf("\n");
  30.     }
  31.    
  32. }
  33. bool skok(int ktury,int x,int y,int&a,int&b){
  34.     if(ktury==1){
  35.         a=x+1;
  36.         b=y-2;
  37.     }
  38.     if(ktury==2){
  39.         a=x+2;
  40.         b=y-1;
  41.     }
  42.     if(ktury==3){
  43.         a=x+2;
  44.         b=y+1;
  45.     }
  46.     if(ktury==4){
  47.         a=x+1;
  48.         b=y+2;
  49.     }
  50.     if(ktury==5){
  51.         a=x-1;
  52.         b=y+2;
  53.     }
  54.     if(ktury==6){
  55.         a=x-2;
  56.         b=y+1;
  57.     }
  58.     if(ktury==7){
  59.         a=x-2;
  60.         b=y-1;
  61.     }
  62.     if(ktury==8){
  63.         a=x-1;
  64.         b=y-2;
  65.     }
  66.     if(0<=a&&a<8&&0<=b&&b<8&&skoczek[a][b]==0)return true;
  67.     return false;
  68. }
  69. bool konik(int x,int y,int n){
  70.     int a,b;
  71.     skoczek[x][y]=n;
  72.     if(n==64){
  73.         wypisz();
  74.         return 1;
  75.     }
  76.     else {
  77.         for(int i=1;i<=8;i++){
  78.             if(skok(i,x,y,a,b)==true)
  79.                 if(konik(a,b,n+1)==true)
  80.                     return true;
  81.         }
  82.         skoczek[x][y]=0;
  83.     }
  84.     return false;
  85. }
  86. void start(int i,int j){
  87.     konik(i,j,1);
  88. }
  89. void czysc(int** skoczek){
  90.     for(int i=0;i<8;i++)
  91.         for(int j=0;j<8;j++)skoczek[i][j]=0;
  92. }
  93. int main() {
  94.     start(0,0);
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement