[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] Mau-Mau hinzugefügt



+ Mau-Mau spielen - leider geht Backspace nicht,
  aber was kann ich dafür, wenn fgets() nicht
  blockiert...
---
 src/modules/c/maumau/Makefile.all |    8 +
 src/modules/c/maumau/libmaumau.c  |  119 +++++
 src/modules/c/maumau/libmaumau.h  |  122 ++++++
 src/modules/c/maumau/maumau.c     |  861 +++++++++++++++++++++++++++++++++++++
 4 files changed, 1110 insertions(+), 0 deletions(-)
 create mode 100644 src/modules/c/maumau/Makefile.all
 create mode 100644 src/modules/c/maumau/libmaumau.c
 create mode 100644 src/modules/c/maumau/libmaumau.h
 create mode 100644 src/modules/c/maumau/maumau.c

diff --git a/src/modules/c/maumau/Makefile.all b/src/modules/c/maumau/Makefile.all
new file mode 100644
index 0000000..d38bbd3
--- /dev/null
+++ b/src/modules/c/maumau/Makefile.all
@@ -0,0 +1,8 @@
+shopt -s extglob
+source $LOST_BUILDMK_ROOT/config.sh
+
+echo "LD   $1/apps/maumau"
+$LOST_TOOLS_LD -omaumau -Ttext=0x40000000 *.o --start-group $2 --end-group
+
+
+$LOST_TOOLS_STRIP -s maumau -o $1/apps/maumau
diff --git a/src/modules/c/maumau/libmaumau.c b/src/modules/c/maumau/libmaumau.c
new file mode 100644
index 0000000..f07b0dd
--- /dev/null
+++ b/src/modules/c/maumau/libmaumau.c
@@ -0,0 +1,119 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Max Reitz                                       *
+ *   xanclic@xxxxxxxxxxxxxx                                                *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#define ISLIB
+
+#include "libmaumau.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef MYXOMYCOTA
+#include <myxomycota.h>
+#else
+#include <time.h>
+#endif
+
+maumau_t *newGame(player_count_t playerc, int correct_call)
+{
+  maumau_t *game;
+  
+  if ((playerc < 2) || (playerc > 5) || !correct_call)
+    return 0;
+  game = malloc(sizeof(maumau_t));
+  game->_players = playerc;
+  game->_stackSize = 0;
+  return game;
+}
+
+void startGame(maumau_t *game)
+{
+  int i, j, k;
+  
+  for (i = 0; i < 5; i++)
+    game->_player[i]._cards = 0;
+  k = 0;
+  for (i = MAUMAU_COLOUR_HEARTS; i <= MAUMAU_COLOUR_SPADES; i++)
+  {
+    for (j = MAUMAU_VALUE_7; j <= MAUMAU_VALUE_10; j++)
+    {
+      game->_stack[k]._single._colour = i;
+      game->_stack[k++]._single._value = j;
+      game->_stackSize++;
+    }
+    for (j = MAUMAU_VALUE_JACK; j <= MAUMAU_VALUE_ACE; j++)
+    {
+      game->_stack[k]._single._colour = i;
+      game->_stack[k++]._single._value = j;
+      game->_stackSize++;
+    }
+  }
+}
+
+void shuffle(card_t *stack)
+{
+  card_t tmpstack[NUM_ELEMENTS];
+  int i, j;
+  
+  #ifdef MYXOMYCOTA
+  srand(elapsedMilliseconds());
+  #else
+  srand(time(NULL));
+  #endif
+  memcpy(tmpstack, stack, sizeof(card_t)*NUM_ELEMENTS);
+  for (i = 0; i < NUM_ELEMENTS; i++)
+  {
+    while (!tmpstack[(j = rand()%NUM_ELEMENTS)]._single._value);
+    stack[i]._value = tmpstack[j]._value;
+    tmpstack[j]._single._value = 0;
+  }
+}
+
+void action(maumau_t *game, int number, ...)
+{
+  va_list pars;
+  int which_player, cardstodo;
+  
+  va_start(pars, number);
+  switch (number)
+  {
+    case (MAUMAU_ACTION_PLAYER):
+      which_player = va_arg(pars, int)-1;
+      switch (va_arg(pars, int))
+      {
+        case (MAUMAU_PLAYER_TAKE_CARDS):
+          for (cardstodo = va_arg(pars, int); (cardstodo > 0) && (game->_player[which_player]._cards < 16) && (game->_stackSize > 0); cardstodo--)
+          {
+            game->_player[which_player]._hand[(int)game->_player[which_player]._cards++]._value = game->_stack[(int)--game->_stackSize]._value;
+            game->_stack[(int)game->_stackSize]._value = 0;
+          }
+          break;
+      }
+      break;
+  }
+  va_end(pars);
+}
+
+void putCurrentCardUnderStack(maumau_t *game)
+{
+  memmove(&game->_stack[1], &game->_stack[0], sizeof(card_t)*(NUM_ELEMENTS-1));
+  game->_stack[0]._value = game->_currentCard._value;
+  game->_stackSize++;
+}
diff --git a/src/modules/c/maumau/libmaumau.h b/src/modules/c/maumau/libmaumau.h
new file mode 100644
index 0000000..7c30e4c
--- /dev/null
+++ b/src/modules/c/maumau/libmaumau.h
@@ -0,0 +1,122 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Max Reitz                                       *
+ *   xanclic@xxxxxxxxxxxxxx                                                *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef __LIBMAUMAU_H
+#define __LIBMAUMAU_H
+
+#define NUM_ELEMENTS 32
+
+#ifndef ISLIB
+
+const char *colour_name[4] = {
+  "Herz",
+  "Karo",
+  "Kreuz",
+  "Pik"
+};
+
+const char *value_name[11] = {
+  "<INV>",
+  "Bube",
+  "Dame",
+  "König",
+  "As",
+  "<INV>",
+  "<INV>",
+  "7",
+  "8",
+  "9",
+  "10"
+};
+
+const char value_char[11] = {
+  '?',
+  'B',
+  'D',
+  'K',
+  'A',
+  '?',
+  '?',
+  '7',
+  '8',
+  '9',
+  'X'
+};
+
+#endif
+
+#define MAUMAU_COLOUR_HEARTS   0 /* Herz  */
+#define MAUMAU_COLOUR_DIAMONDS 1 /* Karo  */
+#define MAUMAU_COLOUR_CLUBS    2 /* Kreuz */
+#define MAUMAU_COLOUR_SPADES   3 /* Pik   */
+
+#define MAUMAU_VALUE_7     7
+#define MAUMAU_VALUE_8     8
+#define MAUMAU_VALUE_9     9
+#define MAUMAU_VALUE_10   10
+#define MAUMAU_VALUE_JACK  1 /* Bube  */
+#define MAUMAU_VALUE_QUEEN 2 /* Dame  */
+#define MAUMAU_VALUE_KING  3 /* König */
+#define MAUMAU_VALUE_ACE   4 /* As   */
+
+#define MAUMAU_ACTION_PLAYER     0
+#define MAUMAU_PLAYER_TAKE_CARDS 0
+
+#define players ,1
+#define with (player_count_t)
+#define player MAUMAU_ACTION_PLAYER,
+#define takes ,MAUMAU_PLAYER_TAKE_CARDS,
+#define cards
+#define card
+
+typedef int player_count_t;
+
+typedef union
+{
+  struct
+  {
+    char _colour;
+    char _value;
+  } _single;
+  short _value;
+} card_t;
+
+typedef struct
+{
+  char _cards;
+  card_t _hand[32];
+} player_t;
+
+typedef struct
+{
+  int _players;
+  int _stackSize;
+  player_t _player[5];
+  card_t _stack[NUM_ELEMENTS];
+  card_t _currentCard;
+} maumau_t;
+
+void      action(maumau_t *game, int number, ...);
+maumau_t* newGame(player_count_t playerc, int correct_call);
+void      putCurrentCardUnderStack(maumau_t *game);
+void      shuffle(card_t *stack);
+void      startGame(maumau_t *game);
+
+#endif
diff --git a/src/modules/c/maumau/maumau.c b/src/modules/c/maumau/maumau.c
new file mode 100644
index 0000000..1885720
--- /dev/null
+++ b/src/modules/c/maumau/maumau.c
@@ -0,0 +1,861 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Max Reitz                                       *
+ *   xanclic@xxxxxxxxxxxxxx                                                *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+//define this if you are using Linux or another OS with full Unicode support
+//#define FULL_UNICODE
+
+//define this if you are using the (very strange) týndur standard C library
+#define TYNDUR
+
+#include "libmaumau.h"
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define SYMBOL_HEARTS   3
+#define SYMBOL_DIAMONDS 4
+#define SYMBOL_CLUBS    5
+#define SYMBOL_SPADES   6
+
+#define MUST_NOTHING 0x00
+#define MUST_TAKE    0x01
+#define MUST_WAIT    0x02
+
+
+int main(int argc, char *argv[])
+{
+  maumau_t *game;
+  FILE *graphic;
+  int i, _card = 0, playerMust[2] = {0, 0}, curcol, colcount[4], greatest, greatest_i, maybe, mau = 0, _take = 0, found, ignorePlayer1 = 0, c;
+  char inp[32], pafterclear[128];
+  #ifdef TYNDUR
+  int inpi, tinp;
+  #endif
+  
+  if (argc > 2)
+  {
+    fprintf(stderr, "Unbekannte Parameter.\n");
+    return EXIT_FAILURE;
+  }
+  if (argc == 2)
+  {
+    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "--help"))
+    {
+      printf("Ein einfaches Textbasiertes Mau-Mau.\n");
+      printf("REGELN:\n");
+      printf("  Zunächst gelten die Standardregeln von Mau-Mau. Achtung: Wer eine Karte\n");
+      printf("  ziehen muss, weil er keine legen kann/will, der muss für diese Runde aus-\n");
+      printf("  setzen.\n");
+      printf("SONDERREGELN:\n");
+      printf("  Ein Bube darf auf jede andere Karte gelegt werden (auch auf andere Buben).\n");
+      printf("  Der ihn ausspielende Spieler darf nach dem Legen die nächste auszuspielende\n");
+      printf("  Farbe wählen.\n");
+      printf("  Wird eine 7 gelegt, so muss der andere Spieler zwei Karten ziehen, bevor er\n");
+      printf("  seinen Zug ausführt, es sei denn, er kann mit einer 7 oder 10 antworten.\n");
+      printf("  Wird eine 10 gelegt, so muss der andere Spieler eine Karte ziehen, bevor er\n");
+      printf("  seinen Zug ausführt, es sei denn, er kann mit einer 7 oder 10 antworten.\n");
+      printf("  \"Antworten\" heißt, auf eine \"Ziehkarte\" (7 oder 10) sofort eine andere\n");
+      printf("  (beliebige) Ziehkarte zu legen und so die Anzahl der zu ziehenden Karten zu\n");
+      printf("  erhöhen und die Bürde des Ziehens wieder dem anderen Spieler zu übertragen.\n");
+      printf("  Ein As lässt den gegnerischen Spieler eine Runde aussetzen.\n");
+      printf("\n");
+      printf("Die genauen Regeln sollten Sie unter /mnt/fda/home/Mau-Mau-Regeln.txt finden.\n");
+      return EXIT_SUCCESS;
+    }
+    else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
+    {
+      printf("MyxMauMau (MyX games) 0.5\nWritten by Max Reitz\n\n");
+      printf("Using libmaumau 0.3\nWritten by Max Reitz with support from irc.euirc.net#tyndur\n");
+      return EXIT_SUCCESS;
+    }
+    else
+    {
+      fprintf(stderr, "Unbekannter Parameter.\n");
+      return EXIT_FAILURE;
+    }
+  }
+  
+  if ((graphic = fopen("/dev/c437console", "r")))
+    freopen("/dev/c437console", "a", graphic);
+  
+  game = newGame(with 2 players);
+  startGame(game);
+  shuffle(game->_stack);
+  action(game, player 1 takes 6 cards);
+  action(game, player 2 takes 6 cards);
+  game->_currentCard._value = game->_stack[--game->_stackSize]._value;
+  curcol = game->_currentCard._single._colour;
+  
+  pafterclear[0] = 0;
+  
+  for (;;)
+  {
+    printf("\33[2J");
+    
+    if (mau)
+    {
+      if (mau == 0x01)
+        printf("Sie: \"");
+      else if (mau == 0x02)
+        printf("Gegner: \"");
+      else
+        printf("Sie und Ihr Gegner: \"");
+      
+      printf("Mau!\"\n\n");
+      mau = 0;
+    }
+    
+    printf("Aktuelle Farbe: ");
+    switch (curcol)
+    {
+      case (MAUMAU_COLOUR_HEARTS):   printf("\33[31m");
+                                     if (graphic) fputc(SYMBOL_HEARTS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('H');
+                                       #else
+                                       printf("\u2665");
+                                       #endif
+                                     break;
+      case (MAUMAU_COLOUR_DIAMONDS): printf("\33[31m");
+                                     if (graphic) fputc(SYMBOL_DIAMONDS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('C');
+                                       #else
+                                       printf("\u2666");
+                                       #endif
+                                     break;                               
+      case (MAUMAU_COLOUR_CLUBS):    printf("\33[30;1m");
+                                     if (graphic) fputc(SYMBOL_CLUBS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('K');
+                                       #else
+                                       printf("\u2663");
+                                       #endif
+                                     break;
+      case (MAUMAU_COLOUR_SPADES):   printf("\33[30;1m");
+                                     if (graphic) fputc(SYMBOL_SPADES, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('P');
+                                       #else
+                                       printf("\u2660");
+                                       #endif
+                                     break;
+    }
+    printf("\33[0m\n\n");
+    
+    //BEGINN "KARTEN DES GEGNERS"
+    for (i = 0; i < game->_player[1]._cards; i++)
+    {
+      if (graphic)
+      {
+        if (!i)
+          fprintf(graphic, "\xDA\xC4\xC4\xC4");
+        else
+          fprintf(graphic, "\xC2\xC4\xC4\xC4");
+      }
+      else
+        printf("+---");
+    }
+    if (graphic)
+      fprintf(graphic, "\xBF\n");
+    else
+      printf("+\n");
+    
+    for (i = 0; i < game->_player[1]._cards; i++)
+    {
+      if (graphic)
+        fprintf(graphic, "\xB3\33[34m\xB0\xB0\xB0\33[0m");
+      else
+        printf("|\33[34m###\33[0m");
+    }
+    if (graphic)
+      fputc('\xB3', graphic);
+    else
+      putchar('|');
+    putchar('\n');
+    for (i = 0; i < game->_player[1]._cards; i++)
+    {
+      if (graphic)
+        fprintf(graphic, "\xB3\33[34m\xB0\xB0\xB0\33[0m");
+      else
+        printf("|\33[34m###\33[0m");
+    }
+    if (graphic)
+      fprintf(graphic, "\xB3\n");
+    else
+      printf("|\n");
+    
+    for (i = 0; i < game->_player[1]._cards; i++)
+    {
+      if (graphic)
+      {
+        if (!i)
+          fprintf(graphic, "\xC0\xC4\xC4\xC4");
+        else
+          fprintf(graphic, "\xC1\xC4\xC4\xC4");
+      }
+      else
+      {
+        printf("+---");
+      }
+    }
+    if (graphic)
+      fprintf(graphic, "\xD9\n");
+    else
+      printf("+\n");
+    //ENDE "KARTEN DES GEGNERS"
+    
+    //BEGINN "STAPEL"
+    if (graphic)
+      fprintf(graphic, "\xC9\xCD\xCD\xCD\xBB \xC9\xCD\xCD\xCD\xBB\n\xBA ");
+    else
+      printf("+===+ +===+\n| ");
+    switch (game->_currentCard._single._colour)
+    {
+      case (MAUMAU_COLOUR_HEARTS):   printf("\33[31m");
+                                     if (graphic) fputc(SYMBOL_HEARTS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('H');
+                                       #else
+                                       printf("\u2665");
+                                       #endif
+                                     break;
+      case (MAUMAU_COLOUR_DIAMONDS): printf("\33[31m");
+                                     if (graphic) fputc(SYMBOL_DIAMONDS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('C');
+                                       #else
+                                       printf("\u2666");
+                                       #endif
+                                     break;                               
+      case (MAUMAU_COLOUR_CLUBS):    printf("\33[30;1m");
+                                     if (graphic) fputc(SYMBOL_CLUBS, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('K');
+                                       #else
+                                       printf("\u2663");
+                                       #endif
+                                     break;
+      case (MAUMAU_COLOUR_SPADES):   printf("\33[30;1m");
+                                     if (graphic) fputc(SYMBOL_SPADES, graphic);
+                                     else
+                                       #ifndef FULL_UNICODE
+                                       putchar('P');
+                                       #else
+                                       printf("\u2660");
+                                       #endif
+                                     break;
+    }
+    printf("\33[0m ");
+    if (graphic)
+      fprintf(graphic, "\xBA \xBA\33[34m\xB0\xB0\xB0\33[0m\xBA\n\xBA");
+    else
+      printf("| |\33[34m###\33[0m|\n|");
+    printf(" %c ", value_char[(int)game->_currentCard._single._value]);
+    if (graphic)
+    {
+      fprintf(graphic, "\xBA \xBA\33[34m\xB0\xB0\xB0\33[0m\xBA\n");
+      fprintf(graphic, "\xC8\xCD\xCD\xCD\xBC \xC8\xCD\xCD\xCD\xBC\n");
+    }
+    else
+    {
+      printf("| |\33[34m###\33[0m|\n");
+      printf("+===+ +===+\n");
+    }
+    //ENDE "STAPEL"
+    
+    //BEGINN "EIGENE KARTEN"
+    for (i = 0; i < game->_player[0]._cards; i++)
+    {
+      if (graphic)
+      {
+        if (!i)
+          fprintf(graphic, "\xDA\xC4\xC4\xC4");
+        else
+          fprintf(graphic, "\xC2\xC4\xC4\xC4");
+      }
+      else
+        printf("+---");
+    }
+    if (graphic)
+      fprintf(graphic, "\xBF\n");
+    else
+      printf("+\n");
+    
+    for (i = 0; i < game->_player[0]._cards; i++)
+    {
+      if (graphic)
+        fprintf(graphic, "\xB3 ");
+      else
+        printf("| ");
+      switch (game->_player[0]._hand[i]._single._colour)
+      {
+        case (MAUMAU_COLOUR_HEARTS):
+          printf("\33[31m");
+          if (graphic)
+            fputc(SYMBOL_HEARTS, graphic);
+          else
+            #ifndef FULL_UNICODE
+            putchar('H');
+            #else
+            printf("\u2665");
+            #endif
+          break;
+        case (MAUMAU_COLOUR_DIAMONDS):
+          printf("\33[31m");
+          if (graphic)
+            fputc(SYMBOL_DIAMONDS, graphic);
+          else
+            #ifndef FULL_UNICODE
+            putchar('C');
+            #else
+            printf("\u2666");
+            #endif
+          break;
+        case (MAUMAU_COLOUR_CLUBS):
+          printf("\33[30;1m");
+          if (graphic)
+            fputc(SYMBOL_CLUBS, graphic);
+          else
+            #ifndef FULL_UNICODE
+            putchar('K');
+            #else
+            printf("\u2663");
+            #endif
+          break;
+        case (MAUMAU_COLOUR_SPADES):
+          printf("\33[30;1m");
+          if (graphic)
+            fputc(SYMBOL_SPADES, graphic);
+          else
+            #ifndef FULL_UNICODE
+            putchar('P');
+            #else
+            printf("\u2660");
+            #endif
+          break;
+      }
+      printf("\33[0m ");
+    }
+    if (graphic)
+      fputc('\xB3', graphic);
+    else
+      putchar('|');
+    putchar('\n');
+    for (i = 0; i < game->_player[0]._cards; i++)
+    {
+      if (graphic)
+        fprintf(graphic, "\xB3 ");
+      else
+        printf("| ");
+      printf("%c ", value_char[(int)game->_player[0]._hand[i]._single._value]);
+    }
+    if (graphic)
+      fprintf(graphic, "\xB3\n");
+    else
+      printf("|\n");
+    
+    for (i = 0; i < game->_player[0]._cards; i++)
+    {
+      if (graphic)
+      {
+        if (!i)
+          fprintf(graphic, "\xC0\xC4\xC4\xC4");
+        else
+          fprintf(graphic, "\xC1\xC4\xC4\xC4");
+      }
+      else
+      {
+        printf("+---");
+      }
+    }
+    if (graphic)
+      fprintf(graphic, "\xD9\n");
+    else
+      printf("+\n");
+    //ENDE "EIGENE KARTEN"
+    
+    //BEGINN "EIGENE KARTENNUMMERN"
+    i = 0;
+    while (i < game->_player[0]._cards)
+      printf("%3i ", ++i);
+    putchar('\n');
+    //ENDE "EIGENE KARTENNUMMERN"
+    
+    //BEGINN "SPIELER LEGT"
+    if (ignorePlayer1)
+    {
+      ignorePlayer1 = 0;
+      goto Player2sTurn;
+    }
+    if (playerMust[0] & MUST_TAKE)
+    {
+      playerMust[0] &= ~MUST_TAKE;
+      for (i = 0, found = 0; i < game->_player[0]._cards; i++)
+      {
+        if ((game->_player[0]._hand[i]._single._value == MAUMAU_VALUE_7) || (game->_player[0]._hand[i]._single._value == MAUMAU_VALUE_10))
+        {
+          found = 1;
+          break;
+        }
+      }
+      if (found)
+      {
+        printf("\nSie müssten jetzt %i %s ziehen, können dies aber auch abwehren.\n", _take, (_take == 1) ? "Karte" : "Karten");
+        printf("Möchten Sie eine 7 oder 10 legen? ");
+        #ifdef MYXOMYCOTA
+        printf("[j/n] ");
+        fflush(stdout);
+        c = 0;
+        while ((c != 'j') && (c != 'n'))
+          c = tolower(getchar());
+        printf("\n");
+        #else
+        do
+        {
+          printf("[j/n] ");
+          fflush(stdout);
+          clearerr(stdin);
+          #ifdef TYNDUR
+          *inp = 0;
+          while ((tinp = getchar()) == EOF);
+          if (feof(stdin) || ferror(stdin) || (tinp == '\n'))
+          {
+            putchar('\n');
+            clearerr(stdin);
+          }
+          else
+          {
+            putchar(tinp);
+            fflush(stdout);
+            *inp = tolower(tinp);
+          }
+          if (!*inp)
+            continue;
+          #else
+          fgets(inp, 31, stdin);
+          if (!*inp)
+            continue;
+          inp[strlen(inp)-1] = 0;
+          #endif
+        } while ((strlen(inp) != 1) || ((tolower(*inp) != 'j') && (tolower(*inp) != 'n')));
+        c = tolower(*inp);
+        #endif
+        if (c == 'n')
+          found = 0;
+        else
+        {
+          printf("\nWelche Karte möchten Sie legen?\n");
+          for (;;)
+          {
+            printf("> ");
+            fflush(stdout);
+            clearerr(stdin);
+            #ifdef TYNDUR
+            memset(inp, 0, 32);
+            for (inpi = 0; inpi < 32; inpi++)
+            {
+              while ((tinp = getchar()) == EOF);
+              if (feof(stdin) || ferror(stdin) || (tinp == '\n'))
+              {
+                putchar('\n');
+                clearerr(stdin);
+                break;
+              }
+              putchar(tinp);
+              fflush(stdout);
+              inp[inpi] = tolower(tinp);
+            }
+            if (!*inp)
+              continue;
+            #else
+            fgets(inp, 31, stdin);
+            if (!*inp)
+              continue;
+            inp[strlen(inp)-1] = 0;
+            for (i = 0; i < strlen(inp); i++)
+              inp[i] = tolower(inp[i]);
+            #endif
+            if (!strcmp(inp, "keine"))
+            {
+              _card = 0;
+              break;
+            }
+            _card = atoi(inp);
+            if ((_card < 1) || (_card > game->_player[0]._cards))
+            {
+              printf("Diese Karte haben Sie leider nicht.\n");
+              continue;
+            }
+            else if ((game->_player[0]._hand[_card-1]._single._value != MAUMAU_VALUE_7 ) &&
+                     (game->_player[0]._hand[_card-1]._single._value != MAUMAU_VALUE_10))
+            {
+              printf("Diese Karte können Sie leider nicht ablegen (nur 7 oder 10).\n");
+              continue;
+            }
+            break;
+          }
+          if (!_card)
+            found = 0;
+          else
+          {
+            putCurrentCardUnderStack(game);
+            game->_currentCard._value = game->_player[0]._hand[_card-1]._value;
+            if (_card < game->_player[0]._cards)
+              memmove(&game->_player[0]._hand[_card-1], &game->_player[0]._hand[_card], sizeof(card_t)*(game->_player[0]._cards-_card));
+            game->_player[0]._cards--;
+        
+            curcol = game->_currentCard._single._colour;
+            switch (game->_currentCard._single._value)
+            {
+              case (MAUMAU_VALUE_7):
+                playerMust[1] |= MUST_TAKE;
+                _take += 2;
+                break;
+              case (MAUMAU_VALUE_10):
+                playerMust[1] |= MUST_TAKE;
+                _take++;
+                break;
+            }
+            if (game->_player[0]._cards == 1)
+              mau |= 0x01;
+            else if (!game->_player[0]._cards)
+            {
+              printf("\33[32;1mMAU MAU!\33[0m\n\nHerzlichen Glückwunsch! Sie haben das Spiel gewonnen!\n");
+              break;
+            }
+          }
+        }
+        ignorePlayer1 = 1;
+      }
+      if (!found)
+      {
+        sprintf(pafterclear, "\nSie müssen %i %s ziehen.\n", _take, (_take == 1) ? "Karte" : "Karten");
+        action(game, player 1 takes _take cards);
+        _take = 0;
+        ignorePlayer1 = 0;
+      }
+      continue; //Alles neu zeichnen
+    }
+    if (*pafterclear)
+    {
+      printf(pafterclear);
+      *pafterclear = 0;
+    }
+    if (playerMust[0] & MUST_WAIT)
+    {
+      playerMust[0] &= ~MUST_WAIT;
+      printf("\nSie müssen aussetzen. Drücken Sie die Eingabetaste.\n");
+      while (getchar() != '\n');
+    }
+    else
+    {
+      printf("\nWelche Karte möchten Sie legen?\n");
+      for (;;)
+      {
+        printf("> ");
+        fflush(stdout);
+        clearerr(stdin);
+        #ifdef TYNDUR
+        memset(inp, 0, 32);
+        for (inpi = 0; inpi < 32; inpi++)
+        {
+          while ((tinp = getchar()) == EOF);
+          if (feof(stdin) || ferror(stdin) || (tinp == '\n'))
+          {
+            putchar('\n');
+            clearerr(stdin);
+            break;
+          }
+          putchar(tinp);
+          fflush(stdout);
+          inp[inpi] = tolower(tinp);
+        }
+        if (!*inp)
+          continue;
+        #else
+        fgets(inp, 31, stdin);
+        if (!*inp)
+          continue;
+        inp[strlen(inp)-1] = 0;
+        for (i = 0; i < strlen(inp); i++)
+          inp[i] = tolower(inp[i]);
+        #endif
+        if (!strcmp(inp, "keine"))
+        {
+          _card = 0;
+          break;
+        }
+        else if (!strcmp(inp, "quit"))
+        {
+          _card = -1;
+          break;
+        }
+        _card = atoi(inp);
+        if ((_card < 1) || (_card > game->_player[0]._cards))
+        {
+          printf("Diese Karte haben Sie nicht.\n");
+          continue;
+        }
+        else if (game->_player[0]._hand[_card-1]._single._value == MAUMAU_VALUE_JACK)
+          break;
+        else if ((game->_player[0]._hand[_card-1]._single._value  != game->_currentCard._single._value) &&
+                 (game->_player[0]._hand[_card-1]._single._colour != curcol                           ))
+        {
+          printf("Diese Karte können Sie leider nicht ablegen.\n");
+          continue;
+        }
+        break;
+      }
+      
+      if (_card == -1)
+        break;
+      
+      if (!_card)
+        action(game, player 1 takes 1 card);
+      else
+      {
+        putCurrentCardUnderStack(game);
+        game->_currentCard._value = game->_player[0]._hand[_card-1]._value;
+        if (_card < game->_player[0]._cards)
+          memmove(&game->_player[0]._hand[_card-1], &game->_player[0]._hand[_card], sizeof(card_t)*(game->_player[0]._cards-_card));
+        game->_player[0]._cards--;
+        
+        if (game->_currentCard._single._value != MAUMAU_VALUE_JACK)
+        {
+          curcol = game->_currentCard._single._colour;
+          switch (game->_currentCard._single._value)
+          {
+            case (MAUMAU_VALUE_ACE):
+              playerMust[1] |= MUST_WAIT;
+              break;
+            case (MAUMAU_VALUE_7):
+              playerMust[1] |= MUST_TAKE;
+              _take += 2;
+              break;
+            case (MAUMAU_VALUE_10):
+              playerMust[1] |= MUST_TAKE;
+              _take++;
+              break;
+          }
+        }
+        else if (game->_player[0]._cards)
+        {
+          printf("Da Sie einen Buben gelegt haben, dürfen Sie jetzt eine Farbe wählen.\n");
+          for (;;)
+          {
+            printf("Möchten Sie Kreuz (K), Pik (P), Herz (H) oder Karo (C)? ");
+            fflush(stdout);
+            clearerr(stdin);
+            #ifdef TYNDUR
+            *inp = 0;
+            while ((tinp = getchar()) == EOF);
+            if (feof(stdin) || ferror(stdin) || (tinp == '\n'))
+            {
+              putchar('\n');
+              clearerr(stdin);
+            }
+            else
+            {
+              putchar(tinp);
+              fflush(stdout);
+              *inp = toupper(tinp);
+              putchar('\n');
+            }
+            if (!*inp)
+              continue;
+            #else
+            fgets(inp, 31, stdin);
+            if (!*inp)
+              continue;
+            inp[strlen(inp)-1] = 0;
+            if (strlen(inp) != 1)
+              continue;
+            *inp = toupper(*inp);
+            #endif
+            if ((*inp == 'K') || (*inp == 'P') || (*inp == 'H') || (*inp == 'C'))
+              break;
+          }
+          switch (*inp)
+          {
+            case ('K'):
+              curcol = MAUMAU_COLOUR_CLUBS;
+              break;
+            case ('P'):
+              curcol = MAUMAU_COLOUR_SPADES;
+              break;
+            case ('H'):
+              curcol = MAUMAU_COLOUR_HEARTS;
+              break;
+            case ('C'):
+              curcol = MAUMAU_COLOUR_DIAMONDS;
+              break;
+          }
+        }
+      }
+      
+      if (game->_player[0]._cards == 1)
+        mau |= 0x01;
+      else if (!game->_player[0]._cards)
+      {
+        printf("\33[32;1mMAU MAU!\33[0m\n\nHerzlichen Glückwunsch! Sie haben das Spiel gewonnen!\n");
+        break;
+      }
+    }
+    //ENDE "SPIELER LEGT"
+    
+    Player2sTurn:
+    
+    //BEGINN "GEGNER LEGT"
+    if (playerMust[1] & MUST_TAKE)
+    {
+      playerMust[1] &= ~MUST_TAKE;
+      for (i = 0, found = 0; i < game->_player[0]._cards; i++)
+      {
+        if ((game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_7) || (game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_10))
+        {
+          found = i+1;
+          break;
+        }
+      }
+      if (found)
+      {
+        putCurrentCardUnderStack(game);
+        game->_currentCard._value = game->_player[1]._hand[found-1]._value;
+        if (_card < game->_player[1]._cards)
+          memmove(&game->_player[1]._hand[found-1], &game->_player[1]._hand[found], sizeof(card_t)*(game->_player[1]._cards-found));
+        game->_player[1]._cards--;
+        
+        curcol = game->_currentCard._single._colour;
+        switch (game->_currentCard._single._value)
+        {
+          case (MAUMAU_VALUE_7):
+            playerMust[0] |= MUST_TAKE;
+            _take += 2;
+            break;
+          case (MAUMAU_VALUE_10):
+            playerMust[0] |= MUST_TAKE;
+            _take++;
+            break;
+        }
+        if (game->_player[1]._cards == 1)
+          mau |= 0x02;
+        else if (!game->_player[1]._cards)
+        {
+          printf("\33[31;1mMAU MAU!\33[0m\n\nLeider haben Sie verloren!\n");
+          break;
+        }
+        continue;
+      }
+      else
+      {
+        action(game, player 2 takes _take cards);
+        _take = 0;
+        ignorePlayer1 = 1;
+        continue;
+      }
+    }
+    if (playerMust[1] & MUST_WAIT)
+      playerMust[1] &= ~MUST_WAIT;
+    else
+    {
+      for (i = 0, _card = 0, maybe = 0; i < game->_player[1]._cards; i++)
+      {
+        if (game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_JACK)
+          maybe = i+1;
+        else if ((game->_player[1]._hand[i]._single._value  == game->_currentCard._single._value) ||
+            (game->_player[1]._hand[i]._single._colour == curcol                           ))
+        {
+          _card = i+1;
+          break;
+        }
+      }
+      
+      if (!_card && maybe)
+        _card = maybe;
+      
+      if (!_card)
+        action(game, player 2 takes 1 card);
+      else
+      {
+        putCurrentCardUnderStack(game);
+        game->_currentCard._value = game->_player[1]._hand[_card-1]._value;
+        if (_card < game->_player[1]._cards)
+          memmove(&game->_player[1]._hand[_card-1], &game->_player[1]._hand[_card], sizeof(card_t)*(game->_player[1]._cards-_card));
+        game->_player[1]._cards--;
+        
+        if (game->_currentCard._single._value != MAUMAU_VALUE_JACK)
+        {
+          curcol = game->_currentCard._single._colour;
+          switch (game->_currentCard._single._value)
+          {
+            case (MAUMAU_VALUE_ACE):
+              playerMust[0] |= MUST_WAIT;
+              break;
+            case (MAUMAU_VALUE_7):
+              playerMust[0] |= MUST_TAKE;
+              _take += 2;
+              break;
+            case (MAUMAU_VALUE_10):
+              playerMust[0] |= MUST_TAKE;
+              _take++;
+              break;
+          }
+        }
+        else if (game->_player[1]._cards)
+        {
+          memset(colcount, 0, 4*sizeof(int));
+          for (i = 0; i < game->_player[1]._cards; i++)
+            colcount[(int)game->_player[1]._hand[i]._single._colour]++;
+          greatest = 0;
+          for (i = 0, greatest_i = 0; i < 4; i++)
+          {
+            if (colcount[i] > greatest)
+            {
+              greatest = colcount[i];
+              greatest_i = i;
+            }
+          }
+          curcol = greatest_i;
+        }
+      }
+      
+      if (game->_player[1]._cards == 1)
+        mau |= 0x02;
+      else if (!game->_player[1]._cards)
+      {
+        printf("\33[31;1mMAU MAU!\33[0m\n\nLeider haben Sie verloren!\n");
+        break;
+      }
+    }
+    //ENDE "GEGNER LEGT"
+  }
+  
+  free(game);
+  return EXIT_SUCCESS;
+}
-- 
1.6.0.2