Commit f8a1e286 authored by Simon Wüllhorst's avatar Simon Wüllhorst

Code Cleanup

parent edaf972b
......@@ -10,68 +10,95 @@
#include <stdio.h>
#include <stdlib.h>
#define BRETTGROESSE 8
int matchcount;
void ausgabe(int brett[8], int *optcount){
/**
* Main Function
* @return Returns Statuscode, 0 = OK, else = ERROR
*/
int main(void);
/**
* Meta Function, initializes environment.
*/
void dame_meta(void);
/**
* Places a "Dame" on gameboard
* @param brett current Position of "Damen" on board
* @param level Current Deepness
*/
void setze(int brett[BRETTGROESSE], int level);
/**
* Checks, whether current position is good or not
* @param brett current Position of "Damen" on board
* @param level Current deepness
* @param startlevel Maximum deepness
* @return
*/
int bedroht(int brett[BRETTGROESSE], int level, int startlevel);
/**
* Prints a valid result to commandline.
* @param brett current Position of "Damen" on board
*/
void ausgabe(int brett[BRETTGROESSE]);
void ausgabe(int brett[BRETTGROESSE]){
int i = 0, j = 0;
int max = 8;
printf("-----------------\n");
printf("Nr: %d\n", *optcount);
for(;i < max; ++i){
printf("Nr: %d\n", matchcount);
for(;i < BRETTGROESSE; ++i){
j = 0;
for(;j < max; ++j){
if(brett[i] == j){
printf("|D");
}else{
printf("| ");
}
for(;j < BRETTGROESSE; ++j){
printf("|%c", (brett[i] == j)?'D':' ');
}
printf("|\n");
}
}
int bedroht(int brett[8], int level, int maxlevel, int position){
int bedroht(int brett[BRETTGROESSE], int level, int startlevel){
--level;
int diff = maxlevel - level;
if(brett[level] == position){
int diff = startlevel - level;
if(brett[level] == brett[startlevel]){
return 1;
}else if(brett[level] == position-diff || brett[level] == position+diff){
}else if(brett[level] == brett[startlevel]-diff || brett[level] == brett[startlevel]+diff){
return 1;
}else{
if(level > 0){
return bedroht(brett,level,maxlevel, position);
return bedroht(brett,level,startlevel);
}else{
return 0;
}
}
}
void setze(int brett[8], int level, int *optcount){
void setze(int brett[BRETTGROESSE], int level){
++level;
int i = 0;
int max = 8;
for(;i<max;++i){
if(bedroht(brett,level,level, i) == 0){
brett[level] = i;
if(level == max-1){
++(*optcount);
ausgabe(brett, optcount);
for(;i<BRETTGROESSE;++i){
brett[level] = i;
if(bedroht(brett,level,level) == 0){
if(level == BRETTGROESSE-1){
++matchcount;
ausgabe(brett);
}else{
setze(brett,level, optcount);
setze(brett,level);
}
}
}
//return 0;
}
void dame_meta(){
int brett[8] = {-1};
void dame_meta(void){
matchcount = 0;
int brett[BRETTGROESSE];
int i = 0;
int max = 8;
int optcount = 0;
for(;i<max;++i){
for(;i<BRETTGROESSE;++i){
brett[0] = i;
setze(brett,0,&optcount);
setze(brett,0);
}
}
int main(void) {
dame_meta();
getchar();
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment