summaryrefslogtreecommitdiffstats
path: root/qnetchess/src
diff options
context:
space:
mode:
Diffstat (limited to 'qnetchess/src')
-rw-r--r--qnetchess/src/CMakeLists.txt44
-rw-r--r--qnetchess/src/gameboard.cpp1987
-rw-r--r--qnetchess/src/gameboard.h245
-rw-r--r--qnetchess/src/gamesocket.cpp33
-rw-r--r--qnetchess/src/gamesocket.h37
-rw-r--r--qnetchess/src/main.cpp54
-rw-r--r--qnetchess/src/mainwindow.cpp294
-rw-r--r--qnetchess/src/mainwindow.h87
-rw-r--r--qnetchess/src/xpm/black_bishop.xpm46
-rw-r--r--qnetchess/src/xpm/black_castle.xpm46
-rw-r--r--qnetchess/src/xpm/black_king.xpm46
-rw-r--r--qnetchess/src/xpm/black_knight.xpm46
-rw-r--r--qnetchess/src/xpm/black_pawn.xpm45
-rw-r--r--qnetchess/src/xpm/black_queen.xpm46
-rw-r--r--qnetchess/src/xpm/chess.xpm46
-rw-r--r--qnetchess/src/xpm/new_game.xpm65
-rw-r--r--qnetchess/src/xpm/quit.xpm68
-rw-r--r--qnetchess/src/xpm/white_bishop.xpm46
-rw-r--r--qnetchess/src/xpm/white_castle.xpm46
-rw-r--r--qnetchess/src/xpm/white_king.xpm46
-rw-r--r--qnetchess/src/xpm/white_knight.xpm46
-rw-r--r--qnetchess/src/xpm/white_pawn.xpm46
-rw-r--r--qnetchess/src/xpm/white_queen.xpm46
23 files changed, 3511 insertions, 0 deletions
diff --git a/qnetchess/src/CMakeLists.txt b/qnetchess/src/CMakeLists.txt
new file mode 100644
index 00000000..4d5bac08
--- /dev/null
+++ b/qnetchess/src/CMakeLists.txt
@@ -0,0 +1,44 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+# (C) 2011-2012 Timothy Pearson
+# kb9vqf (AT) pearsoncomputing (DOT) net
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIR}
+)
+
+
+##### q15 #################################
+
+install( PROGRAMS
+ ${CMAKE_CURRENT_BINARY_DIR}/qnetchess
+ DESTINATION ${BIN_INSTALL_DIR} )
+
+
+set( target qnetchess )
+
+set( ${target}_SRCS
+ gameboard.cpp gamesocket.cpp main.cpp mainwindow.cpp
+)
+
+tde_add_executable( ${target} AUTOMOC
+ SOURCES ${${target}_SRCS}
+ LINK tqt-mt
+ DESTINATION ${BIN_INSTALL_DIR}
+)
diff --git a/qnetchess/src/gameboard.cpp b/qnetchess/src/gameboard.cpp
new file mode 100644
index 00000000..ca07e3b8
--- /dev/null
+++ b/qnetchess/src/gameboard.cpp
@@ -0,0 +1,1987 @@
+/*
+ * $Id: gameboard.cpp,v 1.1 2005/03/26 11:24:13 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ * Fixed the mate checker (big thanks to knyaz@RusNet)
+ */
+
+#include <ntqpainter.h>
+#include <ntqfontmetrics.h>
+#include <ntqmessagebox.h>
+#include <ntqcursor.h>
+#include <ntqfiledialog.h>
+#include <stdlib.h>
+
+#include "gameboard.h"
+#include "gamesocket.h"
+
+#include "xpm/black_bishop.xpm"
+#include "xpm/black_castle.xpm"
+#include "xpm/black_king.xpm"
+#include "xpm/black_knight.xpm"
+#include "xpm/black_pawn.xpm"
+#include "xpm/black_queen.xpm"
+#include "xpm/white_bishop.xpm"
+#include "xpm/white_castle.xpm"
+#include "xpm/white_king.xpm"
+#include "xpm/white_knight.xpm"
+#include "xpm/white_pawn.xpm"
+#include "xpm/white_queen.xpm"
+
+const int
+ cell_size = 40,
+ XSize = 640,
+ YSize = 480;
+
+TQColor cb, cw;
+
+bool
+Figure::hasMyFigure(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int x, int y, bool mirror)
+{
+ int n;
+ bool res;
+
+ n = map2map(gt, x, y, mirror);
+
+ if (gt == GameBoard::WHITE)
+ switch (map[n]) {
+ case GameBoard::DUMMY:
+ case GameBoard::WHITE_PAWN:
+ case GameBoard::WHITE_CASTLE:
+ case GameBoard::WHITE_BISHOP:
+ case GameBoard::WHITE_KING:
+ case GameBoard::WHITE_QUEEN:
+ case GameBoard::WHITE_KNIGHT:
+ res = TRUE;
+ break;
+ default:
+ res = FALSE;
+ }
+ else if (gt == GameBoard::BLACK)
+ switch (map[n]) {
+ case GameBoard::DUMMY:
+ case GameBoard::BLACK_PAWN:
+ case GameBoard::BLACK_CASTLE:
+ case GameBoard::BLACK_BISHOP:
+ case GameBoard::BLACK_KING:
+ case GameBoard::BLACK_QUEEN:
+ case GameBoard::BLACK_KNIGHT:
+ res = TRUE;
+ break;
+ default:
+ res = FALSE;
+ }
+ else
+ res = FALSE;
+
+ return (res);
+}
+
+
+int
+Figure::hasEnemyFigure(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int x, int y, bool mirror)
+{
+ int n;
+ int res;
+
+ n = map2map(gt, x, y, mirror);
+
+ if (gt == GameBoard::BLACK)
+ switch (map[n]) {
+ case GameBoard::WHITE_PAWN:
+ case GameBoard::WHITE_CASTLE:
+ case GameBoard::WHITE_BISHOP:
+ case GameBoard::WHITE_QUEEN:
+ case GameBoard::WHITE_KNIGHT:
+ res = 1;
+ break;
+ case GameBoard::WHITE_KING:
+ res = 2;
+ break;
+ case GameBoard::DUMMY:
+ default:
+ res = 0;
+ }
+ else if (gt == GameBoard::WHITE)
+ switch (map[n]) {
+ case GameBoard::BLACK_PAWN:
+ case GameBoard::BLACK_CASTLE:
+ case GameBoard::BLACK_BISHOP:
+ case GameBoard::BLACK_QUEEN:
+ case GameBoard::BLACK_KNIGHT:
+ res = 1;
+ break;
+ case GameBoard::BLACK_KING:
+ res = 2;
+ break;
+ case GameBoard::DUMMY:
+ default:
+ res = 0;
+ }
+ else
+ res = 0;
+
+ return (res);
+}
+
+
+bool
+Figure::hasFigure(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int x, int y, bool mirror)
+{
+ int n;
+
+ n = map2map(gt, x, y, mirror);
+
+ return (map[n] != GameBoard::NONE);
+}
+
+
+int
+Figure::map2map(GameBoard::GameType gt, int x, int y, bool mirror)
+{
+ int n = -1;
+
+ if (gt == GameBoard::WHITE)
+ if (mirror)
+ n = (y - 1) * 8 + (8 - x);
+ else
+ n = (8 - y) * 8 + (x - 1);
+ else if (gt == GameBoard::BLACK)
+ if (mirror)
+ n = (8 - y) * 8 + (x - 1);
+ else
+ n = (y - 1) * 8 + (8 - x);
+
+ return (n);
+}
+
+
+QString
+Figure::map2str(int x, int y)
+{
+ QString s;
+
+ s = TQString(TQChar('a' + x - 1)) + TQString::number(y);
+ return (s);
+}
+
+
+void
+Figure::str2map(const TQString &coo, int *x, int *y)
+{
+
+ *x = coo[0] - 'a' + 1;
+ *y = coo[1] - '0';
+}
+
+
+int
+Figure::validMove(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int fx, int fy, int tx, int ty, bool mirror)
+{
+ TQPointArray vl;
+ int res, f, t;
+
+ moveList(vl, gt, map, fx, fy, mirror);
+ res = hasPoint(vl, tx, ty);
+ f = map2map(gt, fx, fy, mirror);
+ switch (map[f]) {
+ case GameBoard::WHITE_PAWN:
+ if (res && (ty == 8))
+ res++;
+ break;
+ case GameBoard::BLACK_PAWN:
+ if (res && (ty == 1))
+ res++;
+ break;
+ default:;
+ }
+ if (res) {
+ t = map2map(gt, tx, ty, mirror);
+ map[t] = map[f];
+ map[f] = GameBoard::NONE;
+ if (mirror) {
+ vl.resize(0);
+ t = checkKing(gt, map, mirror, vl, FALSE);
+ switch (t) {
+ case 1:
+ res |= 0x10;
+ break;
+ case 2:
+ res |= 0x20;
+ break;
+ case 3:
+ res |= 0x40;
+ break;
+ default:;
+ }
+ }
+ }
+
+ return (res);
+}
+
+
+/*
+ * 0 - nothing
+ * 1 - check
+ * 2 - mate
+ * 3 - stalemate
+ */
+int
+Figure::checkKing(GameBoard::GameType gt, GameBoard::FigureType *map,
+ bool mirror, TQPointArray &vl, bool co)
+{
+ TQPointArray tmp;
+ GameBoard::FigureType myking, map1[64];
+ GameBoard::GameType mytype;
+ int res, x, y, p, xk, yk, pk;
+ bool hp;
+
+ if (gt == GameBoard::WHITE) {
+ myking = GameBoard::BLACK_KING;
+ mytype = GameBoard::BLACK;
+ } else if (gt == GameBoard::BLACK) {
+ myking = GameBoard::WHITE_KING;
+ mytype = GameBoard::WHITE;
+ } else {
+ myking = GameBoard::NONE;
+ mytype = GameBoard::NOGAME;
+ }
+ xk = yk = -1;
+ res = 0; p = -1;
+
+ for (y = 1; y < 9; ++y)
+ for (x = 1; x < 9; ++x)
+ /* check enemy figures */
+ if (hasMyFigure(gt, map, x, y, mirror))
+ moveList(vl, gt, map, x, y, mirror);
+ else if (p == -1) {
+ p = map2map(mytype, x, y, !mirror);
+ if (map[p] == myking) {
+ xk = x;
+ yk = y;
+ } else
+ p = -1;
+ }
+
+ hp = hasPoint(vl, xk, yk);
+ if (hp) {
+ res++;
+ if (!co) {
+ vl.resize(0);
+ for (y = 1; y < 9; ++y)
+ for (x = 1; x < 9; ++x)
+ if (hasMyFigure(mytype, map,
+ x, y, !mirror))
+ moveList(vl, mytype, map,
+ x, y, !mirror);
+ memmove(map1, map, sizeof(map1));
+ pk = map2map(mytype, xk, yk, !mirror);
+ for (x = vl.size() - 1; x >= 0; --x) {
+ p = map2map(mytype, vl.point(x).x(),
+ vl.point(x).y(), !mirror);
+ if (p != pk)
+ map1[p] = GameBoard::DUMMY;
+ }
+ if (checkKing(gt, map1, mirror, vl, TRUE) != 0) {
+ vl.resize(0);
+ moveListKing(vl, mytype, map, xk, yk, !mirror);
+ memmove(map1, map, sizeof(map1));
+ for (y = 0, x = vl.size() - 1; x >= 0; --x) {
+ p = map2map(mytype, vl.point(x).x(),
+ vl.point(x).y(), !mirror);
+ map1[p] = myking;
+ map1[pk] = GameBoard::NONE;
+ if (checkKing(gt, map1, mirror,
+ tmp, TRUE) == 1)
+ ++y;
+ map1[pk] = map[pk];
+ map1[p] = map[p];
+ }
+ if (y == (int)vl.size())
+ res++;
+ }
+ }
+ } else if (!co) {
+ vl.resize(0);
+ for (y = 1; y < 9; ++y)
+ for (x = 1; x < 9; ++x)
+ if (hasMyFigure(mytype, map, x, y, !mirror))
+ moveList(vl, mytype, map, x, y,
+ !mirror);
+ if (vl.size() == 0)
+ res = 3;
+ }
+
+ return (res);
+}
+
+
+void
+Figure::moveList(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+ int n;
+
+ n = map2map(gt, x, y, mirror);
+ switch (map[n]) {
+ case GameBoard::WHITE_PAWN:
+ moveListWhitePawn(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::WHITE_CASTLE:
+ case GameBoard::BLACK_CASTLE:
+ moveListCastle(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::WHITE_BISHOP:
+ case GameBoard::BLACK_BISHOP:
+ moveListBishop(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::WHITE_KING:
+ case GameBoard::BLACK_KING:
+ moveListKing(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::WHITE_QUEEN:
+ case GameBoard::BLACK_QUEEN:
+ moveListQueen(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::WHITE_KNIGHT:
+ case GameBoard::BLACK_KNIGHT:
+ moveListKnight(vl, gt, map, x, y, mirror);
+ break;
+
+ case GameBoard::BLACK_PAWN:
+ moveListBlackPawn(vl, gt, map, x, y, mirror);
+ break;
+
+
+ default:;
+ }
+}
+
+
+void
+Figure::moveListWhitePawn(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+
+ if (validPoint(gt, map, x, y + 1, mirror) &&
+ !hasFigure(gt, map, x, y + 1, mirror)) {
+ vl.putPoints(vl.size(), 1, x, y + 1);
+ if ((y == 2) && validPoint(gt, map, x, y + 2, mirror))
+ vl.putPoints(vl.size(), 1, x, y + 2);
+ }
+ if (validPoint(gt, map, x + 1, y + 1, mirror) &&
+ hasEnemyFigure(gt, map, x + 1, y + 1, mirror))
+ vl.putPoints(vl.size(), 1, x + 1, y + 1);
+ if (validPoint(gt, map, x - 1, y + 1, mirror) &&
+ hasEnemyFigure(gt, map, x - 1, y + 1, mirror))
+ vl.putPoints(vl.size(), 1, x - 1, y + 1);
+}
+
+
+void
+Figure::moveListBlackPawn(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+
+ if (validPoint(gt, map, x, y - 1, mirror) &&
+ !hasFigure(gt, map, x, y - 1, mirror)) {
+ vl.putPoints(vl.size(), 1, x, y - 1);
+ if ((y == 7) && validPoint(gt, map, x, y - 2, mirror))
+ vl.putPoints(vl.size(), 1, x, y - 2);
+ }
+ if (validPoint(gt, map, x + 1, y - 1, mirror) &&
+ hasEnemyFigure(gt, map, x + 1, y - 1, mirror))
+ vl.putPoints(vl.size(), 1, x + 1, y - 1);
+ if (validPoint(gt, map, x - 1, y - 1, mirror) &&
+ hasEnemyFigure(gt, map, x - 1, y - 1, mirror))
+ vl.putPoints(vl.size(), 1, x - 1, y - 1);
+}
+
+
+void
+Figure::moveListCastle(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+ int i;
+
+ for (i = x + 1; i < 9; i++) {
+ if (!hasFigure(gt, map, i, y, mirror)) {
+ vl.putPoints(vl.size(), 1, i, y);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, y, mirror))
+ vl.putPoints(vl.size(), 1, i, y);
+ break;
+ }
+ for (i = x - 1; i > 0; i--) {
+ if (!hasFigure(gt, map, i, y, mirror)) {
+ vl.putPoints(vl.size(), 1, i, y);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, y, mirror))
+ vl.putPoints(vl.size(), 1, i, y);
+ break;
+ }
+ for (i = y + 1; i < 9; i++) {
+ if (!hasFigure(gt, map, x, i, mirror)) {
+ vl.putPoints(vl.size(), 1, x, i);
+ continue;
+ } else if (hasEnemyFigure(gt, map, x, i, mirror))
+ vl.putPoints(vl.size(), 1, x, i);
+ break;
+ }
+ for (i = y - 1; i > 0; i--) {
+ if (!hasFigure(gt, map, x, i, mirror)) {
+ vl.putPoints(vl.size(), 1, x, i);
+ continue;
+ } else if (hasEnemyFigure(gt, map, x, i, mirror))
+ vl.putPoints(vl.size(), 1, x, i);
+ break;
+ }
+}
+
+
+void
+Figure::moveListBishop(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+ int i, j;
+
+ for (i = x + 1, j = y + 1; (i < 9) && (j < 9); i++, j++) {
+ if (!hasFigure(gt, map, i, j, mirror)) {
+ vl.putPoints(vl.size(), 1, i, j);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, j, mirror))
+ vl.putPoints(vl.size(), 1, i, j);
+ break;
+ }
+ for (i = x - 1, j = y + 1; (i > 0) && (j < 9); i--, j++) {
+ if (!hasFigure(gt, map, i, j, mirror)) {
+ vl.putPoints(vl.size(), 1, i, j);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, j, mirror))
+ vl.putPoints(vl.size(), 1, i, j);
+ break;
+ }
+ for (i = x - 1, j = y - 1; (i > 0) && (j > 0); i--, j--) {
+ if (!hasFigure(gt, map, i, j, mirror)) {
+ vl.putPoints(vl.size(), 1, i, j);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, j, mirror))
+ vl.putPoints(vl.size(), 1, i, j);
+ break;
+ }
+ for (i = x + 1, j = y - 1; (i < 9) && (j > 0); i++, j--) {
+ if (!hasFigure(gt, map, i, j, mirror)) {
+ vl.putPoints(vl.size(), 1, i, j);
+ continue;
+ } else if (hasEnemyFigure(gt, map, i, j, mirror))
+ vl.putPoints(vl.size(), 1, i, j);
+ break;
+ }
+}
+
+
+void
+Figure::moveListKing(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+ int x1, x2, y1, y2;
+
+ x1 = x - 1; x2 = x + 1;
+ y1 = y - 1; y2 = y + 1;
+ if (validPoint(gt, map, x1, y2, mirror) &&
+ !hasKingsMeeting(gt, map, x1, y2, mirror))
+ vl.putPoints(vl.size(), 1, x1, y2);
+ if (validPoint(gt, map, x, y2, mirror) &&
+ !hasKingsMeeting(gt, map, x, y2, mirror))
+ vl.putPoints(vl.size(), 1, x, y2);
+ if (validPoint(gt, map, x2, y2, mirror) &&
+ !hasKingsMeeting(gt, map, x2, y2, mirror))
+ vl.putPoints(vl.size(), 1, x2, y2);
+ if (validPoint(gt, map, x1, y, mirror) &&
+ !hasKingsMeeting(gt, map, x1, y, mirror))
+ vl.putPoints(vl.size(), 1, x1, y);
+ if (validPoint(gt, map, x2, y, mirror) &&
+ !hasKingsMeeting(gt, map, x2, y, mirror))
+ vl.putPoints(vl.size(), 1, x2, y);
+ if (validPoint(gt, map, x1, y1, mirror) &&
+ !hasKingsMeeting(gt, map, x1, y1, mirror))
+ vl.putPoints(vl.size(), 1, x1, y1);
+ if (validPoint(gt, map, x, y1, mirror) &&
+ !hasKingsMeeting(gt, map, x, y1, mirror))
+ vl.putPoints(vl.size(), 1, x, y1);
+ if (validPoint(gt, map, x2, y1, mirror) &&
+ !hasKingsMeeting(gt, map, x2, y1, mirror))
+ vl.putPoints(vl.size(), 1, x2, y1);
+}
+
+
+void
+Figure::moveListQueen(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+
+ moveListBishop(vl, gt, map, x, y, mirror);
+ moveListCastle(vl, gt, map, x, y, mirror);
+}
+
+
+void
+Figure::moveListKnight(TQPointArray &vl, GameBoard::GameType gt,
+ GameBoard::FigureType *map, int x, int y, bool mirror)
+{
+ int x1, x2, x3, x4,
+ y1, y2, y3, y4;
+
+ x1 = x + 1;
+ x2 = x1 + 1;
+ x3 = x - 1;
+ x4 = x3 - 1;
+ y1 = y + 1;
+ y2 = y1 + 1;
+ y3 = y - 1;
+ y4 = y3 - 1;
+ if (validPoint(gt, map, x3, y2, mirror))
+ vl.putPoints(vl.size(), 1, x3, y2);
+ if (validPoint(gt, map, x1, y2, mirror))
+ vl.putPoints(vl.size(), 1, x1, y2);
+ if (validPoint(gt, map, x4, y1, mirror))
+ vl.putPoints(vl.size(), 1, x4, y1);
+ if (validPoint(gt, map, x2, y1, mirror))
+ vl.putPoints(vl.size(), 1, x2, y1);
+ if (validPoint(gt, map, x4, y3, mirror))
+ vl.putPoints(vl.size(), 1, x4, y3);
+ if (validPoint(gt, map, x2, y3, mirror))
+ vl.putPoints(vl.size(), 1, x2, y3);
+ if (validPoint(gt, map, x3, y4, mirror))
+ vl.putPoints(vl.size(), 1, x3, y4);
+ if (validPoint(gt, map, x1, y4, mirror))
+ vl.putPoints(vl.size(), 1, x1, y4);
+}
+
+
+bool
+Figure::hasKingsMeeting(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int x, int y, bool mirror)
+{
+ int x1, x2, y1, y2;
+ bool res;
+
+ x1 = x - 1; x2 = x + 1;
+ y1 = y - 1; y2 = y + 1;
+ res = FALSE;
+
+ if (validPoint(gt, map, x1, y2, mirror))
+ res = (hasEnemyFigure(gt, map, x1, y2, mirror) == 2);
+ if (! res && validPoint(gt, map, x, y2, mirror))
+ res = (hasEnemyFigure(gt, map, x, y2, mirror) == 2);
+ if (!res && validPoint(gt, map, x2, y2, mirror))
+ res = (hasEnemyFigure(gt, map, x2, y2, mirror) == 2);
+ if (!res && validPoint(gt, map, x1, y, mirror))
+ res = (hasEnemyFigure(gt, map, x1, y, mirror) == 2);
+ if (!res && validPoint(gt, map, x2, y, mirror))
+ res = (hasEnemyFigure(gt, map, x2, y, mirror) == 2);
+ if (!res && validPoint(gt, map, x1, y1, mirror))
+ res = (hasEnemyFigure(gt, map, x1, y1, mirror) == 2);
+ if (!res && validPoint(gt, map, x, y1, mirror))
+ res = (hasEnemyFigure(gt, map, x, y1, mirror) == 2);
+ if (!res && validPoint(gt, map, x2, y1, mirror))
+ res = (hasEnemyFigure(gt, map, x2, y1, mirror) == 2);
+
+ return (res);
+}
+
+
+bool
+Figure::hasPoint(const TQPointArray &vl, int x, int y)
+{
+ int i, xp, yp, cnt;
+ bool res = FALSE;
+
+ cnt = vl.count();
+ for (i = 0; i < cnt; ++i) {
+ vl.point(i, &xp, &yp);
+ if ((xp == x) && (yp == y)) {
+ res = TRUE;
+ break;
+ }
+ }
+
+ return (res);
+}
+
+
+bool
+Figure::validPoint(GameBoard::GameType gt, GameBoard::FigureType *map,
+ int x, int y, bool mirror)
+{
+ bool res;
+
+ res = ((x >0) && (x < 9) && (y >0) && (y < 9));
+ if (res)
+ res = !hasMyFigure(gt, map, x, y, mirror);
+
+ return (res);
+}
+
+//-----------------------------------------------------------------------------
+
+GameBoard::GameBoard(GameType g, const TQString &h, TQWidget *parent,
+ const char *name)
+ :TQWidget(parent, name, TQt::WResizeNoErase |
+ TQt::WRepaintNoErase | TQt::WDestructiveClose)
+{
+ TQString str;
+
+ gt = g; hst = h;
+ setCursor(TQCursor(TQt::WaitCursor));
+ if (gt == WHITE)
+ str = tr("White");
+ else if (gt == BLACK)
+ str = tr("Black");
+ str += ' ' + tr("game with") + ' ';
+ setCaption(str + hst);
+ setIcon(TQPixmap((const char **)white_knight));
+ map = new FigureType[64];
+ initMap();
+
+ sock = new TQSocket(this);
+ drw = new Drawer(map, &gt, this);
+ drw->setEnabled(FALSE);
+ drw->setFocusPolicy(NoFocus);
+ box = new TQGroupBox(tr("Game chat"), this);
+ lst = new TQListBox(box);
+ lst->setFocusPolicy(NoFocus);
+ lst->setVScrollBarMode(TQScrollView::AlwaysOff);
+ lst->setSelectionMode(TQListBox::NoSelection);
+ edt = new TQLineEdit(box);
+ edt->setEnabled(FALSE);
+ setFocusProxy(edt);
+ hist = new TQGroupBox(tr("History"), this);
+ hist->setAlignment(TQt::AlignHCenter);
+ hist->setFocusPolicy(NoFocus);
+ hw = new TQListBox(hist);
+ hw->setSelectionMode(TQListBox::NoSelection);
+ hw->setPaletteBackgroundColor(cw);
+ hb = new TQListBox(hist);
+ hb->setSelectionMode(TQListBox::NoSelection);
+ hb->setPaletteBackgroundColor(cb);
+ tmr = new TQTimer(this);
+ sock_tout = SOCK_WAIT;
+ my_stat = tr("Looking up the host") + ' ' + hst + "...";
+ TQObject::connect(sock, SIGNAL(hostFound()),
+ this, SLOT(showHostFound()));
+ TQObject::connect(sock, SIGNAL(connected()),
+ this, SLOT(sockConnected()));
+ TQObject::connect(sock, SIGNAL(readyRead()),
+ this, SLOT(sockRead()));
+ TQObject::connect(sock, SIGNAL(connectionClosed()),
+ this, SLOT(sockClosed()));
+ TQObject::connect(sock, SIGNAL(error(int)),
+ this, SLOT(sockError(int)));
+ TQObject::connect(drw, SIGNAL(moved(const TQString&)),
+ this, SLOT(sendMove(const TQString&)));
+ TQObject::connect(drw, SIGNAL(newFigure(const TQString&,
+ GameBoard::FigureType)),
+ this, SLOT(sendFigure(const TQString&, GameBoard::FigureType)));
+ TQObject::connect(drw, SIGNAL(gameover(int)),
+ this, SLOT(gameover(int)));
+ TQObject::connect(edt, SIGNAL(returnPressed()),
+ this, SLOT(sendText()));
+ TQObject::connect(tmr, SIGNAL(timeout()), this, SLOT(sockTest()));
+
+ resize(XSize, YSize);
+ setMinimumSize(size());
+ setMaximumSize(size());
+ sock->connectToHost(hst, GAME_PORT);
+ tmr->start(1000);
+}
+
+GameBoard::GameBoard(int sfd, TQWidget *parent, const char *name)
+ :TQWidget(parent, name, TQt::WResizeNoErase | TQt::WRepaintNoErase |
+ TQt::WDestructiveClose)
+{
+
+ gt = NOGAME;
+ setCursor(TQCursor(TQt::WaitCursor));
+ setIcon(TQPixmap((const char **)white_knight));
+ map = new FigureType[64];
+ memset(map, NONE, 64 * sizeof(*map));
+
+ sock = new TQSocket(this);
+ drw = new Drawer(map, &gt, this);
+ drw->setEnabled(FALSE);
+ drw->setFocusPolicy(NoFocus);
+ box = new TQGroupBox(tr("Game chat"), this);
+ lst = new TQListBox(box);
+ lst->setFocusPolicy(NoFocus);
+ lst->setVScrollBarMode(TQScrollView::AlwaysOff);
+ lst->setSelectionMode(TQListBox::NoSelection);
+ edt = new TQLineEdit(box);
+ setFocusProxy(edt);
+ hist = new TQGroupBox(tr("History"), this);
+ hist->setAlignment(TQt::AlignHCenter);
+ hist->setFocusPolicy(NoFocus);
+ hw = new TQListBox(hist);
+ hw->setSelectionMode(TQListBox::NoSelection);
+ hw->setPaletteBackgroundColor(cw);
+ hb = new TQListBox(hist);
+ hb->setSelectionMode(TQListBox::NoSelection);
+ hb->setPaletteBackgroundColor(cb);
+ tmr = new TQTimer(this);
+ sock->setSocket(sfd);
+ sock_tout = SOCK_WAIT;
+ my_stat = tr("Accepted a new connection");
+ TQObject::connect(sock, SIGNAL(hostFound()),
+ this, SLOT(showHostFound()));
+ TQObject::connect(sock, SIGNAL(connected()),
+ this, SLOT(sockConnected()));
+ TQObject::connect(sock, SIGNAL(readyRead()),
+ this, SLOT(sockRead()));
+ TQObject::connect(sock, SIGNAL(connectionClosed()),
+ this, SLOT(sockClosed()));
+ TQObject::connect(sock, SIGNAL(error(int)),
+ this, SLOT(sockError(int)));
+ TQObject::connect(drw, SIGNAL(moved(const TQString&)),
+ this, SLOT(sendMove(const TQString&)));
+ TQObject::connect(drw, SIGNAL(newFigure(const TQString&,
+ GameBoard::FigureType)),
+ this, SLOT(sendFigure(const TQString&, GameBoard::FigureType)));
+ TQObject::connect(drw, SIGNAL(gameover(int)),
+ this, SLOT(gameover(int)));
+ TQObject::connect(edt, SIGNAL(returnPressed()),
+ this, SLOT(sendText()));
+ TQObject::connect(tmr, SIGNAL(timeout()), this, SLOT(sockTest()));
+ resize(XSize, YSize);
+ setMinimumSize(size());
+ setMaximumSize(size());
+ tmr->start(1000);
+}
+
+GameBoard::~GameBoard()
+{
+
+ GameProtocol::sendQuit(sock);
+ delete tmr;
+ delete hb;
+ delete hw;
+ delete hist;
+ delete edt;
+ delete lst;
+ delete box;
+ delete drw;
+ delete sock;
+ delete map;
+}
+
+
+void
+GameBoard::resizeEvent(TQResizeEvent *e)
+{
+ TQFontMetrics fm(font());
+ int w = e->size().width(),
+ h = e->size().height(),
+ fh = fm.lineSpacing() + 4;
+
+ TQWidget::resizeEvent(e);
+ drw->move(0, 0);
+ box->move(drw->x(), drw->y() + drw->height());
+ box->resize(w, h - box->y());
+ edt->move(2, box->height() - fh - 2);
+ edt->resize(box->width() - edt->x() * 2, fh);
+ lst->move(edt->x(), fm.lineSpacing());
+ lst->resize(edt->width(), edt->y() - lst->y());
+ hist->move(drw->x() + drw->width(), drw->y());
+ hist->resize(w - hist->x(), box->y());
+ hw->move(2, TQFontMetrics(hist->font()).lineSpacing());
+ hw->resize((hist->width() - hw->x()) / 2,
+ hist->height() - hw->y() - 2);
+ hb->move(hw->x() + hw->width(), hw->y());
+ hb->resize(hw->size());
+}
+
+
+void
+GameBoard::focusInEvent(TQFocusEvent *e)
+{
+
+ TQWidget::focusInEvent(e);
+ emit showStatus(my_stat);
+}
+
+
+void
+GameBoard::initMap()
+{
+
+ memset(map, NONE, 64 * sizeof(*map));
+ if (gt == WHITE) {
+ map[0] = BLACK_CASTLE;
+ map[1] = BLACK_KNIGHT;
+ map[2] = BLACK_BISHOP;
+ map[3] = BLACK_QUEEN;
+ map[4] = BLACK_KING;
+ map[5] = BLACK_BISHOP;
+ map[6] = BLACK_KNIGHT;
+ map[7] = BLACK_CASTLE;
+ map[8] = BLACK_PAWN;
+ map[9] = BLACK_PAWN;
+ map[10] = BLACK_PAWN;
+ map[11] = BLACK_PAWN;
+ map[12] = BLACK_PAWN;
+ map[13] = BLACK_PAWN;
+ map[14] = BLACK_PAWN;
+ map[15] = BLACK_PAWN;
+ map[48] = WHITE_PAWN;
+ map[49] = WHITE_PAWN;
+ map[50] = WHITE_PAWN;
+ map[51] = WHITE_PAWN;
+ map[52] = WHITE_PAWN;
+ map[53] = WHITE_PAWN;
+ map[54] = WHITE_PAWN;
+ map[55] = WHITE_PAWN;
+ map[56] = WHITE_CASTLE;
+ map[57] = WHITE_KNIGHT;
+ map[58] = WHITE_BISHOP;
+ map[59] = WHITE_QUEEN;
+ map[60] = WHITE_KING;
+ map[61] = WHITE_BISHOP;
+ map[62] = WHITE_KNIGHT;
+ map[63] = WHITE_CASTLE;
+ } else {
+ map[0] = WHITE_CASTLE;
+ map[1] = WHITE_KNIGHT;
+ map[2] = WHITE_BISHOP;
+ map[3] = WHITE_KING;
+ map[4] = WHITE_QUEEN;
+ map[5] = WHITE_BISHOP;
+ map[6] = WHITE_KNIGHT;
+ map[7] = WHITE_CASTLE;
+ map[8] = WHITE_PAWN;
+ map[9] = WHITE_PAWN;
+ map[10] = WHITE_PAWN;
+ map[11] = WHITE_PAWN;
+ map[12] = WHITE_PAWN;
+ map[13] = WHITE_PAWN;
+ map[14] = WHITE_PAWN;
+ map[15] = WHITE_PAWN;
+ map[48] = BLACK_PAWN;
+ map[49] = BLACK_PAWN;
+ map[50] = BLACK_PAWN;
+ map[51] = BLACK_PAWN;
+ map[52] = BLACK_PAWN;
+ map[53] = BLACK_PAWN;
+ map[54] = BLACK_PAWN;
+ map[55] = BLACK_PAWN;
+ map[56] = BLACK_CASTLE;
+ map[57] = BLACK_KNIGHT;
+ map[58] = BLACK_BISHOP;
+ map[59] = BLACK_KING;
+ map[60] = BLACK_QUEEN;
+ map[61] = BLACK_BISHOP;
+ map[62] = BLACK_KNIGHT;
+ map[63] = BLACK_CASTLE;
+ }
+}
+
+
+void
+GameBoard::showHostFound()
+{
+
+ my_stat = tr("The host found");
+ emit showStatus(my_stat);
+}
+
+
+void
+GameBoard::sockConnected()
+{
+
+ my_stat = tr("Connected to the host");
+ emit showStatus(my_stat);
+ GameProtocol::setGameType(sock, gt);
+ edt->setEnabled(TRUE);
+}
+
+
+void
+GameBoard::sockRead()
+{
+ TQString str;
+
+ if (sock->canReadLine()) {
+ str = sock->readLine();
+ str.remove(EOL);
+ str.remove('\r');
+ parseString(str);
+ sock_tout = SOCK_WAIT;
+ }
+}
+
+
+void
+GameBoard::sockClosed()
+{
+
+ close();
+}
+
+
+void
+GameBoard::sockError(int err)
+{
+ TQString e;
+
+ TQMessageBox::critical(this, tr("Socket Error..."),
+ tr("You have a socket error number") + ' ' +
+ TQString::number(err));
+}
+
+
+void
+GameBoard::parseString(const TQString &str)
+{
+ TQStringList lst(TQStringList::split(SEP, str));
+ TQString s(lst[0].lower());
+ int id;
+
+ if (s == "game") {
+ s = lst[1].lower();
+ if (s == "mate") {
+ updateHistory(GAMEOVER_TXT, TRUE);
+ gt = NOGAME;
+ gameover(0);
+ close();
+ } else if (s == "stalemate") {
+ gt = NOGAME;
+ gameover(3);
+ close();
+ } else if (s != "accept") {
+ if (s == "white") {
+ gt = BLACK;
+ s = tr("White");
+ } else if (s == "black") {
+ gt = WHITE;
+ s = tr("Black");
+ drw->setEnabled(TRUE);
+ setCursor(TQCursor(TQt::ArrowCursor));
+ }
+ s += ' ' + tr("game from") + ' ';
+ my_stat = tr("Accepted the") + ' ' + s;
+ hst = sock->peerName();
+ if (hst.isEmpty())
+ hst = sock->peerAddress().toString() + ':' +
+ TQString::number(sock->peerPort());
+ initMap();
+ drw->repaint(TRUE);
+ GameProtocol::acceptGame(sock);
+ setCaption(s + hst);
+ my_stat += hst;
+ emit showStatus(my_stat);
+ } else if (gt == WHITE) {
+ drw->setEnabled(TRUE);
+ setCursor(TQCursor(TQt::ArrowCursor));
+ }
+ } else if (s == "move") {
+ if (!drw->isEnabled()) {
+ drw->setEnabled(TRUE);
+ s = lst[1].lower();
+ updateHistory(s, TRUE);
+ drw->makeMove(s);
+ setCursor(TQCursor(TQt::ArrowCursor));
+ my_stat = tr("Your move...");
+ emit showStatus(my_stat);
+ }
+ } else if (s == "quit") {
+ gt = NOGAME;
+ sockClosed();
+ } else if (s == "chat") {
+ s = str.right(str.length() - 5);
+ updateChat('>' + s);
+ } else if (s == "figure") {
+ s = lst[1].lower();
+ id = lst[2].toInt();
+ drw->newFigure(s, id);
+ updateHistory(id, TRUE);
+ }
+}
+
+
+void
+GameBoard::sendMove(const TQString &str)
+{
+
+ GameProtocol::sendMove(sock, str);
+ drw->setEnabled(FALSE);
+ setCursor(TQCursor(TQt::WaitCursor));
+ updateHistory(str, FALSE);
+ sock_tout = SOCK_WAIT;
+ my_stat = tr("Waiting a move...");
+ emit showStatus(my_stat);
+}
+
+
+void
+GameBoard::closeEvent(TQCloseEvent *e)
+{
+ int res;
+
+ if (gt != NOGAME) {
+ res = TQMessageBox::question(this, tr("End the game"),
+ tr("Want you to end the game?\nYou will lose it"),
+ tr("Yes, end"), tr("No, continue"), TQString::null, 1);
+ if (res == 0)
+ TQWidget::closeEvent(e);
+ } else
+ TQWidget::closeEvent(e);
+}
+
+
+void
+GameBoard::sendText()
+{
+ TQString s;
+
+ s = edt->text().utf8();
+ if (!s.isEmpty()) {
+ updateChat(s);
+ GameProtocol::sendText(sock, s.ascii());
+ }
+ edt->clear();
+}
+
+
+void
+GameBoard::updateChat(const TQString &s)
+{
+ int fh, h;
+
+ lst->insertItem(TQString::fromUtf8(s.ascii()));
+ h = lst->height();
+ fh = TQFontMetrics(lst->font()).lineSpacing();
+ if ((int)lst->count() * fh >= lst->visibleHeight())
+ lst->removeItem(0);
+}
+
+
+void
+GameBoard::updateHistory(const TQString &st, bool t)
+{
+ TQString s;
+
+ if (st.length() == 3) {
+ if (st[0] == '@')
+ s = "O-O";
+ else
+ s = st;
+ } else
+ s = st.left(2) + " - " + st.right(2);
+ if (t) {
+ if (gt == WHITE)
+ hb->insertItem(s);
+ else if (gt == BLACK)
+ hw->insertItem(s);
+ } else {
+ if (gt == WHITE)
+ hw->insertItem(s);
+ else if (gt == BLACK)
+ hb->insertItem(s);
+ }
+}
+
+
+void
+GameBoard::updateHistory(int id, bool t)
+{
+ TQString s("; "), s1;
+
+ switch (id) {
+ case 3:
+ s += tr("B");
+ break;
+ case 4:
+ s += tr("K");
+ break;
+ case 5:
+ s += tr("C");
+ break;
+ case 10:
+ s += tr("Q");
+ break;
+ default:
+ s += tr("Error!");
+ }
+ if (t) {
+ if (gt == WHITE) {
+ id = hb->count() - 1;
+ s1 = hb->text(id);
+ hb->changeItem(s1 + s, id);
+ } else if (gt == BLACK) {
+ id = hw->count() - 1;
+ s1 = hw->text(id);
+ hw->changeItem(s1 + s, id);
+ }
+ } else {
+ if (gt == WHITE) {
+ id = hw->count() - 1;
+ s1 = hw->text(id);
+ hw->changeItem(s1 + s, id);
+ } else if (gt == BLACK) {
+ id = hb->count() - 1;
+ s1 = hb->text(id);
+ hb->changeItem(s1 + s, id);
+ }
+ }
+}
+
+
+void
+GameBoard::sendFigure(const TQString &coo, GameBoard::FigureType ft)
+{
+ int id = -1;
+
+ switch (ft) {
+ case BLACK_CASTLE:
+ case WHITE_CASTLE:
+ id = 5;
+ break;
+
+ case BLACK_BISHOP:
+ case WHITE_BISHOP:
+ id = 3;
+ break;
+
+ case BLACK_KNIGHT:
+ case WHITE_KNIGHT:
+ id = 4;
+ break;
+
+ case BLACK_QUEEN:
+ case WHITE_QUEEN:
+ id = 10;
+ break;
+ default:
+ id = -1;
+ }
+ if (id != -1) {
+ GameProtocol::sendFigure(sock, coo, id);
+ updateHistory(id, FALSE);
+ }
+}
+
+
+void
+GameBoard::sockTest()
+{
+
+ --sock_tout;
+ if (sock_tout < 0) {
+ tmr->stop();
+ HAXEP:
+ gt = NOGAME;
+ sockClosed();
+ } else if ((sock->state() == TQSocket::HostLookup) &&
+ (sock_tout + 60 < SOCK_WAIT)) {
+ tmr->stop();
+ TQMessageBox::critical(this, tr("Lookup Error"),
+ tr("The host") + ' ' + hst + ' ' + tr("not found."));
+ goto HAXEP;
+ }
+
+}
+
+
+void
+GameBoard::saveImage()
+{
+ TQString fn;
+
+ fn = TQFileDialog::getSaveFileName(TQString::null, "*.png", this, NULL,
+ tr("Save image"));
+
+ if (!fn.isEmpty()) {
+ if (fn.findRev(".png") < (int)(fn.length() - 4))
+ fn += ".png";
+ TQPixmap::grabWidget(this).save(fn, "PNG");
+ }
+}
+
+
+void
+GameBoard::gameover(int type)
+{
+ bool save = FALSE;
+
+ TQString s('\n' + tr("Do you want to save the image?")),
+ yes(tr("Yes, save")),
+ no(tr("No, don't save")),
+ go(tr("Game over"));
+
+ if (type == 0) {
+ save = (TQMessageBox::question(this, go,
+ tr("You scored the game") + s, yes, no) == 0);
+ } else if (type == 2) {
+ updateHistory(GAMEOVER_TXT, FALSE);
+ GameProtocol::sendGameover(sock, "MATE");
+ save = (TQMessageBox::question(this, go,
+ tr("You have a mate.\nYou lost the game.") + s,
+ yes, no) == 0);
+ } else if (type == 3) {
+ GameProtocol::sendGameover(sock, "STALEMATE");
+ save = (TQMessageBox::question(this, go,
+ tr("You have a stalemate") + s, yes, no) == 0);
+ }
+
+ if (save)
+ saveImage();
+}
+
+//-----------------------------------------------------------------------------
+
+Drawer::Drawer(GameBoard::FigureType *ft, GameBoard::GameType *g,
+ TQWidget *parent, const char *name)
+ :TQWidget(parent, name, TQt::WResizeNoErase | TQt::WRepaintNoErase)
+{
+ TQFontMetrics fm(font());
+ int i;
+
+ map = ft; gt = g;
+ kk = rcm = lcm = km = FALSE;
+ cs = cell_size * 8;
+ top_margin = 5;
+ for (left_margin = 0, i = 0; i < 8; i++)
+ left_margin = MAX(fm.width(QString::number(i)), left_margin);
+ left_margin += top_margin;
+ hl = fm.lineSpacing() + 2;
+ setPaletteBackgroundColor(TQt::white);
+ i = MAX(cs + left_margin + top_margin, cs + top_margin + hl);
+ resize(i, i);
+ x_brd = i - cs - 6;
+ y_brd = 4;
+ tfx = tfy = -1;
+ fig[0] = TQPixmap((const char **)black_bishop);
+ fig[1] = TQPixmap((const char **)black_castle);
+ fig[2] = TQPixmap((const char **)black_knight);
+ fig[3] = TQPixmap((const char **)black_pawn);
+ fig[4] = TQPixmap((const char **)black_king);
+ fig[5] = TQPixmap((const char **)black_queen);
+ fig[6] = TQPixmap((const char **)white_bishop);
+ fig[7] = TQPixmap((const char **)white_castle);
+ fig[8] = TQPixmap((const char **)white_knight);
+ fig[9] = TQPixmap((const char **)white_pawn);
+ fig[10] = TQPixmap((const char **)white_king);
+ fig[11] = TQPixmap((const char **)white_queen);
+}
+
+Drawer::~Drawer()
+{
+}
+
+
+void
+Drawer::paintEvent(TQPaintEvent *e)
+{
+ TQPainter *p;
+ int w, y;
+
+ w = width();
+ y = w - 4;
+ TQWidget::paintEvent(e);
+ p = new TQPainter(this);
+ p->setPen(TQt::black);
+ p->drawRect(0, 0, w, w);
+ p->drawRect(2, 2, y, y);
+ p->drawLine(2, y, x_brd, cs + 4);
+ drawBoard(p, x_brd, y_brd);
+ drawMap(p, x_brd, y_brd);
+ delete p;
+}
+
+
+void
+Drawer::drawBoard(TQPainter *p, int x, int y)
+{
+ int i, j, cs, x1, r, k;
+ char c, st;
+
+ cs = Drawer::cs + 2;
+ p->setPen(TQt::black);
+ p->drawRect(x, y, cs, cs);
+ c = 'a'; st = 1;
+ r = (*gt == GameBoard::BLACK);
+ if (r) {
+ c += 7;
+ st = -st;
+ k = 1;
+ r ^= 1;
+ } else
+ k = 8;
+ x1 = x + 1;
+ for (j = 0, y++; j < 8; j++, y += cell_size, r ^= 1) {
+ for (i = 0, x = x1; i < 8; i++, x += cell_size) {
+ r ^= 1;
+ if (r) {
+ p->setPen(cw);
+ p->setBrush(cw);
+ } else {
+ p->setPen(cb);
+ p->setBrush(cb);
+ }
+ p->drawRect(x, y, cell_size, cell_size);
+ if (j == 7) {
+ p->setPen(Qt::black);
+ p->drawText(x, cs + 2, cell_size, hl,
+ TQt::AlignCenter, TQChar(c));
+ c += st;
+ }
+ }
+ p->setPen(TQt::black);
+ p->drawText(x1 - left_margin, y, left_margin, cell_size,
+ TQt::AlignCenter, TQString::number(k));
+ k -= st;
+ }
+ if ((tfx != -1) && (tfy != -1)) {
+ map2win(tfx, tfy, x, y);
+ p->setPen(TQPen(TQt::red, 2));
+ p->setBrush(TQt::NoBrush);
+ p->drawRect(x, y, cell_size, cell_size);
+ }
+}
+
+
+void
+Drawer::drawMap(TQPainter *p, int x, int y)
+{
+ int i, j, x1, n;
+ TQPixmap *xpm;
+
+ x1 = x + 1; y++;
+ for (n = j = 0; j < 8; j++, y += cell_size) {
+ for (i = 0, x = x1; i < 8; i++, x += cell_size) {
+ switch (map[n++]) {
+ case GameBoard::WHITE_PAWN:
+ xpm = &fig[9];
+ break;
+ case GameBoard::WHITE_CASTLE:
+ xpm = &fig[7];
+ break;
+ case GameBoard::WHITE_BISHOP:
+ xpm = &fig[6];
+ break;
+ case GameBoard::WHITE_KING:
+ xpm = &fig[10];
+ break;
+ case GameBoard::WHITE_QUEEN:
+ xpm = &fig[11];
+ break;
+ case GameBoard::WHITE_KNIGHT:
+ xpm = &fig[8];
+ break;
+ case GameBoard::BLACK_PAWN:
+ xpm = &fig[3];
+ break;
+ case GameBoard::BLACK_CASTLE:
+ xpm = &fig[1];
+ break;
+ case GameBoard::BLACK_BISHOP:
+ xpm = &fig[0];
+ break;
+ case GameBoard::BLACK_KING:
+ xpm = &fig[4];
+ break;
+ case GameBoard::BLACK_QUEEN:
+ xpm = &fig[5];
+ break;
+ case GameBoard::BLACK_KNIGHT:
+ xpm = &fig[2];
+ break;
+ default:
+ xpm = NULL;
+ }
+ if (xpm != NULL)
+ p->drawPixmap(x, y, *xpm);
+ }
+ }
+}
+
+
+void
+Drawer::mousePressEvent(TQMouseEvent *e)
+{
+ int x = e->x() - x_brd,
+ y = e->y() - y_brd;
+
+ if ((x >= 0) && (x <= cs) && (y >= 0) && (y <= cs)) {
+ win2map(x, y);
+ if (hasTakenFigure()) {
+ if ((tfx == x) && (tfy == y)) {
+ tfx = tfy = -1;
+ repaint(FALSE);
+ } else
+ makeMove(*gt, tfx, tfy, x, y, FALSE, FALSE);
+ } else if (canTake(x, y)) {
+ takeFigure(x, y);
+ emit touchFigure(x, y);
+ }
+ }
+}
+
+
+bool
+Drawer::canTake(int x, int y)
+{
+
+ return (Figure::hasMyFigure(*gt, map, x, y, FALSE));
+}
+
+
+void
+Drawer::win2map(int &x, int &y)
+{
+
+ if (*gt == GameBoard::WHITE) {
+ x /= cell_size;
+ y = 8 - y / cell_size;
+ x++;
+ } else if (*gt == GameBoard::BLACK) {
+ x = 8 - x / cell_size;
+ y /= cell_size;
+ y++;
+ }
+}
+
+
+void
+Drawer::map2win(int mx, int my, int &x, int &y)
+{
+
+ if (*gt == GameBoard::WHITE) {
+ x = (mx - 1) * cell_size + x_brd + 1;
+ y = (8 - my) * cell_size + y_brd + 1;
+ } else if (*gt == GameBoard::BLACK) {
+ x = (8 - mx) * cell_size + x_brd + 1;
+ y = (my - 1) * cell_size + y_brd + 1;
+ } else {
+ x = mx;
+ y = my;
+ }
+}
+
+
+void
+Drawer::takeFigure(int x, int y)
+{
+
+ if ((tfx == x) && (tfy == y))
+ tfx = tfy = -1;
+ else {
+ tfx = x;
+ tfy = y;
+ }
+ repaint(FALSE);
+}
+
+
+bool
+Drawer::hasTakenFigure()
+{
+
+ return ((tfx != -1) && (tfy != -1));
+}
+
+
+void
+Drawer::newFigure(const TQString &coo, int id)
+{
+ GameBoard::FigureType ft;
+ int x, y, n;
+
+ ft = GameBoard::NONE; n = -1;
+ Figure::str2map(coo, &x, &y);
+ if (*gt == GameBoard::WHITE) {
+ n = Figure::map2map(GameBoard::BLACK, x, y, TRUE);
+ switch (id) {
+ case 3:
+ ft = GameBoard::BLACK_BISHOP;
+ break;
+ case 4:
+ ft = GameBoard::BLACK_KNIGHT;
+ break;
+ case 5:
+ ft = GameBoard::BLACK_CASTLE;
+ break;
+ case 10:
+ ft = GameBoard::BLACK_QUEEN;
+ break;
+ default:
+ ft = GameBoard::NONE;
+ }
+ } else if (*gt == GameBoard::BLACK) {
+ n = Figure::map2map(GameBoard::WHITE, x, y, TRUE);
+ switch (id) {
+ case 3:
+ ft = GameBoard::WHITE_BISHOP;
+ break;
+ case 4:
+ ft = GameBoard::WHITE_KNIGHT;
+ break;
+ case 5:
+ ft = GameBoard::WHITE_CASTLE;
+ break;
+ case 10:
+ ft = GameBoard::WHITE_QUEEN;
+ break;
+ default:
+ ft = GameBoard::NONE;
+ }
+ }
+
+ if (ft != GameBoard::NONE) {
+ map[n] = ft;
+ repaint(FALSE);
+ }
+}
+
+
+void
+Drawer::makeMove(const TQString &txt)
+{
+ int fx, fy, tx, ty;
+ GameBoard::GameType et;
+
+ if (*gt == GameBoard::WHITE)
+ et = GameBoard::BLACK;
+ else if (*gt == GameBoard::BLACK)
+ et = GameBoard::WHITE;
+ else
+ et = GameBoard::NOGAME;
+ if (txt == LONG_XCHG) {
+ if (et == GameBoard::BLACK)
+ makeMove(et, 1, 8, 4, 8, TRUE, TRUE);
+ else if (et == GameBoard::WHITE)
+ makeMove(et, 1, 1, 4, 1, TRUE, TRUE);
+ } else if (txt == SHORT_XCHG) {
+ if (et == GameBoard::BLACK)
+ makeMove(et, 8, 8, 6, 8, TRUE, TRUE);
+ else if (et == GameBoard::WHITE)
+ makeMove(et, 8, 1, 6, 1, TRUE, TRUE);
+ } else {
+ Figure::str2map(txt.left(2), &fx, &fy);
+ Figure::str2map(txt.right(2), &tx, &ty);
+ makeMove(et, fx, fy, tx, ty, TRUE, FALSE);
+ }
+}
+
+
+void
+Drawer::makeMove(GameBoard::GameType gt, int fx, int fy, int tx, int ty,
+ bool mirror, bool xc)
+{
+ GameBoard::GameType et;
+ GameBoard::FigureType fo, old;
+ int res, nf, nt;
+ FigureDialog *dlg;
+ bool x;
+ TQPointArray vl;
+
+ et = GameBoard::NOGAME;
+ nf = Figure::map2map(gt, fx, fy, mirror);
+ fo = map[nf];
+ nt = Figure::map2map(gt, tx, ty, mirror);
+ old = map[nt];
+ res = Figure::validMove(gt, map, fx, fy, tx, ty, mirror);
+ if (res) {
+ if (!mirror) {
+ x = FALSE;
+ if (gt == GameBoard::WHITE)
+ et = GameBoard::BLACK;
+ else if (gt == GameBoard::BLACK)
+ et = GameBoard::WHITE;
+ if (Figure::checkKing(et, map, mirror, vl, TRUE) !=
+ 0) {
+ map[nf] = map[nt];
+ map[nt] = old;
+ tfx = tfy = -1;
+ TQMessageBox::information(this,
+ tr("Error moving"), tr("You cannot "
+ "move this figure because the king "
+ "is in check") + '.');
+ goto HAXEP;
+ } else
+ kk = FALSE;
+ if (!km && (!lcm || !rcm) && !kk)
+ x = xchg(fo, map[nt], fx, fy, tx, ty);
+ else
+ x = TRUE;
+ if (x)
+ emit moved(Figure::map2str(fx, fy) +
+ Figure::map2str(tx, ty));
+ if ((res & 0xF) == 2) {
+ dlg = new FigureDialog(fig, gt, this);
+ dlg->exec();
+ fo = dlg->figure();
+ delete dlg;
+ map[nt] = fo;
+ emit newFigure(Figure::map2str(tx, ty), fo);
+ }
+ tfx = tfy = -1;
+ } else if (xc) {
+ if (gt == GameBoard::BLACK)
+ checkBlackCastle(fx, fy, tx, ty, TRUE);
+ else if (gt == GameBoard::WHITE)
+ checkWhiteCastle(fx, fy, tx, ty, TRUE);
+ }
+ if (mirror && (res & 0x10)) {
+ kk = TRUE;
+ } else if (res & 0x20) {
+ repaint(FALSE);
+ emit gameover(2);
+ return;
+ } else if (res & 0x40) {
+ repaint(FALSE);
+ emit gameover(3);
+ return;
+ }
+ HAXEP:
+ repaint(FALSE);
+ }
+}
+
+
+bool
+Drawer::xchg(GameBoard::FigureType o, GameBoard::FigureType n,
+ int fx, int fy, int tx, int ty)
+{
+ bool ret = TRUE;
+
+ if (*gt == GameBoard::WHITE) {
+ km = ((o == n) && (o == GameBoard::WHITE_KING));
+ if (!km && ((o == n) && (o == GameBoard::WHITE_CASTLE)))
+ ret = checkWhiteCastle(fx, fy, tx, ty, FALSE);
+ } else if (*gt == GameBoard::BLACK) {
+ km = ((o == n) && (o == GameBoard::BLACK_KING));
+ if (!km && ((o == n) && (o == GameBoard::BLACK_CASTLE)))
+ ret = checkBlackCastle(fx, fy, tx, ty, FALSE);
+ }
+
+ return (ret);
+}
+
+
+bool
+Drawer::checkWhiteCastle(int fx, int fy, int tx, int ty, bool mirror)
+{
+ int n1, n2;
+ bool ret = TRUE;
+
+ n1 = n2 = -1;
+ if ((fx == 1) && (fy == 1)) {
+ if ((tx == 4) && (ty == 1))
+ if (mirror) {
+ n1 = Figure::map2map(*gt, 5, 1, FALSE);
+ n2 = Figure::map2map(*gt, 3, 1, FALSE);
+ } else if (!lcm) {
+ if (makeXchg()) {
+ n1 = Figure::map2map(*gt, 5, 1, FALSE);
+ n2 = Figure::map2map(*gt, 3, 1, FALSE);
+ emit moved(LONG_XCHG);
+ ret = FALSE;
+ rcm = TRUE;
+ }
+ lcm = TRUE;
+ }
+ } else if ((fx == 8) && (fy == 1)) {
+ if ((tx == 6) && (ty == 1))
+ if (mirror) {
+ n1 = Figure::map2map(*gt, 5, 1, FALSE);
+ n2 = Figure::map2map(*gt, 7, 1, FALSE);
+ } else if (!rcm) {
+ if (makeXchg()) {
+ n1 = Figure::map2map(*gt, 5, 1, FALSE);
+ n2 = Figure::map2map(*gt, 7, 1, FALSE);
+ emit moved(SHORT_XCHG);
+ ret = FALSE;
+ lcm = TRUE;
+ }
+ rcm = TRUE;
+ }
+ }
+ if (n1 != n2) {
+ map[n2] = map[n1];
+ map[n1] = GameBoard::NONE;
+ }
+
+ return (ret);
+}
+
+
+bool
+Drawer::checkBlackCastle(int fx, int fy, int tx, int ty, bool mirror)
+{
+ int n1, n2;
+ bool ret = TRUE;
+
+ n1 = n2 = -1;
+ if ((fx == 1) && (fy == 8)) {
+ if ((tx == 4) && (ty == 8)) {
+ if (mirror) {
+ n1 = Figure::map2map(*gt, 5, 8, FALSE);
+ n2 = Figure::map2map(*gt, 3, 8, FALSE);
+ } else if (!rcm) {
+ if (makeXchg()) {
+ n1 = Figure::map2map(*gt, 5, 8, FALSE);
+ n2 = Figure::map2map(*gt, 3, 8, FALSE);
+ emit moved(LONG_XCHG);
+ ret = FALSE;
+ }
+ rcm = TRUE;
+ }
+ }
+ } else if ((fx == 8) && (fy == 8)) {
+ if ((tx == 6) && (ty == 8))
+ if (mirror) {
+ n1 = Figure::map2map(*gt, 5, 8, FALSE);
+ n2 = Figure::map2map(*gt, 7, 8, FALSE);
+ } else if (!lcm) {
+ if (makeXchg()) {
+ n1 = Figure::map2map(*gt, 5, 8, FALSE);
+ n2 = Figure::map2map(*gt, 7, 8, FALSE);
+ emit moved(SHORT_XCHG);
+ ret = FALSE;
+ }
+ lcm = TRUE;
+ }
+ }
+ if (n1 != n2) {
+ map[n2] = map[n1];
+ map[n1] = GameBoard::NONE;
+ }
+
+ return (ret);
+}
+
+
+bool
+Drawer::makeXchg()
+{
+
+ return (TQMessageBox::question(this, tr("To castle"),
+ tr("Do you want to castle?"), tr("Yes"), tr("No")) == 0);
+}
+
+
+//-----------------------------------------------------------------------------
+
+FigureDialog::FigureDialog(const TQPixmap *f, const GameBoard::GameType g,
+ TQWidget *parent, const char *name):TQDialog(parent, name)
+{
+ TQFontMetrics fm(font());
+ int w, h;
+
+ gt = g; fig = f;
+ if (gt == GameBoard::WHITE)
+ fr = GameBoard::WHITE_QUEEN;
+ else if (gt == GameBoard::BLACK)
+ fr = GameBoard::BLACK_QUEEN;
+ str = tr("What figure should I set?");
+ setCaption(str);
+ fh = fm.lineSpacing() + 2;
+ h = cell_size + fh;
+ w = MAX(cell_size * 4, fm.width(str));
+ step = (w - cell_size * 4) / 2;
+ resize(w, h);
+ setMinimumSize(size());
+ setMaximumSize(size());
+}
+
+FigureDialog::~FigureDialog()
+{
+}
+
+
+void
+FigureDialog::paintEvent(TQPaintEvent *e)
+{
+ TQPainter *p;
+ int x, f = -1;
+
+ TQDialog::paintEvent(e);
+ p = new TQPainter(this);
+
+ p->setPen(TQt::black);
+ p->drawText(0, 0, width(), fh, TQt::AlignCenter, str);
+ x = step;
+ if (gt == GameBoard::BLACK)
+ f = 0;
+ else if (gt == GameBoard::WHITE)
+ f = 6;
+ p->drawPixmap(x, fh, fig[f]); x += cell_size;
+ p->drawPixmap(x, fh, fig[f + 1]); x += cell_size;
+ p->drawPixmap(x, fh, fig[f + 2]); x += cell_size;
+ p->drawPixmap(x, fh, fig[f + 5]);
+
+ delete p;
+}
+
+
+void
+FigureDialog::mousePressEvent(TQMouseEvent *e)
+{
+ int x = e->x(),
+ y = e->y(),
+ f = -1;
+
+ if (e->button() == TQt::LeftButton) {
+ if ((x >= step) && (x <= width() - step) && (y >= fh) &&
+ (y <= height()))
+ f = (x - step) / cell_size;
+ }
+
+ if (f != -1) {
+ if (gt == GameBoard::WHITE)
+ switch (f) {
+ case 0:
+ fr = GameBoard::WHITE_BISHOP;
+ break;
+ case 1:
+ fr = GameBoard::WHITE_CASTLE;
+ break;
+ case 2:
+ fr = GameBoard::WHITE_KNIGHT;
+ break;
+ case 3:
+ default:
+ fr = GameBoard::WHITE_QUEEN;
+ }
+ else if (gt == GameBoard::BLACK)
+ switch (f) {
+ case 0:
+ fr = GameBoard::BLACK_BISHOP;
+ break;
+ case 1:
+ fr = GameBoard::BLACK_CASTLE;
+ break;
+ case 2:
+ fr = GameBoard::BLACK_KNIGHT;
+ break;
+ case 3:
+ default:
+ fr = GameBoard::BLACK_QUEEN;
+ }
+ accept();
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+
+void
+GameProtocol::send(TQSocket *sock, const TQString &dat)
+{
+ TQString s(dat + EOL);
+ const char *buf;
+
+ if (sock->state() == TQSocket::Connected) {
+ buf = s.ascii();
+ sock->writeBlock(buf, s.length());
+ sock->flush();
+ }
+}
+
+
+void
+GameProtocol::setGameType(TQSocket *sock, GameBoard::GameType gt)
+{
+ TQString d("GAME");
+
+ d += SEP;
+ if (gt == GameBoard::WHITE)
+ d += "WHITE";
+ else if (gt == GameBoard::BLACK)
+ d += "BLACK";
+ else
+ d += "NOGAME";
+ send(sock, d);
+}
+
+
+void
+GameProtocol::acceptGame(TQSocket *sock)
+{
+ TQString d("GAME");
+
+ d += SEP;
+ d += "ACCEPT";
+ send(sock, d);
+}
+
+
+void
+GameProtocol::sendMove(TQSocket *sock, const TQString &coo)
+{
+ TQString d("MOVE");
+
+ d += SEP;
+ d += coo;
+ send(sock, d);
+}
+
+
+void
+GameProtocol::sendQuit(TQSocket *sock)
+{
+
+ send(sock, "QUIT");
+}
+
+
+void
+GameProtocol::sendText(TQSocket *sock, const TQString &txt)
+{
+ TQString d("CHAT");
+
+ d += SEP;
+ d += txt;
+ send(sock, d);
+}
+
+
+void
+GameProtocol::sendFigure(TQSocket *sock, const TQString &coo, int id)
+{
+ TQString d("FIGURE");
+
+ d += SEP;
+ d += coo;
+ d += SEP;
+ d += TQString::number(id);
+ send(sock, d);
+}
+
+
+void
+GameProtocol::sendGameover(TQSocket *sock, const TQString &got)
+{
+ TQString d("GAME");
+
+ d += SEP;
+ d += got;
+ send(sock, d);
+}
+
+#include "gameboard.moc"
diff --git a/qnetchess/src/gameboard.h b/qnetchess/src/gameboard.h
new file mode 100644
index 00000000..2db232ac
--- /dev/null
+++ b/qnetchess/src/gameboard.h
@@ -0,0 +1,245 @@
+/*
+ * $Id: gameboard.h,v 0.1 2005/01/08 13:00:57 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#ifndef __GAME_BOARD_H__
+#define __GAME_BOARD_H__
+
+#include <ntqwidget.h>
+#include <ntqpainter.h>
+#include <ntqpixmap.h>
+#include <ntqpointarray.h>
+#include <ntqdialog.h>
+#include <ntqsocket.h>
+#include <ntqgroupbox.h>
+#include <ntqlineedit.h>
+#include <ntqlistbox.h>
+#include <ntqtimer.h>
+#include <stdlib.h>
+
+#define MAX(a, b) (((a) > (b))?(a):(b))
+#define SEP ' '
+#define EOL '\n'
+#define LONG_XCHG "@-@"
+#define SHORT_XCHG "o-o"
+#define SOCK_WAIT 900
+#define GAMEOVER_TXT "****"
+
+class GameBoard;
+class Drawer;
+class Figure;
+
+class GameBoard:public TQWidget
+{
+ Q_OBJECT
+public:
+ enum GameType {
+ NOGAME = 0x0,
+ BLACK = 0x1,
+ WHITE = 0x2
+ };
+
+ enum FigureType {
+ NONE = 0x00,
+ WHITE_PAWN = 0x01,
+ WHITE_CASTLE = 0x02,
+ WHITE_BISHOP = 0x03,
+ WHITE_KING = 0x04,
+ WHITE_QUEEN = 0x05,
+ WHITE_KNIGHT = 0x06,
+ BLACK_PAWN = 0x11,
+ BLACK_CASTLE = 0x12,
+ BLACK_BISHOP = 0x13,
+ BLACK_KING = 0x14,
+ BLACK_QUEEN = 0x15,
+ BLACK_KNIGHT = 0x16,
+ DUMMY = 0xFF
+ };
+
+ GameBoard(GameType, const TQString &, TQWidget *parent = NULL,
+ const char *name = NULL);
+ GameBoard(int, TQWidget *parent = NULL, const char *name = NULL);
+ ~GameBoard();
+
+ void saveImage();
+
+ GameType type()const{return (gt);}
+ TQString status()const{return (my_stat);}
+
+private:
+ Drawer *drw;
+ GameType gt;
+ FigureType *map;
+ TQString hst, my_stat;
+ TQSocket *sock;
+ TQGroupBox *box, *hist;
+ TQListBox *lst, *hw, *hb;
+ TQLineEdit *edt;
+ TQTimer *tmr;
+ int sock_tout;
+
+ void initMap();
+ void parseString(const TQString&);
+ void updateChat(const TQString&);
+ void updateHistory(const TQString&, bool);
+ void updateHistory(int, bool);
+
+protected:
+ void resizeEvent(TQResizeEvent *);
+ void closeEvent(TQCloseEvent *);
+ void focusInEvent(TQFocusEvent *);
+
+private slots:
+ void showHostFound();
+ void sockConnected();
+ void sockRead();
+ void sockClosed();
+ void sendMove(const TQString&);
+ void sendText();
+ void sendFigure(const TQString&, GameBoard::FigureType);
+ void sockTest();
+ void sockError(int);
+ void gameover(int);
+
+signals:
+ void showStatus(const TQString&);
+};
+
+//-----------------------------------------------------------------------------
+
+class Drawer:public TQWidget
+{
+ Q_OBJECT
+public:
+ Drawer(GameBoard::FigureType *, GameBoard::GameType *,
+ TQWidget *parent = NULL, const char *name = NULL);
+ ~Drawer();
+
+ void makeMove(const TQString&);
+ void newFigure(const TQString&, int);
+
+private:
+ int top_margin, left_margin, hl;
+ int x_brd, y_brd, cs;
+ int tfx, tfy;
+ TQPixmap fig[12];
+ GameBoard::FigureType *map;
+ GameBoard::GameType *gt;
+ bool km, lcm, rcm, kk;
+
+ void drawBoard(TQPainter *, int, int);
+ void drawMap(TQPainter *, int, int);
+ void win2map(int&, int&);
+ void map2win(int, int, int&, int&);
+ void takeFigure(int, int);
+ void makeMove(GameBoard::GameType, int, int, int, int, bool, bool);
+ bool xchg(GameBoard::FigureType, GameBoard::FigureType,
+ int, int, int, int);
+ bool checkWhiteCastle(int, int, int, int, bool);
+ bool checkBlackCastle(int, int, int, int, bool);
+
+ bool canTake(int, int);
+ bool hasTakenFigure();
+ bool makeXchg();
+
+protected:
+ void paintEvent(TQPaintEvent *);
+ void mousePressEvent(TQMouseEvent *);
+
+signals:
+ void touchFigure(int, int);
+ void moved(const TQString&);
+ void newFigure(const TQString&, GameBoard::FigureType);
+ void gameover(int);
+};
+
+//-----------------------------------------------------------------------------
+
+class FigureDialog:public TQDialog
+{
+ Q_OBJECT
+public:
+ FigureDialog(const TQPixmap *, const GameBoard::GameType,
+ TQWidget *parent = NULL, const char *name = NULL);
+ ~FigureDialog();
+
+ GameBoard::FigureType figure()const{return (fr);}
+
+private:
+ GameBoard::GameType gt;
+ const TQPixmap *fig;
+ TQString str;
+ int step, fh;
+ GameBoard::FigureType fr;
+
+protected:
+ void paintEvent(TQPaintEvent *);
+ void mousePressEvent(TQMouseEvent *);
+};
+
+//-----------------------------------------------------------------------------
+
+class Figure
+{
+public:
+
+ static bool hasMyFigure(GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static int hasEnemyFigure(GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static bool hasFigure(GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static int map2map(GameBoard::GameType, int, int, bool);
+ static int validMove(GameBoard::GameType, GameBoard::FigureType *,
+ int, int, int, int, bool);
+
+ static void moveList(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListWhitePawn(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListBlackPawn(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListCastle(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListBishop(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListKing(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListQueen(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static void moveListKnight(TQPointArray&, GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static bool hasPoint(const TQPointArray&, int, int);
+ static bool hasKingsMeeting(GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static bool validPoint(GameBoard::GameType,
+ GameBoard::FigureType *, int, int, bool);
+ static TQString map2str(int, int);
+ static void str2map(const TQString&, int *, int *);
+ static int checkKing(GameBoard::GameType, GameBoard::FigureType *,
+ bool, TQPointArray&, bool);
+};
+
+//-----------------------------------------------------------------------------
+
+class GameProtocol
+{
+public:
+ static void send(TQSocket *, const TQString&);
+ static void setGameType(TQSocket *, GameBoard::GameType);
+ static void acceptGame(TQSocket *);
+ static void sendMove(TQSocket *, const TQString&);
+ static void sendQuit(TQSocket *);
+ static void sendText(TQSocket *, const TQString&);
+ static void sendFigure(TQSocket *, const TQString&, int);
+ static void sendGameover(TQSocket *, const TQString&);
+};
+
+#endif /* __GAME_BOARD_H__ */
diff --git a/qnetchess/src/gamesocket.cpp b/qnetchess/src/gamesocket.cpp
new file mode 100644
index 00000000..b3dc2fe5
--- /dev/null
+++ b/qnetchess/src/gamesocket.cpp
@@ -0,0 +1,33 @@
+/*
+ * $Id: gamesocket.cpp,v 0.1 2005/01/08 12:31:24 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#include <ntqsocket.h>
+
+#include "gamesocket.h"
+
+GameSocket::GameSocket(TQObject *parent, const char *name)
+ :TQServerSocket(GAME_PORT, GAME_BACKLOG, parent, name)
+{
+}
+
+GameSocket::~GameSocket()
+{
+}
+
+
+void
+GameSocket::newConnection(int sock)
+{
+
+ emit acceptConnection(sock);
+}
+
+#include "gamesocket.moc"
diff --git a/qnetchess/src/gamesocket.h b/qnetchess/src/gamesocket.h
new file mode 100644
index 00000000..63774721
--- /dev/null
+++ b/qnetchess/src/gamesocket.h
@@ -0,0 +1,37 @@
+/*
+ * $Id: gamesocket.h,v 0.1 2005/01/08 12:31:24 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#ifndef __GAME_SOCKET_H__
+#define __GAME_SOCKET_H__
+
+#include <ntqserversocket.h>
+#include <stdlib.h>
+
+#define GAME_PORT 1345
+#define GAME_BACKLOG 5
+
+class GameSocket:public TQServerSocket
+{
+ Q_OBJECT
+public:
+ GameSocket(TQObject *parent = NULL, const char *name = NULL);
+ ~GameSocket();
+
+private:
+
+protected:
+ void newConnection(int);
+
+signals:
+ void acceptConnection(int);
+};
+
+#endif /* __GAME_SOCKET_H__ */
diff --git a/qnetchess/src/main.cpp b/qnetchess/src/main.cpp
new file mode 100644
index 00000000..d58a6cce
--- /dev/null
+++ b/qnetchess/src/main.cpp
@@ -0,0 +1,54 @@
+/*
+ * $Id: main.cpp,v 0.1 2005/01/08 12:19:58 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#include <ntqapplication.h>
+#include <ntqmessagebox.h>
+#include <ntqtextcodec.h>
+#include <ntqtranslator.h>
+
+#include "mainwindow.h"
+
+const int
+ XSize = 800,
+ YSize = 600;
+
+int
+main(int argc, const char *argv[])
+{
+ TQApplication *app;
+ MainWindow *mw;
+// TQTranslator *qt;
+ int result = 0;
+
+ app = new TQApplication(argc, (char **)argv);
+/* FIXME: how does TQTranslator() work in TQt?
+ qt = new TQTranslator();
+ if (qt->load(LOCALE_FILE))
+ app->installTranslator(qt);*/
+ mw = new MainWindow();
+
+ if (mw->sockOk()) {
+ app->setMainWidget(mw);
+ mw->show();
+ mw->resize(XSize, YSize);
+ mw->setMinimumSize(mw->size());
+ result = app->exec();
+ } else
+ TQMessageBox::critical(NULL, TQObject::tr("Socket Error"),
+ TQObject::tr("Cannot create a server socket!"));
+
+ delete mw;
+// delete qt;
+ delete app;
+
+ return (result);
+}
+
diff --git a/qnetchess/src/mainwindow.cpp b/qnetchess/src/mainwindow.cpp
new file mode 100644
index 00000000..d490f85d
--- /dev/null
+++ b/qnetchess/src/mainwindow.cpp
@@ -0,0 +1,294 @@
+/*
+ * $Id: mainwindow.cpp,v 0.1 2005/01/08 12:20:13 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#include <ntqapplication.h>
+#include <ntqmenubar.h>
+#include <ntqstatusbar.h>
+#include <ntqpixmap.h>
+#include <ntqvalidator.h>
+#include <ntqmessagebox.h>
+
+#include "mainwindow.h"
+#include "gameboard.h"
+
+#include "xpm/chess.xpm"
+#include "xpm/quit.xpm"
+#include "xpm/new_game.xpm"
+
+extern TQColor cw, cb;
+
+MainWindow::MainWindow(TQWidget *parent, const char *name)
+ :TQMainWindow(parent, name)
+{
+ TQPixmap xpm(chess_xpm);
+
+ cw = TQColor(0x8F, 0xDF, 0xF0);
+ cb = TQColor(0x70, 0x9F, 0xDF);
+ setIcon(xpm);
+ wrk = new TQWorkspace(this);
+ sock = new GameSocket(this);
+ game = new TQPopupMenu(this);
+ game->insertItem(TQPixmap((const char **)new_game), tr("New"),
+ this, SLOT(newGame()), CTRL + Key_N);
+ id = game->insertItem(xpm, tr("Save image"), this,
+ SLOT(saveImage()), CTRL + Key_S);
+ game->setItemEnabled(id, FALSE);
+ game->insertSeparator();
+ game->insertItem(TQPixmap((const char **)quit_xpm), tr("Quit"), tqApp,
+ SLOT(quit()), CTRL + Key_Q);
+ help = new TQPopupMenu(this);
+ help->insertItem(xpm, tr("About the game"), this, SLOT(about()));
+
+ menuBar()->insertItem(tr("Game"), game);
+ menuBar()->insertSeparator();
+ menuBar()->insertItem(tr("Help"), help);
+
+ setCentralWidget(wrk);
+ ready_txt = tr("Ready");
+ showStatus(ready_txt);
+
+ TQObject::connect(sock, SIGNAL(acceptConnection(int)),
+ this, SLOT(newGame(int)));
+ TQObject::connect(wrk, SIGNAL(windowActivated(TQWidget *)),
+ this, SLOT(activated(TQWidget *)));
+}
+
+MainWindow::~MainWindow()
+{
+
+ delete help;
+ delete game;
+ delete sock;
+ delete wrk;
+}
+
+
+void
+MainWindow::showStatus(const TQString &txt)
+{
+
+ statusBar()->message(txt);
+}
+
+
+void
+MainWindow::newGame()
+{
+ SelectGame *dlg;
+ GameBoard *brd;
+ TQString hst;
+
+ dlg = new SelectGame(this);
+ dlg->setHosts(hosts);
+ if (dlg->exec()) {
+ hosts = dlg->hosts();
+ hst = dlg->host();
+ brd = new GameBoard(dlg->gameType(), hst, wrk);
+ showStatus(brd->status());
+ TQObject::connect(brd, SIGNAL(showStatus(const TQString&)),
+ this, SLOT(showStatus(const TQString&)));
+ brd->show();
+ }
+ delete dlg;
+}
+
+
+void
+MainWindow::newGame(int sock)
+{
+ GameBoard *brd;
+
+ brd = new GameBoard(sock, wrk);
+ showStatus(brd->status());
+ TQObject::connect(brd, SIGNAL(showStatus(const TQString&)),
+ this, SLOT(showStatus(const TQString&)));
+ brd->show();
+ game->setItemEnabled(id, TRUE);
+}
+
+
+void
+MainWindow::about()
+{
+
+ TQMessageBox::about(this, tr("About") + " QNetChess", "QNetChess " + tr(
+ "is a network game chess for two players.\n"
+ "It has a client and a server in the same program.\n"
+ "You can modify and redistribute the source code\n"
+ "because it is under GPL.\n\n"
+ "Russia, Tambov, 2005, 2020 (denis@tambov.ru)"
+ ));
+}
+
+
+void
+MainWindow::activated(TQWidget *w)
+{
+ GameBoard *brd = (GameBoard *)w;
+
+ game->setItemEnabled(id, brd != NULL);
+ if (brd != NULL)
+ showStatus(brd->status());
+ else
+ showStatus(ready_txt);
+}
+
+
+void
+MainWindow::saveImage()
+{
+ GameBoard *brd = (GameBoard *)wrk->activeWindow();
+
+ if (brd != NULL)
+ brd->saveImage();
+}
+
+//-----------------------------------------------------------------------------
+
+SelectGame::SelectGame(TQWidget *parent, const char *name)
+ :TQDialog(parent, name)
+{
+
+ setCaption(tr("New game with..."));
+ l1 = new TQLabel(tr("To play with "), this);
+ hst = new TQComboBox(TRUE, this);
+ hst->setValidator(new TQRegExpValidator(
+ TQRegExp("([a-zA-Z0-9]*\\.)*[a-zA-Z]"), hst));
+ btn = new TQButtonGroup(tr("Choose your game"), this);
+ wg = new TQRadioButton(tr("White game"), btn);
+ bg = new TQRadioButton(tr("Black game"), btn);
+ box = new TQGroupBox(this);
+ Ok = new TQPushButton(tr("Play!"), box);
+ Cancel = new TQPushButton(tr("Cancel"), box);
+
+ resize(400, TQFontMetrics(font()).lineSpacing() * 7);
+ setMinimumSize(size());
+ setMaximumSize(size());
+
+ TQObject::connect(Ok, SIGNAL(clicked()), this, SLOT(accept()));
+ TQObject::connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
+ TQObject::connect(wg, SIGNAL(clicked()), this, SLOT(checkParams()));
+ TQObject::connect(bg, SIGNAL(clicked()), this, SLOT(checkParams()));
+ TQObject::connect(hst, SIGNAL(textChanged(const TQString&)),
+ this, SLOT(checkParams(const TQString&)));
+
+ checkParams();
+}
+
+SelectGame::~SelectGame()
+{
+
+ delete Cancel;
+ delete Ok;
+ delete box;
+ delete bg;
+ delete wg;
+ delete btn;
+ delete hst;
+ delete l1;
+}
+
+
+void
+SelectGame::resizeEvent(TQResizeEvent *e)
+{
+ TQFontMetrics fm(font());
+ int w = e->size().width(),
+ h = e->size().height(),
+ fh = fm.lineSpacing() + 2,
+ bl;
+
+ TQDialog::resizeEvent(e);
+ l1->setGeometry(0, 0, fm.width(l1->text()) + 20, fh);
+ hst->move(l1->x() + l1->width(), l1->y());
+ hst->resize(w - hst->x(), l1->height());
+ btn->move(l1->x(), l1->y() + l1->height());
+ btn->resize(w, l1->height() * 3 + 2);
+ wg->setGeometry(2, fh, btn->width() - 4, fh);
+ bg->setGeometry(wg->x(), wg->y() + wg->height(),
+ wg->width(), wg->height());
+ box->move(btn->x(), btn->y() + btn->height());
+ box->resize(w, h - box->y());
+ bl = box->width() / 5;
+ Ok->move(bl, 4);
+ Ok->resize(bl, box->height() - Ok->y() * 2);
+ Cancel->setGeometry(Ok->x() + Ok->width() + bl, Ok->y(),
+ Ok->width(), Ok->height());
+}
+
+
+void
+SelectGame::checkParams()
+{
+ bool res;
+
+ res = !hst->currentText().isEmpty() &&
+ (bg->isChecked() || wg->isChecked());
+ Ok->setEnabled(res);
+}
+
+
+void
+SelectGame::checkParams(const TQString&)
+{
+
+ checkParams();
+}
+
+
+TQString
+SelectGame::host()
+{
+ TQString h(hst->currentText());
+
+ return h.left(h.findRev(':'));
+}
+
+
+TQStringList
+SelectGame::hosts()
+{
+ TQStringList lst;
+ int i, cnt;
+
+ cnt = hst->count();
+ lst += host();
+ for (i = 0; i < cnt; i++)
+ lst += hst->text(i);
+
+ return (lst);
+}
+
+
+void
+SelectGame::setHosts(const TQStringList &h)
+{
+
+ hst->insertStringList(h);
+}
+
+
+GameBoard::GameType
+SelectGame::gameType()
+{
+ GameBoard::GameType gt;
+
+ if (wg->isChecked())
+ gt = GameBoard::WHITE;
+ else if (bg->isChecked())
+ gt = GameBoard::BLACK;
+ else
+ gt = GameBoard::NOGAME;
+
+ return (gt);
+}
+
+#include "mainwindow.moc"
diff --git a/qnetchess/src/mainwindow.h b/qnetchess/src/mainwindow.h
new file mode 100644
index 00000000..45a7f563
--- /dev/null
+++ b/qnetchess/src/mainwindow.h
@@ -0,0 +1,87 @@
+/*
+ * $Id: mainwindow.h,v 0.1 2005/01/08 12:20:13 denis Exp $
+ *
+ * Author: Denis Kozadaev (denis@tambov.ru)
+ * Description:
+ *
+ * See also: style(9)
+ *
+ * Hacked by:
+ */
+
+#ifndef __MAIN_WINDOW_H__
+#define __MAIN_WINDOW_H__
+
+#include <ntqmainwindow.h>
+#include <ntqpopupmenu.h>
+#include <ntqworkspace.h>
+#include <ntqdialog.h>
+#include <ntqlabel.h>
+#include <ntqcombobox.h>
+#include <ntqbuttongroup.h>
+#include <ntqradiobutton.h>
+#include <ntqgroupbox.h>
+#include <ntqpushbutton.h>
+#include <stdlib.h>
+
+#include "gamesocket.h"
+#include "gameboard.h"
+
+class MainWindow:public TQMainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow(TQWidget *parent = NULL, const char *name = NULL);
+ ~MainWindow();
+
+ bool sockOk()const{return (sock->ok());}
+
+private:
+ int id;
+ TQString ready_txt;
+ TQPopupMenu *game, *help;
+ TQWorkspace *wrk;
+ GameSocket *sock;
+ TQStringList hosts;
+
+private slots:
+ void showStatus(const TQString&);
+ void newGame();
+ void newGame(int);
+ void about();
+ void activated(TQWidget *);
+ void saveImage();
+};
+
+//-----------------------------------------------------------------------------
+
+class SelectGame:public TQDialog
+{
+ Q_OBJECT
+public:
+ SelectGame(TQWidget *parent = NULL, const char *name = NULL);
+ ~SelectGame();
+
+ void setHosts(const TQStringList &);
+
+ TQString host();
+ TQStringList hosts();
+ GameBoard::GameType gameType();
+
+private:
+ TQLabel *l1;
+ TQComboBox *hst;
+ TQButtonGroup *btn;
+ TQRadioButton *wg, *bg;
+ TQGroupBox *box;
+ TQPushButton *Ok, *Cancel;
+
+protected:
+ void resizeEvent(TQResizeEvent *);
+
+private slots:
+ void checkParams();
+ void checkParams(const TQString&);
+};
+
+#endif /* __MAIN_WINDOW_H__ */
diff --git a/qnetchess/src/xpm/black_bishop.xpm b/qnetchess/src/xpm/black_bishop.xpm
new file mode 100644
index 00000000..f866a010
--- /dev/null
+++ b/qnetchess/src/xpm/black_bishop.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *black_bishop[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"..................####..................",
+".................######.................",
+"..................####..................",
+"..................####..................",
+".................######.................",
+"...............##########...............",
+"..............############..............",
+".............##############.............",
+"............#######aa#######............",
+"...........########aa########...........",
+"...........########aa########...........",
+"..........######aaaaaaaa######..........",
+"..........######aaaaaaaa######..........",
+"..........#########aa#########..........",
+"...........########aa########...........",
+"...........########aa########...........",
+"............################............",
+".............##############.............",
+"..............############..............",
+"...............aaaaaaaaaa...............",
+"..............############..............",
+".............##############.............",
+"..............############..............",
+"...............a########a...............",
+"...............#aaaaaaaa#...............",
+"..........####################..........",
+".........######################.........",
+"........###########..###########........",
+"........##########....##########........",
+".........########......########.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/black_castle.xpm b/qnetchess/src/xpm/black_castle.xpm
new file mode 100644
index 00000000..c483d9e0
--- /dev/null
+++ b/qnetchess/src/xpm/black_castle.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *black_castle[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"..........#####...####...#####..........",
+"..........#####...####...#####..........",
+"..........#####...####...#####..........",
+"..........####################..........",
+"..........####################..........",
+"...........##################...........",
+"............##aaaaaaaaaaaa##............",
+".............##############.............",
+"..............############..............",
+"..............##aaaaaaaa##..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............############..............",
+"..............##aaaaaaaa##..............",
+"..............############..............",
+".............##aaaaaaaaaa##.............",
+"............################............",
+"...........##################...........",
+"..........##aaaaaaaaaaaaaaaa##..........",
+"..........####################..........",
+".........######################.........",
+".........######################.........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/black_king.xpm b/qnetchess/src/xpm/black_king.xpm
new file mode 100644
index 00000000..216c2cfc
--- /dev/null
+++ b/qnetchess/src/xpm/black_king.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *black_king[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"...................##...................",
+".................######.................",
+".................######.................",
+"...................##...................",
+"...................##...................",
+"........####.......##.......####........",
+"......########....#aa#....########......",
+".....##########..#a##a#..##########.....",
+".....####aaaa####a####a####aaaa####.....",
+"....####a####a###a####a###a####a####....",
+"....###a######a###a##a###a######a###....",
+"....###a#######a###aa###a#######a###....",
+"....###a########a##aa##a########a###....",
+".....##a#########a####a#########a##.....",
+".....###a########a####a########a###.....",
+".....###a#########a##a#########a###.....",
+"......##a#########a##a#########a##......",
+"......###a########a##a########a###......",
+".......##a########a##a########a##.......",
+".......###a#######a##a#######a###.......",
+"........###a######a##a######a###........",
+".........###a#####a##a#####a###.........",
+"..........###aaaaaaaaaaaaaa###..........",
+"..........aaa##############aaa..........",
+"..........####################..........",
+".........######aaaaaaaaaa######.........",
+"........####aaa##########aaa####........",
+"........aaaa################aaaa........",
+"........########################........",
+"........########################........",
+"........########################........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/black_knight.xpm b/qnetchess/src/xpm/black_knight.xpm
new file mode 100644
index 00000000..9ed24184
--- /dev/null
+++ b/qnetchess/src/xpm/black_knight.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *black_knight[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"................#...#...................",
+"...............###.###..................",
+"...............###.###..................",
+"..............####a###..................",
+".............###aa#####.................",
+"............###a#########...............",
+"...........###############..............",
+"..........############a####.............",
+".........####aaa#######a####............",
+".........###aaa#########a####...........",
+"........#################a####..........",
+"........##################a###..........",
+".......###################a####.........",
+".......####################a###.........",
+"......######################a###........",
+".....################.#####a####........",
+"....##aa###########...######a###........",
+"....##############...########a###.......",
+"....#####a#######...########a####.......",
+"....####aa#####....##########a###.......",
+".....#aaa####.....############a###......",
+".......a####....#############a####......",
+"......#####....###############a###......",
+".......##.....###############a####......",
+".............#################a###......",
+"............#################a####......",
+"...........###################a###......",
+"...........#######################......",
+"...........#######################......",
+"...........#######################......",
+"...........######################.......",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/black_pawn.xpm b/qnetchess/src/xpm/black_pawn.xpm
new file mode 100644
index 00000000..7a6f7309
--- /dev/null
+++ b/qnetchess/src/xpm/black_pawn.xpm
@@ -0,0 +1,45 @@
+/* XPM */
+static const char *black_pawn[]={
+"40 40 2 1",
+". c None",
+"# c #000000",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"..................####..................",
+".................######.................",
+"................########................",
+"...............##########...............",
+"...............##########...............",
+"...............##########...............",
+"................########................",
+"................########................",
+"...............##########...............",
+"..............############..............",
+".............##############.............",
+".............##############.............",
+".............##############.............",
+"..............############..............",
+"...............##########...............",
+"..............############..............",
+".............##############.............",
+"............################............",
+"............################............",
+"...........##################...........",
+"...........##################...........",
+"..........####################..........",
+"..........####################..........",
+"..........####################..........",
+"..........####################..........",
+"..........####################..........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/black_queen.xpm b/qnetchess/src/xpm/black_queen.xpm
new file mode 100644
index 00000000..00f02b9d
--- /dev/null
+++ b/qnetchess/src/xpm/black_queen.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *black_queen[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"...........##.....####.....##...........",
+"..........####....####....####..........",
+"..........####.....##.....####..........",
+"...........##......##......##...........",
+"...##......##......##......##......##...",
+"..####.....##.....####.....##.....####..",
+"..####.....###....####....###.....####..",
+"...##......###....####....###......##...",
+"....#......###....####....###......#....",
+"....##.....####...####...####.....##....",
+"....###....####...####...####....###....",
+"....####...####...####...####...####....",
+".....###...####..######..####...###.....",
+".....####..#####.######.#####..####.....",
+"......####.#####.######.#####.####......",
+"......##########.######.##########......",
+"......############################......",
+".......##########################.......",
+".......########aaaaaaaaaa########.......",
+"........##aaaaa##########aaaaa##........",
+"........#a####################a#........",
+".........######################.........",
+".........######aaaaaaaaaa######.........",
+".........#aaaaa##########aaaaa#.........",
+".........######################.........",
+"........#######aaaaaaaaaa#######........",
+"........#aaaaaa##########aaaaaa#........",
+"........########################........",
+"........########################........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/chess.xpm b/qnetchess/src/xpm/chess.xpm
new file mode 100644
index 00000000..4d6af4cf
--- /dev/null
+++ b/qnetchess/src/xpm/chess.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *chess_xpm[]={
+"40 40 3 1",
+"# c #000000",
+"a c #ffffff",
+". c none",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"..........#####...####...#####..........",
+"..........#aaa#...#aa#...#aaa#..........",
+"..........#aaa#...#aa#...#aaa#..........",
+"..........#aaaa###aaaa###aaaa#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"............#a############a#............",
+".............#aaaaaaaaaaaa#.............",
+"..............#aaaaaaaaaa#..............",
+"..............#.########.#..............",
+"..............#.########.#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+".............#a##########a#.............",
+"............#aaaaaaaaaaaaaa#............",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"..........#a################a#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/new_game.xpm b/qnetchess/src/xpm/new_game.xpm
new file mode 100644
index 00000000..e2c22dda
--- /dev/null
+++ b/qnetchess/src/xpm/new_game.xpm
@@ -0,0 +1,65 @@
+/* XPM */
+static const char *new_game[] = {
+/* width height num_colors chars_per_pixel */
+" 50 50 8 1",
+/* colors */
+". c #040204",
+"# c #8cdef4",
+"a c #749edc",
+"b c #84a6f4",
+"c c #0c0a0c",
+"d c #6c96fa",
+"e c #040604",
+"f c #0c0e0c",
+/* pixels */
+"..................................................",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"e######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"e######bbbbba######abbbaa#######bbbaab######bbbbaa",
+"e######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######",
+"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######"
+};
diff --git a/qnetchess/src/xpm/quit.xpm b/qnetchess/src/xpm/quit.xpm
new file mode 100644
index 00000000..a6e1f83a
--- /dev/null
+++ b/qnetchess/src/xpm/quit.xpm
@@ -0,0 +1,68 @@
+/* XPM */
+static const char *quit_xpm[]={
+"22 22 43 1",
+"e c #a4140a",
+"# c #a41c0b",
+"m c #a92415",
+"x c #ac2a1c",
+"d c #ac2f21",
+"b c #b23628",
+"c c #b33b2e",
+"a c #b44234",
+"o c #bc421c",
+"p c #bc5732",
+"C c #bc5e04",
+"q c #c0603a",
+"h c #c07e5c",
+"s c #c46f4a",
+"g c #c47852",
+"J c #cc7350",
+"i c #cc825c",
+"j c #cc8a63",
+"k c #cc8f66",
+"r c #d4976b",
+"l c #d49e77",
+"O c #d8cecc",
+"F c #d99979",
+"K c #dca47c",
+"N c #dca684",
+"f c #ddab91",
+"n c #e2b59a",
+"t c #e4d2c4",
+"M c #e7e5ea",
+"G c #ebf3f9",
+"I c #ececf2",
+"v c #ecfafc",
+"w c #efcbb7",
+"D c #f1c5b4",
+"z c #f4eef4",
+"B c #f4f6fc",
+"y c #f8d5c8",
+"L c #f9e4d8",
+"H c #fcece2",
+"E c #fcf2e4",
+"A c #fcfed0",
+"u c #fcfefc",
+". c None",
+"...#aabcccdbdddddde...",
+".bbfggghgghijjikkjlmm.",
+".bbfggghgghijjikkjlmm.",
+"ennoppppqqkrsssssghlle",
+"chhpppstuuuuvvwiihhrrx",
+"chhpppstuuuuvvwiihhrrx",
+"bggpssuuyylnzzABBjhrrm",
+"dhhCttufsswDggnuuwjkkm",
+"chhguuysggEEgghEEujrrm",
+"chhguuysggEEgghEEujrrm",
+"dhhkuursssEEhhiDDvlrr#",
+"bhhFuuFgggGEiiiwwufll#",
+"djjhBBtgggHEhhkIIAlll#",
+"djjhBBtgggHEhhkIIAlll#",
+"diiJEEuKhhLtjjDuuMlll#",
+"djjskkBuyynfLLBuullNN#",
+"djjskkBuyynfLLBuullNN#",
+"djjgggiLuuuuuuLlllfNN#",
+"eKKhhhijkkfnrrlNNfOgge",
+".mmKkkrkrrllllKKKfgee.",
+".mmKkkrkrrllllKKKfgee.",
+"...exxmm##m######ee..."};
diff --git a/qnetchess/src/xpm/white_bishop.xpm b/qnetchess/src/xpm/white_bishop.xpm
new file mode 100644
index 00000000..31de757e
--- /dev/null
+++ b/qnetchess/src/xpm/white_bishop.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_bishop[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"..................#aa#..................",
+".................#aaaa#.................",
+"..................#aa#..................",
+"..................####..................",
+".................#aaaa#.................",
+"...............##aaaaaa##...............",
+"..............#aaaaaaaaaa#..............",
+".............#aaaaaaaaaaaa#.............",
+"............#aaaaaa##aaaaaa#............",
+"...........#aaaaaaa##aaaaaaa#...........",
+"...........#aaaaaaa##aaaaaaa#...........",
+"..........#aaaaa########aaaaa#..........",
+"..........#aaaaa########aaaaa#..........",
+"..........#aaaaaaaa##aaaaaaaa#..........",
+"...........#aaaaaaa##aaaaaaa#...........",
+"...........#aaaaaaa##aaaaaaa#...........",
+"............#aaaaaaaaaaaaaa#............",
+".............#aaaaaaaaaaaa#.............",
+"..............#aaaaaaaaaa#..............",
+"...............##########...............",
+"..............#aaaaaaaaaa#..............",
+".............#aaaaaaaaaaaa#.............",
+"..............#aaaaaaaaaa#..............",
+"...............#aaaaaaaa#...............",
+"...............##########...............",
+"..........#####aaaaaaaaaa#####..........",
+".........#aaaaaaaaa##aaaaaaaaa#.........",
+"........#aaaaaaaaa#..#aaaaaaaaa#........",
+"........#aaaaaaaa#....#aaaaaaaa#........",
+".........########......########.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/white_castle.xpm b/qnetchess/src/xpm/white_castle.xpm
new file mode 100644
index 00000000..ab8f499c
--- /dev/null
+++ b/qnetchess/src/xpm/white_castle.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_castle[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"..........#####...####...#####..........",
+"..........#aaa#...#aa#...#aaa#..........",
+"..........#aaa#...#aa#...#aaa#..........",
+"..........#aaaa###aaaa###aaaa#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"............#a############a#............",
+".............#aaaaaaaaaaaa#.............",
+"..............#aaaaaaaaaa#..............",
+"..............#a########a#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#aaaaaaaaaa#..............",
+"..............#a########a#..............",
+"..............#aaaaaaaaaa#..............",
+".............#a##########a#.............",
+"............#aaaaaaaaaaaaaa#............",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"..........#a################a#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/white_king.xpm b/qnetchess/src/xpm/white_king.xpm
new file mode 100644
index 00000000..f3fb74fc
--- /dev/null
+++ b/qnetchess/src/xpm/white_king.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_king[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"...................##...................",
+".................##aa##.................",
+".................##aa##.................",
+"...................##...................",
+"...................##...................",
+"........####.......##.......####........",
+"......##aaaa##....####....##aaaa##......",
+".....#aaaaaaaa#..##aa##..#aaaaaaaa#.....",
+".....#aaa####aa###aaaa###aa####aaa#.....",
+"....#aaa#aaaa#aa##aaaa##aa#aaaa#aaa#....",
+"....#aa#aaaaaa#aa##aa##aa#aaaaaa#aa#....",
+"....#aa#aaaaaaa#aa####aa#aaaaaaa#aa#....",
+"....#aa#aaaaaaaa#aa##aa#aaaaaaaa#aa#....",
+".....#a#aaaaaaaaa#aaaa#aaaaaaaaa#a#.....",
+".....#aa#aaaaaaaa#aaaa#aaaaaaaa#aa#.....",
+".....#aa#aaaaaaaaa#aa#aaaaaaaaa#aa#.....",
+"......#a#aaaaaaaaa#aa#aaaaaaaaa#a#......",
+"......#aa#aaaaaaaa#aa#aaaaaaaa#aa#......",
+".......#a#aaaaaaaa#aa#aaaaaaaa#a#.......",
+".......#aa#aaaaaaa#aa#aaaaaaa#aa#.......",
+"........#aa#aaaaaa#aa#aaaaaa#aa#........",
+".........#aa#aaaaa#aa#aaaaa#aa#.........",
+"..........#aa##############aa#..........",
+"..........###aaaaaaaaaaaaaa###..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+".........#aaaaa##########aaaaa#.........",
+"........#aaa###aaaaaaaaaa###aaa#........",
+"........####aaaaaaaaaaaaaaaa####........",
+"........#aaaaaaaaaaaaaaaaaaaaaa#........",
+"........#aaaaaaaaaaaaaaaaaaaaaa#........",
+"........##aaaaaaaaaaaaaaaaaaaa##........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/white_knight.xpm b/qnetchess/src/xpm/white_knight.xpm
new file mode 100644
index 00000000..e2aae2e4
--- /dev/null
+++ b/qnetchess/src/xpm/white_knight.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_knight[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"................#...#...................",
+"...............#a#.#a#..................",
+"...............#a#.#a#..................",
+"..............#aaa#aa#..................",
+".............#aa##aaa##.................",
+"............#aa#aaaaaaa##...............",
+"...........#aaaaaaaaaaaaa#..............",
+"..........#aaaaaaaaaaa#aaa#.............",
+".........#aaa###aaaaaaa#aaa#............",
+".........#aa###aaaaaaaaa#aaa#...........",
+"........#aaaaaaaaaaaaaaaa#aaa#..........",
+"........#aaaaaaaaaaaaaaaaa#aa#..........",
+".......#aaaaaaaaaaaaaaaaaa#aaa#.........",
+".......#aaaaaaaaaaaaaa#aaaa#aa#.........",
+"......#aaaaaaaaaaaaaa##aaaaa#aa#........",
+".....#aaaaaaaaaaaaa##.#aaaa#aaa#........",
+"....#a##aaaaaaaaaa#...#aaaaa#aa#........",
+"....#aaaaaaaaaaaa#...#aaaaaaa#aa#.......",
+"....#aaaa#aaaaa##...#aaaaaaa#aaa#.......",
+"....#aaa##aaa##....#aaaaaaaaa#aa#.......",
+".....####aaa#.....#aaaaaaaaaaa#aa#......",
+".......#aaa#....##aaaaaaaaaaa#aaa#......",
+"......#aa##....#aaaaaaaaaaaaaa#aa#......",
+".......##.....#aaaaaaaaaaaaaa#aaa#......",
+".............#aaaaaaaaaaaaaaaa#aa#......",
+"............#aaaaaaaaaaaaaaaa#aaa#......",
+"...........#aaaaaaaaaaaaaaaaaa#aa#......",
+"...........#aaaaaaaaaaaaaaaaaaaaa#......",
+"...........#aaaaaaaaaaaaaaaaaaaaa#......",
+"...........#aaaaaaaaaaaaaaaaaaaaa#......",
+"...........######################.......",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/white_pawn.xpm b/qnetchess/src/xpm/white_pawn.xpm
new file mode 100644
index 00000000..541f9a40
--- /dev/null
+++ b/qnetchess/src/xpm/white_pawn.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_pawn[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"..................####..................",
+".................#aaaa#.................",
+"................#aaaaaa#................",
+"...............#aaaaaaaa#...............",
+"...............#aaaaaaaa#...............",
+"...............#aaaaaaaa#...............",
+"................#aaaaaa#................",
+"................##aaaa##................",
+"...............#aaaaaaaa#...............",
+"..............#aaaaaaaaaa#..............",
+".............#aaaaaaaaaaaa#.............",
+".............#aaaaaaaaaaaa#.............",
+".............#aaaaaaaaaaaa#.............",
+"..............#aaaaaaaaaa#..............",
+"...............#aaaaaaaa#...............",
+"..............#aaaaaaaaaa#..............",
+".............#aaaaaaaaaaaa#.............",
+"............#aaaaaaaaaaaaaa#............",
+"............#aaaaaaaaaaaaaa#............",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"...........#aaaaaaaaaaaaaaaa#...........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"..........#aaaaaaaaaaaaaaaaaa#..........",
+"..........####################..........",
+"........................................",
+"........................................",
+"........................................"};
diff --git a/qnetchess/src/xpm/white_queen.xpm b/qnetchess/src/xpm/white_queen.xpm
new file mode 100644
index 00000000..dd01f7dc
--- /dev/null
+++ b/qnetchess/src/xpm/white_queen.xpm
@@ -0,0 +1,46 @@
+/* XPM */
+static const char *white_queen[]={
+"40 40 3 1",
+". c None",
+"# c #000000",
+"a c #ffffff",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"........................................",
+"...................##...................",
+"...........##.....#aa#.....##...........",
+"..........#aa#....#aa#....#aa#..........",
+"..........#aa#.....##.....#aa#..........",
+"...........##......##......##...........",
+"...##......##......##......##......##...",
+"..#aa#.....##.....#aa#.....##.....#aa#..",
+"..#aa#.....#a#....#aa#....#a#.....#aa#..",
+"...##......#a#....#aa#....#a#......##...",
+"....#......#a#....#aa#....#a#......#....",
+"....##.....#aa#...#aa#...#aa#.....##....",
+"....#a#....#aa#...#aa#...#aa#....#a#....",
+"....#aa#...#aa#...#aa#...#aa#...#aa#....",
+".....#a#...#aa#..#aaaa#..#aa#...#a#.....",
+".....#aa#..#aaa#.#aaaa#.#aaa#..#aa#.....",
+"......#aa#.#aaa#.#aaaa#.#aaa#.#aa#......",
+"......#aaa##aaa#.#aaaa#.#aaa##aaa#......",
+"......#aaaa#aaaa#aaaaaa#aaaa#aaaa#......",
+".......#aaaaaaaaaaaaaaaaaaaaaaaa#.......",
+".......#aaaaaaa##########aaaaaaa#.......",
+"........#a#####aaaaaaaaaa#####a#........",
+"........##aaaaaaaaaaaaaaaaaaaa##........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+".........#aaaaa##########aaaaa#.........",
+".........######aaaaaaaaaa######.........",
+".........#aaaaaaaaaaaaaaaaaaaa#.........",
+"........#aaaaaa##########aaaaaa#........",
+"........#######aaaaaaaaaa#######........",
+"........#aaaaaaaaaaaaaaaaaaaaaa#........",
+"........#aaaaaaaaaaaaaaaaaaaaaa#........",
+".........######################.........",
+"........................................",
+"........................................",
+"........................................"};