You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.6 KiB

  1. #define _CRT_SECURE_NO_WARNINGS // to write faster
  2. #define re return
  3. #define N 20 // size of Play Field
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include<stdlib.h>
  7. #include<time.h>
  8. #include<stdbool.h>
  9. int win(int realU[N][N]){
  10. int groesste = 0;
  11. for(int i = 0; i < N; i++){
  12. for(int j = 0; j < N; j++){
  13. if(realU[i][j] > groesste && realU[i][j] != (N * N ) + 1){
  14. groesste = realU[i][j];
  15. }
  16. }
  17. }
  18. if(groesste == (N * N) - 1){
  19. return 1;
  20. }
  21. else{
  22. return 0;
  23. }
  24. }
  25. //Die Funktion überprüft, ob das Feld bereits vom Schlangenkoerper besetzt ist.
  26. int feldFrei(int realU[N][N], int ii, int jj){
  27. if (realU[ii][jj] == 0)
  28. {
  29. return 1;
  30. }
  31. return 0;
  32. }
  33. int lose(int realU[N][N], char richtung){
  34. int groesste = 0; //Suche den Kopf der Schlange
  35. int ii, jj;
  36. for(int i = 0; i < N ; i++){
  37. for(int j = 0; j < N; j++){
  38. if (realU[i][j] > groesste && realU[i][j] != (N * N) + 1){
  39. groesste = realU[i][j];
  40. ii = i;
  41. jj = j;
  42. }
  43. }
  44. }
  45. if (richtung == 'u') {
  46. if (realU[ii - 1][jj] != (N*N) + 1&& realU[ii - 1][jj] != 0) {
  47. return 1;
  48. }
  49. }
  50. else if (richtung == 'd') {
  51. if (realU[ii + 1][jj] != (N*N) + 1 && realU[ii + 1][jj] != 0 || ii == 20) {
  52. return 1;
  53. }
  54. }
  55. else if (richtung == 'l') {
  56. if (realU[ii][jj-1] != (N*N) + 1 && realU[ii][jj-1] != 0 || jj == 0) {
  57. return 1;
  58. }
  59. }
  60. else {
  61. if (realU[ii][jj + 1] != (N*N) + 1 && realU[ii][jj + 1] != 0) {
  62. return 1;
  63. }
  64. }
  65. return 0;
  66. }
  67. int probe(int input){
  68. return input;
  69. }