
(********************************************************************)
(*                                                                  *)
(*  pairs.sd7     Concentration game                                *)
(*  Copyright (C) 2005  Thomas Mertes                               *)
(*                                                                  *)
(*  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., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


$ include "seed7_05.s7i";
  include "float.s7i";
  include "text.s7i";
  include "draw.s7i";
  include "graph_file.s7i";
  include "keybd.s7i";
  include "time.s7i";
  include "duration.s7i";
  include "pic32.s7i";


var text: screen is STD_NULL;

const integer: UPPER_BORDER is 12 + 128 + 12;
const integer: LEFT_BORDER is 8;
const integer: CARD_SIZE is 64;
const integer: CARD_BORDER is 4;
const integer: FIELD_STEP is CARD_SIZE + 2 * CARD_BORDER;
const integer: FIELD_LINES is 6;
const integer: FIELD_COLUMNS is 8;
const integer: OPPONENT_XPOS is 99;
const integer: COMPUTER_HIT_YPOS is 8;

var PRIMITIVE_WINDOW: opponent is PRIMITIVE_WINDOW.value;
var array PRIMITIVE_WINDOW: digit_pixmap is 0 times PRIMITIVE_WINDOW.value;

const type: cardType is new struct
    var array string: picture is 0 times "";
    var PRIMITIVE_WINDOW: pixmap is PRIMITIVE_WINDOW.value;
    var integer: number is 0;
  end struct;

const type: visibleType is new enum
    backSide, frontSide, removed
  end enum;

const type: fieldType is new struct
    var integer: cardNumber is 0;
    var visibleType: visible is backSide;
    var boolean: visited is FALSE;
  end struct;

const type: gameObj is new struct
    var integer: currLevel is 2;
    var integer: playerHits is 0;
    var integer: computerHits is 0;
    var integer: player_hit_ypos is 0;
    var boolean: quit is FALSE;
  end struct;

var gameObj: game is gameObj.value;


const array string: size_2_5 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "           XX    XXXXX          ",
  "            X    X   X          ",
  "            X    X   X          ",
  "            X    X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_3_4 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "           XX    XXXXX          ",
  "            X        X          ",
  "            X    XXXXX          ",
  "            X    X              ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_4_4 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X XXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "           XX    XXXX           ",
  "            X    X              ",
  "            X    XXXXX          ",
  "            X    X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_4_5 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X XXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  XXXXX          ",
  "              X  X   X          ",
  "          XXXXX  X   X          ",
  "          X      X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_4_6 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  X              ",
  "              X  X X            ",
  "          XXXXX  XXXXX          ",
  "          X        X            ",
  "          XXXXX    X            ",
  "                                ");


const array string: size_5_6 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  XXXXX          ",
  "              X  X   X          ",
  "          XXXXX  X   X          ",
  "              X  X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_6_6 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X XXXXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  XXXX           ",
  "              X  X              ",
  "          XXXXX  XXXXX          ",
  "              X  X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_6_7 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X XXXXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          X      XXXXX          ",
  "          X X        X          ",
  "          XXXXX  XXXXX          ",
  "            X    X              ",
  "            X    XXXXX          ",
  "                                ");


const array string: size_6_8 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X XXXXXXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          X      XXXXX          ",
  "          X X    X   X          ",
  "          XXXXX  XXXXX          ",
  "            X    X   X          ",
  "            X    XXXXX          ",
  "                                ");


const array string: size_6_10 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X XXXXXXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXX   XXXXX          ",
  "          X      X   X          ",
  "          XXXXX  X   X          ",
  "          X   X  X   X          ",
  "          XXXXX  XXXXX          ",
  "                                ");


const array string: size_6_12 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X XXXXXX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  XXXXX          ",
  "              X      X          ",
  "             X   XXXXX          ",
  "            X    X              ",
  "            X    XXXXX          ",
  "                                ");


const array string: size_6_14 is [](
  "           YYYYY                ",
  "          YYYYYYY               ",
  "          YYBXBYY               ",
  "          YYXOXYY               ",
  "            XXX                 ",
  "          OOOOOOO               ",
  "         OOOOOOOOO              ",
  "        XO OOMOO OX             ",
  "       XX  MMMMM  XX            ",
  "       bXXXbbbbbXXXb            ",
  "       bbbXXbbbXXbbb            ",
  "                                ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  " X X X X X X X X X X X X X X XX ",
  " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
  "                                ",
  "          XXXXX  X              ",
  "          X   X  X X            ",
  "          XXXXX  XXXXX          ",
  "          X   X    X            ",
  "          XXXXX    X            ",
  "                                ");


const array string: panic_monster1_pic is [](
  "                ",
  "                ",
  "                ",
  " B           B  ",
  " B           B  ",
  " BBBBB   BBBBB  ",
  "      OOO       ",
  "    OOOOOOO     ",
  "  O      B  O   ",
  "  O      B  O   ",
  "  O         O   ",
  "  OOOOOOOOOOO   ",
  "    O     O     ",
  "                ",
  "                ",
  "                ");


const array string: panic_monster2_pic is [](
  "                ",
  "                ",
  "                ",
  "   G       G    ",
  "   G       G    ",
  " GGGGG   GGGGG  ",
  " GGGGG   GGGGG  ",
  " G  M  G  M  G  ",
  " G     G     G  ",
  " GGGGGGGGGGGGG  ",
  "   GGGGGGGGG    ",
  "   OOO   OOO    ",
  " OOO       OOO  ",
  "                ",
  "                ",
  "                ");


const array string: panic_monster3_pic is [](
  "                ",
  "                ",
  "                ",
  "   B       B    ",
  "   BBB   BBB    ",
  " BBBBB   BBBBB  ",
  " BBBBB   BBBBB  ",
  "   B  OOO  B    ",
  "   B  OOO  B    ",
  "   BBB   BBB    ",
  "   B   B   B    ",
  "     BBBBB      ",
  "     B   B      ",
  "                ",
  "                ",
  "                ");


const array string: dig_right_pic is [](
  "  XXXXX         ",
  "  XX XXX        ",
  "  XXXXX         ",
  "   XXX          ",
  "    X           ",
  "  XXXXXX        ",
  "  XXXX XX       ",
  "   XXXX XX      ",
  "   XXXXXXX      ",
  "   XXX  XX      ",
  "  XX XX  XX     ",
  "  XX XX   XX    ",
  "  XX XX    XXX  ",
  "  XX XX    XXX  ",
  "  XX XX     XX  ",
  " XXX XXX     X  ");


const array string: small_bush_pic is [](
  "     G GG       ",
  "   G  GG  GG  G ",
  " G  G  G G   G  ",
  "  GGGG GG G GGG ",
  "      GG  GGG   ",
  " GGG   G G   GG ",
  "   GGG GG GG GGG",
  " G  G GG  G G   ",
  " G  GG G  GG G G",
  "GG GG Gg  g  GG ",
  " G  g  g g   G  ",
  "GGG  g ggGG GGGG",
  "   g  gg   g    ",
  "    g  g  gGG   ",
  "     g g g      ",
  "      ggg       ");


