|
|
@@ -0,0 +1,107 @@
|
|
|
+#include <iostream>
|
|
|
+#include <cstdlib>
|
|
|
+#include <string>
|
|
|
+#include <windows.h>
|
|
|
+
|
|
|
+using namespace std;
|
|
|
+
|
|
|
+int spielzugpruefung(int staebe[3][4], int usereingaben[]){
|
|
|
+ int x;
|
|
|
+ int temp[2];
|
|
|
+ if (staebe[usereingaben[0]][0] == 0){
|
|
|
+ x = 0;
|
|
|
+ }
|
|
|
+ else if (staebe[usereingaben[1]][0] > 0){ //Der Stab der zweiten Usereingabe hat mindestens einen Ring
|
|
|
+ for (int y = 0; y < 2; y++){
|
|
|
+ x = 0;
|
|
|
+ while (staebe[usereingaben[y]][3 - x] < 1 && x < 3){ //Es wird zweimal von oben gezählt, wie viele ringfreie Stufen bei beiden Stäben der Usereingaben vorhanden sind
|
|
|
+ x++;
|
|
|
+ }
|
|
|
+ temp[y] = x;
|
|
|
+ }
|
|
|
+ if (staebe[usereingaben[0]][3 - temp[0]] < staebe[usereingaben[1]][3 - temp[1]]){ //Ist der Ring, der herauf gelegt wird, kleiner als der, der auf dem heraufzulegenden Stab ist
|
|
|
+ x = 1;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ x = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{ //Ansonsten ist der Tausch direkt möglich
|
|
|
+ x = 1;
|
|
|
+ }
|
|
|
+ return x;
|
|
|
+}
|
|
|
+
|
|
|
+void druck(int staebe[3][4])
|
|
|
+{
|
|
|
+ string labels[4] = {" || ", " <==> ", " <====> ", " <======>"};
|
|
|
+ system("cls");
|
|
|
+ for (int x = 3; x >= 0; x--){
|
|
|
+ for (int y = 0; y < 3; y++){
|
|
|
+ cout << labels[staebe[y][x]];
|
|
|
+ }
|
|
|
+ cout << endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+int main(){
|
|
|
+ int spielzuege = 0;
|
|
|
+ bool run;
|
|
|
+ int tausch[3];
|
|
|
+ int usereingaben[2];
|
|
|
+ int staebe[3][4];
|
|
|
+
|
|
|
+ for(int x = 0 ; x < 4; x++){
|
|
|
+ staebe[0][x] = 3-x;
|
|
|
+ }
|
|
|
+ for (int x = 1; x < 3; x++){
|
|
|
+ for (int y = 0; y < 4; y++){
|
|
|
+ staebe[x][y] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ do{
|
|
|
+ druck(staebe);
|
|
|
+ for (int x = 0; x < 2; x++){
|
|
|
+ run = true;
|
|
|
+ if (x){
|
|
|
+ cout << "Auf welchen Turm moechten Sie einen Stab legen?";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cout << "Von welchem Turm moechten Sie einen Stab entfernen?";
|
|
|
+ }
|
|
|
+ do{
|
|
|
+ cin >> usereingaben[x];
|
|
|
+ usereingaben[x]--; //Anpassung zum Index
|
|
|
+ if (usereingaben[x] < 3 && usereingaben[x] >= 0){ //Überprüfung des Zahlenbereichs
|
|
|
+ run = false;
|
|
|
+ cout << endl;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cout << "ERROR" << endl;
|
|
|
+ }
|
|
|
+ } while (run);
|
|
|
+ }
|
|
|
+ run = spielzugpruefung(staebe, usereingaben);
|
|
|
+ if (run){
|
|
|
+ spielzuege++;
|
|
|
+ for (int z = 0; z <= 1; z++){
|
|
|
+ tausch[2] = 1;
|
|
|
+ while (staebe[usereingaben[z]][3 - tausch[2]] < 1 && tausch[2] < 4){
|
|
|
+ tausch[2]++;
|
|
|
+ }
|
|
|
+ tausch[z] = tausch[2];
|
|
|
+ }
|
|
|
+ tausch[2] = staebe[usereingaben[0]][3 - tausch[0]]; //Tauschen der Ringe
|
|
|
+ staebe[usereingaben[0]][3 - tausch[0]] = 0;
|
|
|
+ staebe[usereingaben[1]][4 - tausch[1]] = tausch[2];
|
|
|
+ if (staebe[1][2] == 0 && staebe[2][2] == 0){ //Wenn der 2.te Index im Array der Stäbe 2 u. 3 leer ist, geht es weiter, ansonsten wäre das Rätsel gelöst
|
|
|
+ run = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cout << "ERROR.." << endl;
|
|
|
+ Sleep(1400);
|
|
|
+ }
|
|
|
+ }while (run == false);
|
|
|
+ druck(staebe);
|
|
|
+ cout << "Sie loesten das Raetsel in " << spielzuege << " Spielzuegen!" << endl;
|
|
|
+}
|