const array string: big_bush_pic is [](
  "     G G  GG  G  G   G G        ",
  "      GG   G  G G    GGGGG      ",
  "       G    G GG    gg G   G  G ",
  "    GGGGG    GGG G gg  G   G GG ",
  " G     Ggg G  gg Ggg   G   gg   ",
  " GG   G  ggG  gg gg   gG  ggGG  ",
  "   G      gg  ggggG  gg  gg     ",
  " G  GGGGggggg ggg   gg  ggggGGGG",
  "  G  G      bbbb    bbggg       ",
  "GGGG   G  G  bbb   bbgg G    GG ",
  "   gg   GG G  bb  bb  G   G  G  ",
  " GGGgg   G  ggbb bb G   G GggGGG",
  "     gg  gG  gbbbb  G gg  gg    ",
  "  G   gg g bb bbb   ggg  ggggGG ",
  " GGG   gbg  bbbb  G gg  gg G    ",
  "    G   bg   bbb G  g  gg   G   ",
  "  G  G   gb   bbbb  bbbb  G    G",
  "   g  g  gbb  bbb   bbbg  G  GG ",
  "GGGgggggbb bb bb  G bb    gg G  ",
  "       bbb  bbbb  GbbggGG ggg   ",
  "  G  GGGbb  Gbbb  bb      ggGGG ",
  "   G     bb   bb bbggGG  gg     ",
  "    gg G  bb  bbbb      ggggGGGG",
  " GGggggG GGbb bbb      gggg     ",
  "   G  gg    bbbb   G  bb  GGGG  ",
  "  G    ggG   bbb  G  bb    G    ",
  "     G  gg  G bbgg  bb          ",
  "  GGgggggbb  Gbbg  bbbggggGGGG  ",
  "    G     bb  bb  bb   G        ",
  "       GGGGbb bb bb     G       ",
  "            bbbbbbGGGG          ",
  "             bbbb               ");


const array string: chain_pic is [](
  "     BBB   BBB  ",
  "    B   B B   B ",
  "    B  BBBBB  B ",
  "    BB  B B   B ",
  "    BBBB   BBB  ",
  "   BB           ",
  " BBB            ",
  "B B B           ",
  "B   B           ",
  "B B B           ",
  " BBB            ",
  "   BBBBB   BBB  ",
  "    BB  B B   B ",
  "    B  BBBBB  B ",
  "    B   B B   B ",
  "     BBB   BBB  ");


const array string: vampire_pic is [](
  "      bbbb      ",
  "     bbbbbb     ",
  "     bBxxBb     ",
  "XX   xxxxxx   XX",
  "Xx   xXXXXx   xX",
  " xx   XxxX   xx ",
  "  xxggggggggxx  ",
  "  bxggggggggxb  ",
  "  bbggggggggbb  ",
  "  bbggggggggbb  ",
  "  bbggggggggbb  ",
  "  bbbxxbbxxbbb  ",
  "  bbbxxbbxxbbb  ",
  "  bbbxxbbxxbbb  ",
  "     xx  xx     ",
  "   rrrr  rrrr   ");


const array string: door_pic is [](
  "BBBBBBBBBBBBBBBB",
  "B  B  B  B  B  B",
  "B  B  B  B  B  B",
  "BBBBBBBBBBBBBBBB",
  "B  B  B  B  B  B",
  "B  B  B  B  B  B",
  "BBBBBBBBBBBBBBBB",
  "B  B  B  B  B  B",
  "B  B  B  B  B  B",
  "BBBBBBBBBBBBBBBB",
  "B  B  B  B  B  B",
  "B  B  B  B  B  B",
  "BBBBBBBBBBBBBBBB",
  "B  B  B  B  B  B",
  "B  B  B  B  B  B",
  "BBBBBBBBBBBBBBBB");


const array string: large_gem_pic is [](
  "                                ",
  "                                ",
  "     RRRRRR          RRRRRR     ",
  "   RRRRRRRRRR      RRRRRRRRRR   ",
  "  RRRrrrrrrRRR    RRRrrrrrrRRR  ",
  " RRrrrrrrrrrrRR  RRrrrrrrrrrrRR ",
  " RRrrrrrrrrrrrRRRRrrrrrrrrrrrRR ",
  "RRrrrrrrrrrrrrrRRrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  "RRrrrrrrrrrrrrrrrrrrrrrrrrrrrrRR",
  " RRrrrrrrrrrrrrrrrrrrrrrrrrrrRR ",
  " RRrrrrrrrrrrrrrrrrrrrrrrrrrrRR ",
  "  RRrrrrrrrrrrrrrrrrrrrrrrrrRR  ",
  "   RRrrrrrrrrrrrrrrrrrrrrrrRR   ",
  "    RRrrrrrrrrrrrrrrrrrrrrRR    ",
  "     RRrrrrrrrrrrrrrrrrrrRR     ",
  "      RRrrrrrrrrrrrrrrrrRR      ",
  "       RRrrrrrrrrrrrrrrRR       ",
  "        RRrrrrrrrrrrrrRR        ",
  "         RRrrrrrrrrrrRR         ",
  "          RRrrrrrrrrRR          ",
  "           RRrrrrrrRR           ",
  "            RRrrrrRR            ",
  "             RRrrRR             ",
  "              RRRR              ",
  "               RR               ",
  "                                ");


const array string: fairy_pic is [](
  "      xxxxx                   YYYY                   xxxxx      ",
  "    xxxcccxxx               YYYYYYYY               xxxcccxxx    ",
  "   xxcccccccxx             YYYYYYYYYY             xxcccccccxx   ",
  "  xxcccccccccxx           YYYYYYYYYYYY           xxcccccccccxx  ",
  "  xcccccccccccxx          YYYXXXXXXYYY          xxcccccccccccx  ",
  "  xccccccccccccxx        YYYXXXXXXXXYYY        xxccccccccccccx  ",
  "  xxccccccccccccxx       YYYXBBXXBBXYYY       xxccccccccccccxx  ",
  "   xcccccccccccccxx      YYYXXXXXXXXYYY      xxcccccccccccccx   ",
  "   xxcccccccccccccxx     YYYXXXXXXXXYYY     xxcccccccccccccxx   ",
  "    xxxccccccccccccxx    YYYXXOXXOXXYYY    xxccccccccccccxxx    ",
  "   xxcccccBccccBccccxx   YYYXXXOOXXXYYY   xxcccccccccccccccxx   ",
  "   xcccccccBccBccccccxx      XXXXXX      xxcccccccccccccccccx   ",
  "  xxccccccccccccccccccxx      XXXX      xxccccccccccccccccccxx  ",
  "  xccccccBBcXXcBBccccccxx     XXXX     xxccccccccccccccccccccx  ",
  "  xcccccccccXXccccccccccxXXXXXXXXXXXXXXxcccccccccccccccccccccx  ",
  "  xxccccccBcRRcBcccccccXXXXXXXXXXXXXXXXXXcccccccccccccccccccxx  ",
  "   xcccccBccRRccBcccccXXXXXXXXXXXXXXXXXXXXccccccccccccccccccx   ",
  "   xxcccccccRRcccccccXXXXXRRRXXXXXXRRRXXXXXccccccccccccccccxx   ",
  "    xxxcccccRRccccccXXXXXRRRRRXXXXRRRRRXXXXXcccccccccccccxxx    ",
  "   xxcccccccRRcccccXXXXXRRRRRRRXXRRRRRRRXXXXXccccccccccccccxx   ",
  "   xccccccccRRccccXXXXXcRRRRRRRXXRRRRRRRcXXXXXccccccccccccccx   ",
  "  xxccccccccRRcccXXXXXccRRRRRRRXXRRRRRRRccXXXXXcccccccccccccxx  ",
  "  xcccccccccRRccXXXXXcccxRRRRRXXXXRRRRRxcccXXXXXcccccccccccccx  ",
  "  xcccccccccRRcXXXXXcccxxcRRRXXXXXXRRRcxxcccXXXXXccccccccccccx  ",
  "  xxccccccccRRXXXXXcccxx   XXXXXXXXXX   xxcccXXXXXccccccccccxx  ",
  "   xcccccccXXXXXXXcccxx    XXXXXXXXXX    xxcccXXXXXXXXccccccx   ",
  "   xxcccccXXXXXXXcccxx     XXXXXXXXXX     xxcccXXXXXXccccccxx   ",
  "    xxxcccXXXXXXcccxx      XXXXYYXXXX      xxcccXXXXXXcccxxx    ",
  "   xxcccccXXXXXcccxx      XXXXXYYXXXXX      xxccXXXXXXXccccxx   ",
  "   xcccccccXXXcccxx       XXXXXXXXXXXX       xxccXXXXXccccccx   ",
  "  xxccccccccccccxx       XXXXXXXXXXXXXX       xxccXXccccccccxx  ",
  "  xccccccccccccxx       RRRRRRRRRRRRRRRR       xxccccccccccccx  ",
  "  xcccccccccccxx        XXRRRRRRRRRRRRXX        xxcccccccccccx  ",
  "  xxcccccccccxx        XXXXXRRRRRRRRXXXXX        xxcccccccccxx  ",
  "   xxcccccccxx         XXXXXXRRRRRRXXXXXX         xxcccccccxx   ",
  "    xxxcccxxx          XXXXXXXRRRRXXXXXXX          xxxcccxxx    ",
  "      xxxxx            XXXXXXXRRRRXXXXXXX            xxxxx      ",
  "                       XXXXXXXXRRXXXXXXXX                       ",
  "                        XXXXXXXRRXXXXXXX                        ",
  "                        XXXXXXX  XXXXXXX                        ",
  "                         XXXXXX  XXXXXX                         ",
  "                         XXXXXX  XXXXXX                         ",
  "                         XXXXXX  XXXXXX                         ",
  "                         XXXXXX  XXXXXX                         ",
  "                          XXXXX  XXXXX                          ",
  "                          XXXXX  XXXXX                          ",
  "                          XXXXX  XXXXX                          ",
  "                          XXXXX  XXXXX                          ",
  "                          XXXXX  XXXXX                          ",
  "                          XXXXX  XXXXX                          ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                           XXXX  XXXX                           ",
  "                          XXXXX  XXXXX                          ",
  "                         XXXXXX  XXXXXX                         ",
  "                         XXXXXX  XXXXXX                         ");


const array string: computer_pic is [](
  "ccccccccccccccccccc                                 YYYYY       ",
  "ccccccccccccccccccc                                YYYYYYY      ",
  "cc               cc                               YYYYYYYY      ",
  "cc XXX  R R  XXX cc                               YYYYYYYYY     ",
  "cc  X  RRRRR XXX cc                               YYYYYYYYY     ",
  "cc  X  RRRRR  X  cc                                XXXYYYYY     ",
  "cc  X   RRR  XXX cc                                cXXYYYYY     ",
  "cc  X   RRR   X  cc                               XXXXYYYYY     ",
  "cc XXX   R   X X cc                               XXXXRYYYY     ",
  "cc               cc                                XXXYYYYY     ",
  "cc ccccccccccc   cc                                OXXYYYYY     ",
  "cc XXXXXXXXXXX   cc                                XXXXX        ",
  "cc X         X   cc                                 XXX         ",
  "cc X XXXX XX X   cc                                 XXX         ",
  "cc X         X   cc                                RRRRR  GGG   ",
  "cc X   ccccccccc cc                                RRRRR GGGG   ",
  "cc X X XXXXXXXXX cc                                RRRRRRGGGG   ",
  "cc X   X       X cc                               RRRRRRRGGGG cc",
  "cc XXXXX  RRGG X cc                              RRRRRRRRGGGG cc",
  "cc     X RRRR  X cc                             RRRRRRRRRGGGGccc",
  "cc     X  RR   X cc                             RRRRRRRRRGGGGccc",
  "cc     XXXXXXXXX cc                             RRRRRRRRRGGGGccc",
  "cc               cc                              RRRRRRRRGGGGccc",
  "ccccccccccccccccccc                               RRRRRRRGGGG cc",
  "ccccccccccccccccccc                               RRRRRRRGGGG cc",
  "       xxxxx      R   G  R                       RRRRRRRRGGGG cc",
  "       xxxxx       R  G R                        RRRRRRRRGGGG cc",
  "       xxxxx        R GR                        RRRRRRRRR GGG cc",
  "xxxxxxxxxxxxxxxxxxx BBBB                     RRRRRRRRRRRR     cc",
  "xxxxxxxxxxxXXXXXXxx BBBB                  RRRRRRRRRRRRRRR     cc",
  "xxXXxxxxxxxxxxxxxxx BBBB  cccc  XXXXX  RRRRRRRRRR  RRRRRR     cc",
  "xxXXxxxxxxxXXXXXXxx BBBB  cccccccXXXXXXRRRRRRR     RRRRRR     cc",
  "xxxxxxxxxxxxxxxxxxx BBBB  cccccccccXXXXRRRR        GGGGGG     cc",
  "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        GGGGGG     cc",
  "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        BBBBBBB    cc",
  "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb       BBBBBBBB    cc",
  "  bbbb                  bbbb                  BBBBBBBBBBBBB   cc",
  "  bbbb                  bbbb              BBBBBBBBBBBBBBBBB   cc",
  "  bbbb                  bbbb          BBBBBBBBBBBBBBBBBBBBB   cc",
  "  bbbb                  bbbb       BBBBBBBBBBBBBBBBBBBBBBBB   cc",
  "  bbbb                  bbbb      BBBBBBBBBBBBBBBBBBBBBBBB    cc",
  "  bbbb                  bbbb     BBBBBBBBBBBBBBBBBBBBBBBBB    cc",
  "  bbbb                  bbbb     BBBBBBBBBBBBBBBBBBBBBBBB     cc",
  "  bbbb                  bbbb     BBBBBBBBBBBBBBBBBBBBBB       cc",
  "  bbbb                  bbbb     BBBBBBGGGGGGGGGGGGGGGGGGGGG  cc",
  "  bbbb                  bbbb     BBBBBGGGGGGGGGGGGGGGGGGGGGGG cc",
  "  bbbb            X     bbbb     BBBBBGGGGGGGGGGGGGGGGGGGGGGG cc",
  "  bbbb      X    XX     bbbb     BBBBBGGGGGGGGGGGGGGGGGGGGGGG cc",
  "  bbbb      XX  XXX     bbbb     BBBBB          ccc  cccccc  ccc",
  "  bbbb     XXX XXXX     bbbb     BBBBB          ccc ccccccccccc ",
  "  bbbb    xxxxxxxxxx    bbbb     BBBBB          ccc cccccccccc  ",
  "  bbbb    XxXxXxXxXx    bbbb     BBBBB          ccc             ",
  "  bbbb    xxxXxxxXxx    bbbb     BBBBB          ccc             ",
  "  bbbb    XxXxXxXxXx    bbbb     BBBBB          ccc             ",
  "  bbbb    xXxxxXxxxX    bbbb     BBBBB          ccc             ",
  "  bbbb    XxXxXxXxXx    bbbb     BBBBB          ccc             ",
  "  bbbb    xxxXxxxXxx    bbbb     BBBBB          ccc             ",
  "  bbbb    XxXxXxXxXx    bbbb     BBBBB          ccc             ",
  "  bbbb    xXxxxXxxxX    bbbb     BBBBB   ccccccccccccccccc      ",
  "  bbbb    XxXxXxXxXx    bbbb     BBBBB ccccccccccccccccccccc    ",
  "  bbbb    xxxXxxxXxx    bbbb     BBBBB ccccccccccccccccccccc    ",
  "  bbbb    XxXxXxXxXx    bbbb  RRRRRRRR bbb      bbb      bbb    ",
  "  bbbb    xXxxxXxxxX    bbbb RRRRRRRRR bbb      bbb      bbb    ",
  "  bbbb    xxxxxxxxxx    bbbb RRRRRRRRR bbb      bbb      bbb    ");


const array string: sea_pic is [](
  "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccccccOOOOOOOcccccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOcccccccc",
  "cccccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOcccccc",
  "ccccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOccccc",
  "cccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOOOcccc",
  "cccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOOOcccc",
  "ccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOOOOOccc",
  "ccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOOOOOccc",
  "ccccccccccccccccccccccccccccccccccccccccOOOOOOOOOOOOOOOOOOOOOccc",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBOOOOBOOOOOBOOOOOBOOOOBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBOOOOOBOOOOOBOOOOOBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBOOOBOOOBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "BXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXBBXXB",
  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYbbbbbbYYYYYYYYYYYYYYYYYYYXRRRRXXXXYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYbbbbbbbbbYYYYYYYYYYYYYYYYYYXXRRRXXXXXXXYYYYYYYYYYYYYYYYYYYYYYY",
  "YbbbbXXXXXXYYYYYXXXRXXXXXXXXXXXRRXXXXXXXXXXYYYYYYYYYYYYYYYYYYYYY",
  "YbbbXXBXXXXXYYXXXXxRXXXXXXXXXXXRXXXXXXXXXXXXXYYYYYYYYYYYYYXXXYYY",
  "bbbbXXBXXOXXXXXXXXXXxxXXXXXXXXXRXXXXXXXXXXXXXXXYYYYYYXXXXXXXXXYY",
  "bbbbXXXXXXOXXXXXXXXXXXxxXXXXXXXRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY",
  "bbbbXXBXXOXXXXXXXXXXXXXXxxXXXXXRXXXXXXXXXXXXXXXXXXXXXXXXYYYYXXXY",
  "YbbbXXBXXXXXYYXXXRRRXXXXXXxxXXXRRXXXXXXXXXXXXXXXXXXXYYYYYYYYYXXX",
  "YbbbbXXXXXXYYYYYRRRRRXXXXXXXYYYYYYYYYYYYYYYYYYXXXXYYYYYYYYYYYYRX",
  "YGbbbbbbbbbGGGGGGRRRRRGGXXXXXXGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGY",
  "GGGGGGGGGGGGGGGGGGGGGGGGGGXXXXXXGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
  "GGGGGGGGGGGGGGGGGGXXXXXXXXXXXXXXGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
  "GGGGGGGGGGGGGGGXXXXXXXXXXXXXXXXXGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
  "GGGGGGGGGGGXXXXXXXXXXXXXXXXXXXXGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
  "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY");


const array string: woman_pic is [](
  "                             YYYYYY                             ",
  "                           YYYYYYYYYY                           ",
  "                         YYYYYYYYYYYYYY                         ",
  "                        YYYYYYYYYYYYYYYY                        ",
  "                       YYYYYYYYYYYYYYYYYY                       ",
  "                      YYYYYYYYYYYYYYYYYYYY                      ",
  "                     YYYYYYYYYYYYYYYYYYYYYY                     ",
  "                    YYYYYYYYYYYYYYYYYYYYYYYY                    ",
  "                    YYYYYYYXXXXXXXXXXYYYYYYY                    ",
  "                   YYYYYYYXXXXXXXXXXXXYYYYYYY                   ",
  "                   YYYYYYXXXXXXXXXXXXXXYYYYYY                   ",
  "                  YYYYYYXXXXXXXXXXXXXXXXYYYYYY                  ",
  "                  YYYYYYXXXBBXXXXXXBBXXXYYYYYY                  ",
  "                  YYYYYYXXBBBBXXXXBBBBXXYYYYYY                  ",
  "                  YYYYYYXXXBBXXXXXXBBXXXYYYYYY                  ",
  "                  YYYYYYXXXXXXXXXXXXXXXXYYYYYY                  ",
  "                  YYYYYYXXXXXXXXXXXXXXXXYYYYYY                  ",
  "                  YYYYYYXXXXXXXXXXXXXXXXYYYYYY                  ",
  "                  YYYYYYXXXXXXXXXXXXXXXXYYYYYY                  ",
  "                  YYYYYYXXXXOOXXXXOOXXXXYYYYYY                  ",
  "                  YYYYYYXXXXXOOOOOOXXXXXYYYYYY                  ",
  "                  YYYYYY XXXXXOOOOXXXXX YYYYYY                  ",
  "                          XXXXXXXXXXXX                          ",
  "                           XXXXXXXXXX                           ",
  "                            XXXXXXXX                            ",
  "                            XXXXXXXX                            ",
  "                            XXXXXXXX                            ",
  "                           XXXXXXXXXX                           ",
  "                   OOOOOOOOXXXXXXXXXXOOOOOOOO                   ",
  "                OOOOOOOOOOOOXXXXXXXXOOOOOOOOOOOO                ",
  "              OOOOOOOOOOOOOOOOXXXXOOOOOOOOOOOOOOOO              ",
  "             OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO             ",
  "            OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO            ",
  "           OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO           ",
  "          OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO          ",
  "         OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO         ",
  "         XOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOX         ",
  "        XXXOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOXXX        ",
  "       XXXXXOOOOO  OOOOOOOOOOOOOOOOOOOOOOOOOO  OOOOOXXXXX       ",
  "      XXXXXXXOOO  OOOOOOOOOOOOOOOOOOOOOOOOOOOO  OOOXXXXXXX      ",
  "     XXXXXXXXXO   OOOOOOOOOOOOOOOOOOOOOOOOOOOO   OXXXXXXXXX     ",
  "    XXXXXXXXX     OOOOOOOOOOOOOOOOOOOOOOOOOOOO     XXXXXXXXX    ",
  "   XXXXXXXXX      OOOOOOOOOOOOMOOMOOOOOOOOOOOO      XXXXXXXXX   ",
  "  XXXXXXXXX        OOOOOOOOOOOOOOOOOOOOOOOOOO        XXXXXXXXX  ",
  " XXXXXXXXX         OOOOOOOOOOMOOOOMOOOOOOOOOO         XXXXXXXXX ",
  "XXXXXXXXX           OOOOOOOOMOOOOOOMOOOOOOOO           XXXXXXXXX",
  "XXXXXXXXX            OMOMOMOOOOOOOOOOMOMOMO            XXXXXXXXX",
  "XXXXXXXXXXXX         OOOOOOOOOOOOOOOOOOOOOO         XXXXXXXXXXXX",
  "XXXXXXXXXXXXXXX       OOOOOOOOOOOOOOOOOOOO       XXXXXXXXXXXXXXX",
  " XXXXXXXXXXXXXXXXX    OOOOOOOOOOOOOOOOOOOO    XXXXXXXXXXXXXXXXX ",
  "bbbbXXXXXXXXXXXXXXXXXbbbbbbbbbbbbbbbbbbbbbbXXXXXXXXXXXXXXXXXbbbb",
  "bbbbbbbXXXXXXXXXXXXXXXXXXXXXbbbbbbbbXXXXXXXXXXXXXXXXXXXXXbbbbbbb",
  "bbbbbbbbbbXXXXXXXXXXXXXXXbbbbbbbbbbbbbbXXXXXXXXXXXXXXXbbbbbbbbbb",
  "bbbbbbbbbbbbbXXXXXXXXXXXXXXbbbbbbbbbbXXXXXXXXXXXXXXbbbbbbbbbbbbb",
  "bbbbbbbbbbbbbbbbXXXXXXXXXXXXXbbbbbbXXXXXXXXXXXXXbbbbbbbbbbbbbbbb",
  "bbbbbbbbbbbbbbbbbXXXXXXXXXXXbbbbbbbbXXXXXXXXXXXbbbbbbbbbbbbbbbbb",
  "bbbbbbbbbbbbbbbbbbXXXXXXXXxxbbbbbbbbbbXXXXXXXXbbbbbbccccbbbbbbbb",
  "bbbbbbbbbbbbbbbbbbbbXXXXXxxxbbbbbbbbbbbXXXXXbbbbbbcccbbcccbbbbbb",
  "bbbbbbbbbbbbbbbbbbbbbxxxxxxxbbbbbbbbbbbbbbbbbbbbbccbbbbbbccbbbbb",
  "bbbbbbbbbbbbbbbbbbbbbcccccccbbbbbbbbbbbbbbbbbbbcccbbbbbbbbcbbbbb",
  "bbbbbbbbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbbbccccbbbbbbbbbbccbbbb",
  "bbbbbbbbbbbbbbbbbbbbbbbbccbbbbbbbbbbcccccccccbbbbbbbbbbbbbbcbbbb",
  "bbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccbbbbbbbbbbbbbbbbbbbbbbcbbbb",
  "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcbbbb");


const array string: zero is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc     xBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const array string: one is [](
  "                ",
  "                ",
  "     xBBBBc     ",
  "        xBc     ",
  "        xBc     ",
  "        xBc     ",
  "        xBc     ",
  "        xBc     ",
  "      xBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "  xBBBBBBBBBBc  ",
  "                ");


const array string: two is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "            xBc ",
  "            xBc ",
  "            xBc ",
  "   xBBBBBBBBBc  ",
  "  xBBBBc        ",
  "  xBBBBc        ",
  "  xBBBBc        ",
  "  xBBBBc        ",
  "  xBBBBc        ",
  "  xBBBBBBBBBBBc ",
  "                ");


const array string: three is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "            xBc ",
  "            xBc ",
  "            xBc ",
  "   xBBBBBBBBBc  ",
  "         xBBBBc ",
  "         xBBBBc ",
  "         xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const array string: four is [](
  "                ",
  "                ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBc    xBc    ",
  "  xBc    xBc    ",
  "  xBBBBBBBBBBBc ",
  "      xBBBBc    ",
  "      xBBBBc    ",
  "      xBBBBc    ",
  "      xBBBBc    ",
  "      xBBBBc    ",
  "      xBBBBc    ",
  "                ");

const array string: five is [](
  "                ",
  "                ",
  "  xBBBBBBBBBBBc ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBBBBBBBBBBc  ",
  "         xBBBBc ",
  "         xBBBBc ",
  "         xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const array string: six is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "  xBc           ",
  "  xBc           ",
  "  xBc           ",
  "  xBBBBBBBBBBc  ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const array string: seven is [](
  "                ",
  "                ",
  "  xBBBBBBBBBBBc ",
  "            xBc ",
  "            xBc ",
  "            xBc ",
  "            xBc ",
  "           xBBc ",
  "      xBBBBBBc  ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "     xBBBBc     ",
  "                ");


const array string: eight is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "   xBBBBBBBBBc  ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const array string: nine is [](
  "                ",
  "                ",
  "   xBBBBBBBBBc  ",
  "  xBBc     xBBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "  xBc       xBc ",
  "   xBBBBBBBBBBc ",
  "         xBBBBc ",
  "         xBBBBc ",
  "         xBBBBc ",
  "  xBc    xBBBBc ",
  "  xBBc   xBBBBc ",
  "   xBBBBBBBBBc  ",
  "                ");


const func cardType: genCard (in array string: pattern) is func
  result
    var cardType: result is cardType.value;
  begin
    result.picture := pattern;
  end func;


var cardType: back     is genCard(card_back_pic);

var array cardType: cards is [](
    genCard(fairy_pic),
    genCard(computer_pic),
    genCard(sea_pic),
    genCard(big_bush_pic),
    genCard(crown_pic),
    genCard(hut_pic),
    genCard(fountain_pic),
    genCard(snake_pic),
    genCard(lamp_pic),
    genCard(scepter_pic),
    genCard(book_pic),
    genCard(hourglass_pic),
    genCard(large_gem_pic),
    genCard(magic_wand_pic),
    genCard(sword_pic),
    genCard(key_pic),
    genCard(glasses_pic),
    genCard(helmet_pic),
    genCard(flask_pic),
    genCard(crystal_ball_pic),
    genCard(necklace_pic),
    genCard(holy_cross_pic),
    genCard(diamond_pic),
    genCard(silver_bars_pic),
    genCard(ruby_pic),
    genCard(jade_figurine_pic),
    genCard(harp_pic),
    genCard(goldbar_pic),
    genCard(goblet_pic),
    genCard(bat_pic),
    genCard(statue_pic),
    genCard(door_pic),
    genCard(vampire_pic),
    genCard(ogre_pic),
    genCard(demon_pic),
    genCard(chain_pic),
    genCard(woman_pic),
    genCard(panic_monster1_pic),
    genCard(panic_monster2_pic),
    genCard(panic_monster3_pic),
    genCard(dig_right_pic),
    genCard(tree_pic)
  );

var array cardType: size_descr is [](
    genCard(size_2_5),
    genCard(size_3_4),
    genCard(size_4_4),
    genCard(size_4_5),
    genCard(size_4_6),
    genCard(size_5_6),
    genCard(size_6_6),
    genCard(size_6_7),
    genCard(size_6_8),
    genCard(size_6_10),
    genCard(size_6_12),
    genCard(size_6_14)
  );

const array array integer: size_list is [](
    [](2, 5),
    [](3, 4),
    [](4, 4),
    [](4, 5),
    [](4, 6),
    [](5, 6),
    [](6, 6),
    [](6, 7),
    [](6, 8),
    [](6, 10),
    [](6, 12),
    [](6, 14)
  );


var array array fieldType: field is 0 times 0 times fieldType.value;


const func color: charColor (in char: ch) is func
  result
    var color: result is black;
  begin
    case ch of
      when {' '}: result := black;
      when {'R'}: result := light_red;
      when {'G'}: result := light_green;
      when {'B'}: result := light_blue;
      when {'Y'}: result := yellow;
      when {'M'}: result := light_magenta;
      when {'O'}: result := orange;
      when {'r'}: result := dark_red;
      when {'g'}: result := dark_green;
      when {'c'}: result := light_cyan;
      when {'X'}: result := white;
      when {'x'}: result := light_gray;
      when {'b'}: result := brown;
      otherwise:  result := black;
    end case;
  end func;


const func PRIMITIVE_WINDOW: create_pixmap (in array string: pattern,
    in integer: scale) is func
  result
    var PRIMITIVE_WINDOW: result is PRIMITIVE_WINDOW.value;
  local
    var integer: height is 0;
    var integer: width is 0;
    var integer: line is 0;
    var integer: column is 0;
  begin
    height := length(pattern);
    width := length(pattern[1]);
    result := newPixmap(width * scale, height * scale);
    clear(result, black);
    for line range 1 to height do
      for column range 1 to width do
        rect(result, pred(column) * scale, pred(line) * scale,
            scale, scale, charColor(pattern[line][column]));
      end for;
    end for;
  end func;


const proc: draw (in integer: xPos, in integer: yPos,
    in array string: pattern, in integer: scale) is func
  local
    var integer: height is 0;
    var integer: width is 0;
    var integer: lin is 0;
    var integer: col is 0;
    var integer: xPosition is 0;
    var integer: yPosition1 is 0;
    var integer: yPosition2 is 0;
    var integer: line1 is 0;
    var integer: line2 is 0;
  begin
    height := length(pattern);
    width := length(pattern[1]);
    for lin range 1 to height div 2 do
      xPosition := xPos;
      yPosition1 := yPos + (height div 2 - lin) * scale;
      yPosition2 := yPos + pred(height div 2 + lin) * scale;
      line1 := succ(height div 2 - lin);
      line2 := height div 2 + lin;
      for col range 1 to width do
        rect(xPosition,
            yPosition1,
            scale, scale,
            charColor(pattern[line1][col]));
        rect(xPosition,
            yPosition2,
            scale, scale,
            charColor(pattern[line2][col]));
        xPosition +:= scale;
      end for;
    end for;
  end func;


const proc: draw (in integer: xPos, in integer: yPos,
    inout cardType: aCard) is func
  begin
    if aCard.pixmap = PRIMITIVE_WINDOW.value then
      rect(xPos, yPos, CARD_SIZE, CARD_SIZE, white);
      draw(xPos, yPos, aCard.picture, CARD_SIZE div length(aCard.picture));
      aCard.pixmap := getPixmap(xPos, yPos, CARD_SIZE, CARD_SIZE);
    else
      put(xPos, yPos, aCard.pixmap, PSET);
    end if;
  end func;


const proc: put (inout cardType: aCard, in integer: line, in integer: column) is func
  begin
    draw(LEFT_BORDER + CARD_BORDER + FIELD_STEP * pred(column),
        UPPER_BORDER + CARD_BORDER + FIELD_STEP * pred(line), aCard);
  end func;


const proc: prepare (inout cardType: aCard) is func
  local
    var integer: height is 0;
    var integer: width is 0;
    var integer: scale is 0;
    var PRIMITIVE_WINDOW: pixmap is PRIMITIVE_WINDOW.value;
    var integer: lin is 0;
    var integer: col is 0;
  begin
    if aCard.pixmap = PRIMITIVE_WINDOW.value then
      height := length(aCard.picture);
      width := length(aCard.picture[1]);
      scale := CARD_SIZE div height;
      pixmap := newPixmap(width * scale, height * scale);
      clear(pixmap, black);

      lin := 1;
      while lin <= height and not keypressed(KEYBOARD) do
        for col range 1 to width do
          rect(pixmap, pred(col) * scale, pred(lin) * scale,
              scale, scale, charColor(aCard.picture[lin][col]));
        end for;
        incr(lin);
      end while;
      if not keypressed(KEYBOARD) then
        aCard.pixmap := pixmap;
      end if;
    end if;
  end func;


const proc: show (in integer: line, in integer: column) is func
  begin
    if field[line][column].visible = backSide then
      put(cards[field[line][column].cardNumber], line, column);
      field[line][column].visible := frontSide;
      field[line][column].visited := TRUE;
    end if;
  end func;


const proc: hide (in integer: line, in integer: column) is func
  begin
    if field[line][column].visible = frontSide then
      put(back, line, column);
      field[line][column].visible := backSide;
(*
      put(cards[field[line][column].cardNumber], line, column);
      rect(LEFT_BORDER + CARD_BORDER + FIELD_STEP * pred(column),
          UPPER_BORDER + CARD_BORDER + FIELD_STEP * pred(line), 16, 16, light_cyan);
*)
    end if;
  end func;


const proc: remove (in integer: line, in integer: column) is func
  begin
    if field[line][column].visible <> removed then
      rect(LEFT_BORDER + CARD_BORDER + FIELD_STEP * pred(column),
          UPPER_BORDER + CARD_BORDER + FIELD_STEP * pred(line), CARD_SIZE, CARD_SIZE, white);
      field[line][column].visible := removed;
    end if;
  end func;


const proc: hideAll is func
  local
    var integer: line is 0;
    var integer: column is 0;
  begin
    for line range 1 to length(field) do
      for column range 1 to length(field[line]) do
        hide(line, column);
      end for;
    end for;
  end func;


const proc: draw_number (in integer: xPos, in integer: yPos, in string: num_stri) is func
  local
    var integer: index is 0;
    var char: ch is ' ';
  begin
    for index range 1 to length(num_stri) do
      ch := num_stri[index];
      if ch = ' ' then
        rect(xPos + pred(index) * 32,
            yPos,
            32,
            32,
            white);
      else
        put(xPos + pred(index) * 32,
            yPos,
            digit_pixmap[ord(ch) - ord('0')], PSET);
      end if;
    end for;
  end func;


const proc: showHit (in integer: cardNumber, in var integer: yPos, in var integer: hits) is func
  local
    var integer: xPos is OPPONENT_XPOS + 128 + 8 + 64 + 7;
  begin
    draw_number(OPPONENT_XPOS + 128 + 8, yPos + 16, succ(hits) lpad 2);
    if hits >= 21 then
      hits -:= 21;
      yPos +:= 64 + 8;
    end if;
    line(xPos + 32 * hits,     yPos, 0, 64, white);
    draw(xPos + 32 * hits + 1, yPos, cards[cardNumber]);
    line(xPos + 32 * hits + 5, yPos, 0, 64, white);
    draw(xPos + 32 * hits + 6, yPos, cards[cardNumber]);
  end func;


const func integer: countCardBacks is func
  result
    var integer: result is 0;
  local
    var integer: line is 0;
    var integer: column is 0;
  begin
    for line range 1 to length(field) do
      for column range 1 to length(field[line]) do
        if field[line][column].visible = backSide then
          incr(result);
        end if;
      end for;
    end for;
  end func;


const proc: randomField (inout integer: fieldLine, inout integer: fieldColumn) is func
  local
    var integer: line is 0;
    var integer: column is 0;
    var integer: numCards is 0;
    var integer: selectedCard is 0;
  begin
    numCards := countCardBacks;
    if numCards > 0 then
      selectedCard := rand(1, numCards);
      for line range 1 to length(field) do
        for column range 1 to length(field[line]) do
          if field[line][column].visible = backSide then
            decr(selectedCard);
            if selectedCard = 0 then
              fieldLine := line;
              fieldColumn := column;
            end if;
          end if;
        end for;
      end for;
    end if;
  end func;


const proc: randomNotVisited (inout integer: fieldLine, inout integer: fieldColumn) is func
  local
    var integer: line is 0;
    var integer: column is 0;
    var integer: numCards is 0;
    var integer: selectedCard is 0;
  begin
    for line range 1 to length(field) do
      for column range 1 to length(field[line]) do
        if field[line][column].visible = backSide and
          not field[line][column].visited then
          incr(numCards);
        end if;
      end for;
    end for;
    if numCards > 0 then
      selectedCard := rand(1, numCards);
      for line range 1 to length(field) do
        for column range 1 to length(field[line]) do
          if field[line][column].visible = backSide and
              not field[line][column].visited then
            decr(selectedCard);
            if selectedCard = 0 then
              fieldLine := line;
              fieldColumn := column;
            end if;
          end if;
        end for;
      end for;
    else
      randomField(fieldLine, fieldColumn);
    end if;
  end func;


const proc: firstOfPair (inout integer: fieldLine, inout integer: fieldColumn,
    inout boolean: found) is func
  local
    var integer: line1 is 0;
    var integer: column1 is 0;
    var integer: line2 is 0;
    var integer: column2 is 0;
  begin
    found := FALSE;
    for line1 range 1 to length(field) do
      for column1 range 1 to length(field[line1]) do
        if not found and field[line1][column1].visible = backSide and
            field[line1][column1].visited then
          for column2 range succ(column1) to length(field[line1]) do
            if field[line1][column2].visible = backSide and
                field[line1][column2].visited and
                field[line1][column1].cardNumber =
                field[line1][column2].cardNumber then
              fieldLine := line1;
              fieldColumn := column1;
              found := TRUE;
            end if;
          end for;
          for line2 range succ(line1) to length(field) do
            for column2 range 1 to length(field[line1]) do
              if field[line2][column2].visible = backSide and
                  field[line2][column2].visited and
                  field[line1][column1].cardNumber =
                  field[line2][column2].cardNumber then
                fieldLine := line1;
                fieldColumn := column1;
                found := TRUE;
              end if;
            end for;
          end for;
        end if;
      end for;
    end for;
  end func;


const proc: secondOfPair (in integer: cardNumber,
    inout integer: fieldLine, inout integer: fieldColumn,
    inout boolean: found) is func
  local
    var integer: line is 0;
    var integer: column is 0;
  begin
    found := FALSE;
    for line range 1 to length(field) do
      for column range 1 to length(field[line]) do
        if field[line][column].visible = backSide and
            field[line][column].visited and
            field[line][column].cardNumber = cardNumber then
          fieldLine := line;
          fieldColumn := column;
          found := TRUE;
        end if;
      end for;
    end for;
  end func;


const proc: computerLevel0 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    randomField(line2, column2);
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel1 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found2 is FALSE;
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    if rand(1, 5) = 1 then
      secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    end if;
    if not found2 then
      randomField(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel2 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found2 is FALSE;
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    if rand(1, 4) = 1 then
      secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    end if;
    if not found2 then
      randomField(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel3 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found2 is FALSE;
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    if rand(1, 3) = 1 then
      secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    end if;
    if not found2 then
      randomField(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel4 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found2 is FALSE;
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    if rand(1, 2) = 1 then
      secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    end if;
    if not found2 then
      randomField(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel5 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found2 is FALSE;
  begin
    randomField(line1, column1);
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    if not found2 then
      randomField(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel6 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found1 is FALSE;
    var boolean: found2 is FALSE;
  begin
    if rand(1, 4) = 1 then
      firstOfPair(line1, column1, found1);
    end if;
    if not found1 then
      randomNotVisited(line1, column1);
    end if;
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    if not found2 then
      randomNotVisited(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel7 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found1 is FALSE;
    var boolean: found2 is FALSE;
  begin
    if rand(1, 3) = 1 then
      firstOfPair(line1, column1, found1);
    end if;
    if not found1 then
      randomNotVisited(line1, column1);
    end if;
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    if not found2 then
      randomNotVisited(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel8 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found1 is FALSE;
    var boolean: found2 is FALSE;
  begin
    if rand(1, 2) = 1 then
      firstOfPair(line1, column1, found1);
    end if;
    if not found1 then
      randomNotVisited(line1, column1);
    end if;
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    if not found2 then
      randomNotVisited(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerLevel9 (inout integer: line1, inout integer: column1,
    inout integer: line2, inout integer: column2) is func
  local
    var boolean: found1 is FALSE;
    var boolean: found2 is FALSE;
  begin
    firstOfPair(line1, column1, found1);
    if not found1 then
      randomNotVisited(line1, column1);
    end if;
    show(line1, column1);
    DRAW_FLUSH;
    wait(1 . SECONDS);
    secondOfPair(field[line1][column1].cardNumber, line2, column2, found2);
    if not found2 then
      randomNotVisited(line2, column2);
    end if;
    show(line2, column2);
    DRAW_FLUSH;
    wait(1 . SECONDS);
  end func;


const proc: computerTurn is func
  local
    var integer: line1 is 0;
    var integer: column1 is 0;
    var integer: line2 is 0;
    var integer: column2 is 0;
    var boolean: onTurn is TRUE;
  begin
    while countCardBacks > 0 and onTurn do
      case game.currLevel of
        when {0}: computerLevel0(line1, column1, line2, column2);
        when {1}: computerLevel1(line1, column1, line2, column2);
        when {2}: computerLevel2(line1, column1, line2, column2);
        when {3}: computerLevel3(line1, column1, line2, column2);
        when {4}: computerLevel4(line1, column1, line2, column2);
        when {5}: computerLevel5(line1, column1, line2, column2);
        when {6}: computerLevel6(line1, column1, line2, column2);
        when {7}: computerLevel7(line1, column1, line2, column2);
        when {8}: computerLevel8(line1, column1, line2, column2);
        when {9}: computerLevel9(line1, column1, line2, column2);
        otherwise: computerLevel0(line1, column1, line2, column2);
      end case;
      if field[line1][column1].cardNumber =
          field[line2][column2].cardNumber then
        remove(line1, column1);
        remove(line2, column2);
        showHit(field[line1][column1].cardNumber, COMPUTER_HIT_YPOS, game.computerHits);
        incr(game.computerHits);
      else
        hide(line1, column1);
        hide(line2, column2);
        onTurn := FALSE;
      end if;
    end while;
  end func;


const proc: checkHit (in integer: line1, in integer: column1,
    in integer: line2, in integer: column2, inout boolean: hit) is func
  begin
    if field[line1][column1].cardNumber =
        field[line2][column2].cardNumber then
      remove(line1, column1);
      remove(line2, column2);
      showHit(field[line1][column1].cardNumber, game.player_hit_ypos, game.playerHits);
      incr(game.playerHits);
      hit := TRUE;
    else
      hide(line1, column1);
      hide(line2, column2);
    end if;
  end func;


const proc: mouseCommand (inout integer: line, inout integer: column,
    inout integer: openCards) is func
  begin
    line := getypos(KEYBOARD);
    column := getxpos(KEYBOARD);
    if line >= UPPER_BORDER and column >= LEFT_BORDER then
      line := (line - UPPER_BORDER) div FIELD_STEP + 1;
      column := (column - LEFT_BORDER) div FIELD_STEP + 1;
      if line >= 1 and line <= length(field) and
          column >= 1 and column <= length(field[line]) then
        if field[line][column].visible = backSide then
          show(line, column);
          incr(openCards);
        end if;
      end if;
    end if;
  end func;


const proc: playerMove (inout boolean: hit) is func
  local
    var integer: openCards is 0;
    var integer: line1 is 0;
    var integer: column1 is 0;
    var integer: line2 is 0;
    var integer: column2 is 0;
    var boolean: moveFinished is FALSE;
    var char: command is ' ';
  begin
    hit := FALSE;
    repeat
      command := getc(KEYBOARD);
      if upper(command) = 'Q' then
        moveFinished := TRUE;
        game.quit := TRUE;
      elsif command in digit then
        game.currLevel := ord(command) - ord('0');
        put(59, 12, digit_pixmap[game.currLevel], PSET);
      elsif command in {KEY_RIGHT, KEY_UP} then
        if game.currLevel < 9 then
          incr(game.currLevel);
          put(59, 12, digit_pixmap[game.currLevel], PSET);
        end if;
      elsif command in {KEY_LEFT, KEY_DOWN} then
        if game.currLevel > 0 then
          decr(game.currLevel);
          put(59, 12, digit_pixmap[game.currLevel], PSET);
        end if;
      elsif openCards = 2 then
        checkHit(line1, column1, line2, column2, hit);
        moveFinished := TRUE;
      elsif command = KEY_MOUSE1 then
        if openCards = 0 then
          mouseCommand(line1, column1, openCards);
        elsif openCards = 1 then
          mouseCommand(line2, column2, openCards);
        end if;
      else
        hideAll;
        moveFinished := TRUE;
        if upper(command) = 'Q' then
          game.quit := TRUE;
        end if;
      end if;
    until moveFinished;
  end func;


const proc: playerTurn is func
  local
    var boolean: hit is TRUE;
  begin
    while countCardBacks > 0 and hit do
      playerMove(hit);
    end while;
  end func;


const proc: dealCards (in integer: field_lines, in integer: field_columns) is func
  local
    var integer: line is 0;
    var integer: column is 0;
    var integer: cardNumber is 0;
  begin
    field := field_lines times field_columns times fieldType.value;
    for line range 1 to field_lines do
      for column range 1 to field_columns do
        put(back, line, column);
        repeat
          cardNumber := rand(1, field_lines * field_columns div 2);
        until cards[cardNumber].number < 2;
        field[line][column].cardNumber := cardNumber;
        incr(cards[cardNumber].number);
      end for;
    end for;
    game.player_hit_ypos := UPPER_BORDER + field_lines * FIELD_STEP + 8;
  end func;


const proc: selectSize is func
  local
    var integer: index is 0;
    var char: command is ' ';
    var integer: line is 0;
    var integer: column is 0;
    var boolean: selected is FALSE;
  begin
    for index range 1 to length(size_descr) do
      put(size_descr[index], 1, index);
    end for;
    repeat
      command := getc(KEYBOARD);
      if upper(command) = 'Q' then
        selected := TRUE;
        game.quit := TRUE;
      elsif command = KEY_MOUSE1 then
        line := getypos(KEYBOARD);
        column := getxpos(KEYBOARD);
        if line >= UPPER_BORDER and column >= LEFT_BORDER then
          line := (line - UPPER_BORDER) div FIELD_STEP + 1;
          column := (column - LEFT_BORDER) div FIELD_STEP + 1;
          if line = 1 and column >= 1 and column <= length(size_descr) then
            clear(curr_win, white);
            put(OPPONENT_XPOS, 12, opponent, PSET);
            dealCards(size_list[column][1], size_list[column][2]);
            selected := TRUE;
          end if;
        end if;
      end if;
    until selected;
  end func;


const proc: main is func
  local
    var text: scr is STD_NULL;
    var boolean: done is FALSE;
    var char: command is ' ';
    var integer: line is 0;
    var integer: column is 0;
    var integer: index is 0;
  begin
    screen(1024, 768);
    clear(curr_win, white);
    screen := open(curr_win, 16);
    scr := open(curr_win);
    color(scr, black, white);
    setPos(scr, 2, 44);
    writeln(scr, "P A I R S   -   Concentration game");
    setPos(scr, 4, 44);
    writeln(scr, "Copyright (C) 2005  Thomas Mertes");
    setPos(scr, 6, 44);
    writeln(scr, "This program is free software under the terms of the GNU General Public License.");
    setPos(scr, 8, 44);
    writeln(scr, "Pairs is written in the Seed7 programming language");
    setPos(scr, 9, 46);
    writeln(scr, "Homepage:    http://seed7.sourceforge.net");
    KEYBOARD := GRAPH_KEYBOARD;
    digit_pixmap := [0](
      create_pixmap(zero,  2),
      create_pixmap(one,   2),
      create_pixmap(two,   2),
      create_pixmap(three, 2),
      create_pixmap(four,  2),
      create_pixmap(five,  2),
      create_pixmap(six,   2),
      create_pixmap(seven, 2),
      create_pixmap(eight, 2),
      create_pixmap(nine,  2));

    opponent := create_pixmap(woman_pic, 2);
    put(OPPONENT_XPOS, 12, opponent, PSET);

    selectSize;

    put(59, 12, digit_pixmap[game.currLevel], PSET);

    index := 1;
    while countCardBacks > 0 and not game.quit do
      while index <= length(cards) and not keypressed(KEYBOARD) do
        prepare(cards[index]);
        if not keypressed(KEYBOARD) then
          (* writeln(index); *)
          incr(index);
        end if;
      end while;
      playerTurn;
      if not game.quit then
        computerTurn;
      end if;
    end while;
    if not game.quit then
      command := getc(KEYBOARD);
    end if;
  end func;
