summaryrefslogtreecommitdiff
path: root/noncore/games/chess
Side-by-side diff
Diffstat (limited to 'noncore/games/chess') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/chess/Makefile.in134
-rw-r--r--noncore/games/chess/boardview.cw23
-rw-r--r--noncore/games/chess/chess.cpp358
-rw-r--r--noncore/games/chess/chess.db2
-rw-r--r--noncore/games/chess/chess.h128
-rw-r--r--noncore/games/chess/chess.pro14
-rw-r--r--noncore/games/chess/main.cpp51
-rw-r--r--noncore/games/chess/mainwindow.ui220
-rw-r--r--noncore/games/chess/pieces.pngbin0 -> 5696 bytes
-rw-r--r--noncore/games/chess/qpe-chess.control9
-rw-r--r--noncore/games/chess/simple-l.pngbin0 -> 16143 bytes
11 files changed, 939 insertions, 0 deletions
diff --git a/noncore/games/chess/Makefile.in b/noncore/games/chess/Makefile.in
new file mode 100644
index 0000000..7354d76
--- a/dev/null
+++ b/noncore/games/chess/Makefile.in
@@ -0,0 +1,134 @@
+#############################################################################
+
+####### Compiler, tools and options
+
+CXX = $(SYSCONF_CXX) $(QT_CXX_MT)
+CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) -DQCONFIG=\"qpe\"
+CC = $(SYSCONF_CC) $(QT_C_MT)
+CFLAGS = $(SYSCONF_CFLAGS) -DQCONFIG=\"qpe\"
+INCPATH = -I$(QPEDIR)/include
+LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
+LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
+MOC = $(SYSCONF_MOC)
+UIC = $(SYSCONF_UIC)
+
+####### Target
+
+DESTDIR = ../bin/
+VER_MAJ = 1
+VER_MIN = 0
+VER_PATCH = 0
+TARGET = chess
+TARGET1 = lib$(TARGET).so.$(VER_MAJ)
+
+####### Files
+
+HEADERS = chess.h
+SOURCES = chess.cpp \
+ main.cpp
+OBJECTS = chess.o \
+ main.o \
+ mainwindow.o
+INTERFACES = mainwindow.ui
+UICDECLS = mainwindow.h
+UICIMPLS = mainwindow.cpp
+SRCMOC = moc_chess.cpp \
+ moc_mainwindow.cpp
+OBJMOC = moc_chess.o \
+ moc_mainwindow.o
+
+
+####### Implicit rules
+
+.SUFFIXES: .cpp .cxx .cc .C .c
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cxx.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cc.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.C.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
+
+####### Build rules
+
+
+all: $(DESTDIR)$(TARGET)
+
+$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
+ $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
+
+moc: $(SRCMOC)
+
+tmake:
+ tmake chess.pro
+
+clean:
+ -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
+ -rm -f *~ core
+ -rm -f allmoc.cpp
+
+####### Extension Modules
+
+listpromodules:
+ @echo
+
+listallmodules:
+ @echo
+
+listaddonpromodules:
+ @echo
+
+listaddonentmodules:
+ @echo
+
+
+REQUIRES=
+
+####### Sub-libraries
+
+
+###### Combined headers
+
+
+
+####### Compile
+
+chess.o: chess.cpp \
+ $(QPEDIR)/include/qpe/config.h \
+ $(QPEDIR)/include/qpe/resource.h \
+ chess.h
+
+main.o: main.cpp \
+ mainwindow.h
+
+mainwindow.h: mainwindow.ui
+ $(UIC) mainwindow.ui -o $(INTERFACE_DECL_PATH)/mainwindow.h
+
+mainwindow.cpp: mainwindow.ui
+ $(UIC) mainwindow.ui -i mainwindow.h -o mainwindow.cpp
+
+mainwindow.o: mainwindow.cpp \
+ mainwindow.h \
+ mainwindow.ui
+
+moc_chess.o: moc_chess.cpp \
+ chess.h
+
+moc_mainwindow.o: moc_mainwindow.cpp \
+ mainwindow.h
+
+moc_chess.cpp: chess.h
+ $(MOC) chess.h -o moc_chess.cpp
+
+moc_mainwindow.cpp: mainwindow.h
+ $(MOC) mainwindow.h -o moc_mainwindow.cpp
+
+
diff --git a/noncore/games/chess/boardview.cw b/noncore/games/chess/boardview.cw
new file mode 100644
index 0000000..020af96
--- a/dev/null
+++ b/noncore/games/chess/boardview.cw
@@ -0,0 +1,23 @@
+<!DOCTYPE CW><CW>
+<customwidgets>
+ <customwidget>
+ <class>BoardView</class>
+ <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
+ <sizehint>
+ <width>-1</width>
+ <height>-1</height>
+ </sizehint>
+ <container>0</container>
+ <sizepolicy>
+ <hordata>5</hordata>
+ <verdata>5</verdata>
+ </sizepolicy>
+ <pixmap>
+ <data format="XPM.GZ" length="4605">789c6dd7d96ee33a1206e0fb7e8aa0ebae31a863c9966d613017d9e3ecce9e0ce6a228c94b6c67f192d83998771f9af517e10493b4daf89a25b258a428f75f7fb61e2ecfb6fefcf56b3697f9b0d82a0632ddfa532e2693d5bffff3afbf7ffd4ed3adf027d94a7fffe3d76ff7b9556c9dbfbe5401ef9bf8d8c464136f9b186ee27513cf9bd8dec47c13d30d74bfb52c3d28cdd322a9058fd6aee7f5a29e047f697bbd96b483573fe2173ffc82fbdbb87fb0762389fdcdd6ee859fe0716ccfd7e6def7fed8c5f1d5c5f77c58c2788959ea70230dfd3982dba9de7f6ff9693b757ee4dbb7f9a3fdf5473d7aea464dfb23fa3e3fdafe319f3d75a3a1edbc0fb7913f9991df8b19f7977081f1ae83c5da89cd8dd0bf34601bffceaced14facfd22c53f36db484f95570a9e3398ed6f1c27ec8c4e239877378d79c85bd4f477089f117d1219ee666c4d7d4cd04fddd98d1de5ebb995abc3ca863fb04467eb26746fc398c7ce5c0aced7c1dade3bfc2983f5766acf7be19f59f466b3d4b752bc1fd9a9f58ffd28311cf6d33f2b9323735ff17752bc17855b4f697c119f2cbcd884fe15cd757d6c711b5ea2dd48766708efd959871ffb319f53c86ad1e67d1fafc89ba9d60bcaf68edffca8ce7ab8033c4b7a2b57e3bc1ae95b7eac1db70091fa9db895a6e61ab472b3af4277730e6cb5d33e69bc3781e6865c6f31ce6d3f6f9b75c881738d3f5e2b119ed27708ef655b4aedf0d6cf5fc50e709f27d84510fb930e3f94a615bdf6bb3f627f7b0cd47f3f5f36d877a5103b67af6cddace23759e20fe00b6e77da016acb77370a6e71df5cc18bf1fadfb610c0bcef304ae6aeab619ef83f57b92f286e5c3cfd1a1de3c803378095bbd9bea98cf305af7430b16d47319adf53f34637daee00af9f7d52ed57c692f5acf7fbdbfc8f3bc113c834be43b35a37d185d84feeed482fd47e77086fdbf0b57d81f75b54b311f8ad6f95e9a319f1adc44fed3689ddf132c589f8e59e385a3b5fdcc8cf1bb30d697a2311eea53a07e1cce7b6948a2f52007676ad956bb14e7e53e6cebb382adff67339eb7a5dac6930f33ce87266cf5388dd6f50ccf83f87a8baed77bb4aed78edaa5c877085738ff3fcdd89f13b58d4f68b7f1e5d48cfd589a118ff10bd49b9ea235fe12aef0fc55669c6fe17c718d42701ececcfafea2118cfb3935e3bcf98cd6f18ecc785fbd99f1beabab4bab77c38cef2b613d5c5908ced357b8c2799aa9637c12ade32dcc787fedc04d7c1fb935e33c7b8cd6f509df578aac10acef02aef0bc76ccbade7caeb6fb656ec6fe1c98f1fc5ec2a82f9f9931bf5ab4e67b0263bf70d80f455956e8efc6acf9d185ba4a51bfb119e779789f97be7f9d1fbda9637b19adf73b33e21fe026ea7162c6f31ad6a7acaad4e9fe1fc1d6be1badf53b36a39e4fb0e5771f1dda257c7fa89a668a76657013b6f509eb5bf99f225bbb3b5fff32b1b0e3c25fffefb3d4288de78a7bdce7010ffdf5cca38dabef7fc73ce1177fcf6b8c77fcc6ef3cf56d6f3ce3392ff8833f79c92bfee26ddef1f1bbbcc785c6f3be8f3be0433ef2b11d3ee6133ee5333ee70bbee42e5ff135dff02ddff13d5388179fc5d4f7f4c08ffcc4354e38e53a3738f39f4d6e719b73ce898958d7a7c74312725450491537a9477d1ad0909e69e4e39b34a609bdf01dbdb2d6abf0fd3ff8e8377aa729cd684e8b704de8833e69e97f57f4e5fbdf8efd3fd30eed724a7bb44f733ff6fa3ae0aebf6be5a30f7d2f473ebe8378f1f1c77442a77416fb3ea70bba0c77f47c465dbaa2eb6ffddfd0adefddfabea37b7aa0477aa21a25beff25a5a17fcbff994a4ea88ebe1b9451d3d734a116b529f7d15df1cbefe71bfbe753ba145af72d224e7ca5f84c4aa9bc7b7edca5f4bfe72f03df3ea485f83b652463bf0a19d765e2df012febfcb9f53d7f79f5f16ff22e5399c95c16f2219f7ec512ffe9eb232bf9fa96ff48b67ddb8eecca9eef719fbb72208772b45ee175fda523c7dff2efcb899cfad57a973339478de672219721ba2b573fea3fe61db9f6792eb9292c37722b77d4926558dbaecfa62ff73eff4eec7fc2d7f2208f612dfde5ef3c44e493cfa523354924953af22fa5e1f7f7adaf9dff4f9d5fcb25aeae7468202d1fdd96dcb123ddcfe179d9f3fbef3a5c95131abbf54fc1fe0deb3771e9a32bd7e35e7cbefc4e757d377043f78c6be4af71f87be25edcab7b73ef6eaaf16eb67e92dddc2ddc87fbf4ff6e9f9ffe73e93f57eecb6dfb081ff7fbbffffcf53f54dd2532</data>
+ </pixmap>
+ <slot access="public">newGame()</slot>
+ <slot access="public">swapSides()</slot>
+ <slot access="public">setTheme(QString)</slot>
+ </customwidget>
+</customwidgets>
+</CW>
diff --git a/noncore/games/chess/chess.cpp b/noncore/games/chess/chess.cpp
new file mode 100644
index 0000000..96a838a
--- a/dev/null
+++ b/noncore/games/chess/chess.cpp
@@ -0,0 +1,358 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+// human is not offered a promotion yet
+
+#include <qcanvas.h>
+#include <qmainwindow.h>
+#include <qlist.h>
+#include <qimage.h>
+#include <qpainter.h>
+#include <qmessagebox.h>
+#include <qregexp.h>
+
+#include <qpe/config.h>
+#include <qpe/resource.h>
+
+#include "chess.h"
+
+#define CHESS_DEBUG
+
+int pieceSize = 40;
+static QVector < QImage > imgList;
+int timeMoves, timeTime;
+
+int BoardView::convertToRank(int r)
+{
+ r = r / pieceSize;
+ if (humanSide == sideWhite)
+ r = 8 - r;
+ else
+ r++;
+ return r;
+}
+
+char BoardView::convertToFile(int f)
+{
+ f = f / pieceSize;
+ if (humanSide == sideWhite)
+ return f + 'a';
+ else
+ return 'h' - f;
+}
+
+int BoardView::convertFromFile(char f)
+{
+ if (humanSide == sideWhite)
+ f = f - 'a';
+ else
+ f = 'h' - f;
+ return f * pieceSize;
+}
+
+int BoardView::convertFromRank(int r)
+{
+ if (humanSide == sideWhite)
+ r = 8 - r;
+ else
+ r--;
+ return r * pieceSize;
+}
+
+// Pieces
+Piece::Piece(QCanvas * canvas, int t):QCanvasRectangle(canvas)
+{
+ type = t;
+ setSize(pieceSize, pieceSize);
+ show();
+}
+
+Piece *BoardView::newPiece(int t, char f, int r)
+{
+ Piece *tmpPiece = new Piece(canvas(), t);
+ tmpPiece->move(convertFromFile(f), convertFromRank(r));
+ list.append(tmpPiece);
+ return tmpPiece;
+}
+
+void BoardView::deletePiece(Piece * p)
+{
+ list.remove(p);
+ canvas()->update();
+}
+
+void Piece::drawShape(QPainter & p)
+{
+ p.drawImage(int (x()), int (y()), *(imgList[type]));
+}
+
+void BoardView::buildImages(QImage theme)
+{
+ imgList.resize(12);
+ int x;
+ int y = 0;
+
+ for (int j = 0; j < 2; j++) {
+ x = 0;
+ for (int i = 0; i < 6; i++) {
+ imgList.insert(i + (j * 6),
+ new QImage(theme.
+ copy(x, y, pieceSize, pieceSize)));
+ x += pieceSize;
+ }
+ y += pieceSize;
+ }
+}
+
+void BoardView::readStdout()
+{
+ QString input( crafty->readStdout() );
+#ifdef CHESS_DEBUG
+ qDebug("received this string from crafty->\n%s\n", input.latin1());
+#endif
+
+ int startPosition = input.find("setboard");
+ if (startPosition != -1)
+ decodePosition(input.remove(0, startPosition + 9));
+
+ if (input.contains("Black mates")) {
+ playingGame = FALSE;
+ emit(showMessage("Black mates"));
+ } else if (input.contains("White mates")) {
+ playingGame = FALSE;
+ emit(showMessage("White mates"));
+ } else if (input.contains(" resigns")) {
+ playingGame = FALSE;
+ emit(showMessage("Computer resigns"));
+ } else if (input.contains("Draw")) {
+ playingGame = FALSE;
+ emit(showMessage("Draw"));
+ }
+}
+
+// this is pretty close to getting done right
+// maybe dont use sprites and just draw a picture
+// there'll be lots of drawing done anyway
+// eg creating pictures for the webpages,
+// and presenting options for promotions
+void BoardView::decodePosition(const QString & t)
+{
+ qDebug("decode copped %s \n", t.latin1());
+
+ int count = 0;
+ int stringPos = 0;
+ for (int file = 0; file < 8; file++) {
+ for (int rank = 0; rank < 8; rank++) {
+ if (count)
+ count--;
+ else {
+ if (t.at(stringPos).isNumber())
+ count = t.at(stringPos).digitValue();
+ else {
+ newPiece(t.at(stringPos).latin1(), 'a' + file,
+ rank + 1);
+ }
+ }
+ }
+ }
+}
+
+void BoardView::undo()
+{
+ crafty->writeToStdin("undo\n");
+ crafty->writeToStdin("savepos\nclock\n");
+}
+
+void BoardView::emitErrorMessage()
+{
+ if (activeSide != humanSide)
+ emit(showMessage("Not your move"));
+ else
+ emit(showMessage("You are not playing a game"));
+}
+
+void BoardView::annotateGame()
+{
+ crafty->
+ writeToStdin
+ ("savegame game.save\nannotateh game.save bw 0 1.0 1\n");
+ emit(showMessage("Annotating game"));
+}
+
+Piece *BoardView::findPiece(char f, int r)
+{
+ QListIterator < Piece > it(list);
+ Piece *tmpPiece;
+ for (; it.current(); ++it) {
+ tmpPiece = it.current();
+ if (convertToRank(tmpPiece->x()) == r
+ && convertToFile(tmpPiece->y()) == f)
+ return tmpPiece;
+ }
+ return 0;
+}
+
+void BoardView::newGame()
+{
+ activeSide = sideWhite;
+ emit(showMessage("New game"));
+ crafty->writeToStdin("new\n");
+ crafty->writeToStdin("savepos\n");
+ crafty->writeToStdin("time " +
+ QString::number(timeMoves) +
+ "/" + QString::number(timeTime) + "\n");
+ activeSide = sideWhite;
+ if (humanSide == sideBlack)
+ crafty->writeToStdin("go\n");
+}
+
+void BoardView::setTheme(QString filename)
+{
+ QImage theme = Resource::loadImage(QString("chess/") + filename);
+ pieceSize = theme.height() / 2;
+ setFrameStyle(QFrame::Plain);
+ setFixedSize(8 * pieceSize, 8 * pieceSize);
+ canvas()->setBackgroundColor(Qt::red);
+ canvas()->resize(8 * pieceSize, 8 * pieceSize);
+ whiteSquare = theme.copy(6 * pieceSize, 0, pieceSize, pieceSize);
+ activeWhiteSquare = theme.copy(7 * pieceSize, 0, pieceSize, pieceSize);
+ blackSquare =
+ theme.copy(6 * pieceSize, pieceSize, pieceSize, pieceSize);
+ activeBlackSquare =
+ theme.copy(7 * pieceSize, pieceSize, pieceSize, pieceSize);
+ buildImages(theme);
+ drawBackgroundImage(QPoint(-1, -1));
+}
+
+
+// sets the bg to the default background image for the current theme
+// also resposible for drawing the "active" marker
+void BoardView::drawBackgroundImage(QPoint activeSquare)
+{
+ bg = QPixmap(8 * pieceSize, 8 * pieceSize);
+ QPainter p(&bg);
+ bool col = FALSE;
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0; j < 8; j++) {
+ QPoint point(i * pieceSize, j * pieceSize);
+ if (col) {
+ if (point.x() == activeSquare.x()
+ && point.y() == activeSquare.y())
+ p.drawImage(point, activeBlackSquare);
+ else
+ p.drawImage(point, blackSquare);
+ col = FALSE;
+ } else {
+ if (point.x() == activeSquare.x()
+ && point.y() == activeSquare.y())
+ p.drawImage(point, activeWhiteSquare);
+ else
+ p.drawImage(point, whiteSquare);
+ col = TRUE;
+ }
+ }
+ col = !col;
+ }
+ canvas()->setBackgroundPixmap(bg);
+ canvas()->update();
+}
+
+
+// Board view widget
+void BoardView::contentsMousePressEvent(QMouseEvent * e)
+{
+ QCanvasItemList cList = canvas()->collisions(e->pos());
+ if (activeSide == humanSide && playingGame) {
+ if (!activePiece) {
+ if (cList.count()) {
+ activePiece = (Piece *) (*(cList.at(0)));
+ drawBackgroundImage(QPoint
+ (activePiece->x(), activePiece->y()));
+ }
+ } else {
+ if (!(activePiece == (Piece *) (*(cList.at(0))))) {
+ char fromFile = convertToFile(activePiece->x());
+ int fromRank = convertToRank(activePiece->y());
+ char toFile = convertToFile(e->pos().x());
+ int toRank = convertToRank(e->pos().y());
+ QString moveS;
+ moveS.append(fromFile);
+ moveS.append(moveS.number(fromRank));
+ moveS.append(toFile);
+ moveS.append(moveS.number(toRank));
+ if ((activePiece->type == wPawn
+ && fromRank == 7 && toRank == 8)
+ || (activePiece->type == bPawn
+ && fromRank == 2 && toRank == 1)) {
+ // offer a promotion
+ emit(showMessage
+ ("you are meant to be offered a promotion here"));
+ char promoteTo = wQueen; // doesnt matter for now
+ moveS.append(promoteTo);
+ moveS.append("\n");
+ crafty->writeToStdin(moveS.latin1());
+ }
+ }
+ activePiece = 0;
+ drawBackgroundImage(QPoint(-1, -1));
+ }
+ }
+
+ else {
+ emitErrorMessage();
+ }
+}
+
+void BoardView::swapSides()
+{
+ if (activeSide == humanSide && playingGame) {
+ humanSide = !humanSide;
+ crafty->writeToStdin("savepos\ngo\n");
+ } else
+ emitErrorMessage();
+}
+
+BoardView::BoardView(QCanvas *c, QWidget *w, const char *name)
+ : QCanvasView(c, w, name) {
+ humanSide = sideWhite;
+ activeSide = sideWhite;
+ playingGame = TRUE;
+ activePiece = 0;
+ list.setAutoDelete(TRUE);
+ setCanvas(new QCanvas());
+ Config c("Chess", Config::User);
+ c.setGroup("Theme");
+ QString theme = c.readEntry("imagefile", "simple-28");
+ setTheme(theme);
+ crafty = new CraftyProcess(this);
+ crafty->addArgument("crafty");
+ if (!crafty->start()) {
+ QMessageBox::critical(0,
+ tr("Could not find crafty chess engine"),
+ tr("Quit"));
+ exit(-1);
+ }
+
+ connect(crafty, SIGNAL(readyReadStdout()), this, SLOT(readStdout()));
+ connect(crafty, SIGNAL(processExited()), this, SLOT(craftyDied()));
+// crafty->writeToStdin("xboard\nics\nkibitz=2\n");
+ newGame();
+}
diff --git a/noncore/games/chess/chess.db b/noncore/games/chess/chess.db
new file mode 100644
index 0000000..b520b30
--- a/dev/null
+++ b/noncore/games/chess/chess.db
@@ -0,0 +1,2 @@
+<!DOCTYPE DB><DB version="1.0">
+</DB>
diff --git a/noncore/games/chess/chess.h b/noncore/games/chess/chess.h
new file mode 100644
index 0000000..067b2f8
--- a/dev/null
+++ b/noncore/games/chess/chess.h
@@ -0,0 +1,128 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+** $Id$
+**
+**********************************************************************/
+#ifndef CHESS_H
+#define CHESS_H
+
+#include <qwidget.h>
+#include <qcanvas.h>
+#include <qmainwindow.h>
+#include <qpixmap.h>
+#include <qimage.h>
+#include <qstack.h>
+#include <qvector.h>
+#include <qpe/process.h>
+
+#define wPawn 'P'
+#define wKnight 'N'
+#define wBishop 'B'
+#define wRook 'R'
+#define wQueen 'Q'
+#define wKing 'K'
+#define bPawn 'p'
+#define bKnight 'n'
+#define bBishop 'b'
+#define bRook 'r'
+#define bQueen 'q'
+#define bKing 'k'
+#define NONE N
+
+#define sideWhite 0
+#define sideBlack 1
+
+
+class Piece:public QCanvasRectangle {
+ public:
+ Piece(QCanvas *, int);
+ ~Piece() {
+ };
+
+ char type;
+
+ protected:
+ void drawShape(QPainter &);
+};
+
+
+class CraftyProcess : public Process {
+ public:
+ CraftyProcess(QObject *parent) : Process( parent ) { qDebug("CraftyProcess functions not implemented"); }
+ ~CraftyProcess() { }
+ bool start() { qDebug("CraftyProcess functions not implemented"); return FALSE; }
+ const char *readStdout() { qDebug("CraftyProcess functions not implemented"); return "Blah"; }
+ void writeToStdin(const char *) { qDebug("CraftyProcess functions not implemented"); }
+};
+
+
+class BoardView:public QCanvasView {
+ Q_OBJECT public:
+ BoardView(QCanvas *, QWidget *, const char *);
+ ~BoardView() {
+ };
+
+ protected:
+ void contentsMousePressEvent(QMouseEvent *);
+
+ signals:
+ void showMessage(const QString &);
+
+ public slots:void readStdout();
+ void craftyDied() {
+ qFatal("Crafty died unexpectedly\n");
+ };
+ void newGame();
+ void setTheme(QString);
+ void swapSides();
+ void undo();
+ void annotateGame();
+
+ private:
+ CraftyProcess * crafty;
+ QList < Piece > list;
+ Piece *activePiece;
+
+ void revertLastMove();
+ void emitErrorMessage();
+ void drawBackgroundImage(QPoint activeSquare);
+
+ void buildImages(QImage);
+
+ char convertToFile(int);
+ int convertToRank(int);
+ int convertFromFile(char);
+ int convertFromRank(int);
+
+ void decodePosition(const QString & t);
+
+ Piece *findPiece(char f, int r);
+ Piece *newPiece(int, char, int);
+ void deletePiece(Piece *);
+
+ int pieceSize;
+ QPixmap bg;
+ QImage whiteSquare, blackSquare, activeWhiteSquare, activeBlackSquare;
+
+ bool humanSide;
+ bool activeSide;
+ bool playingGame;
+};
+
+#endif
diff --git a/noncore/games/chess/chess.pro b/noncore/games/chess/chess.pro
new file mode 100644
index 0000000..f6650a0
--- a/dev/null
+++ b/noncore/games/chess/chess.pro
@@ -0,0 +1,14 @@
+SOURCES += chess.cpp main.cpp
+HEADERS += chess.h
+DESTDIR = ../bin
+TARGET = chess
+DEPENDPATH += $(QPEDIR)/include
+INTERFACES = mainwindow.ui
+IMAGES = images/new.png images/repeat.png images/txt.png images/back.png
+TEMPLATE =app
+CONFIG += qt warn_on release
+INCLUDEPATH += $(QPEDIR)/include
+LIBS += -lqpe
+DBFILE = chess.db
+LANGUAGE = C++
+CPP_ALWAYS_CREATE_SOURCE = TRUE
diff --git a/noncore/games/chess/main.cpp b/noncore/games/chess/main.cpp
new file mode 100644
index 0000000..a56913f
--- a/dev/null
+++ b/noncore/games/chess/main.cpp
@@ -0,0 +1,51 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+** $Id$
+**
+**********************************************************************/
+#include <qpe/qpeapplication.h>
+#include <qpe/qpetoolbar.h>
+#include <qmainwindow.h>
+#include <qcanvas.h>
+#include "chess.h"
+
+
+class CanvasMainWindow : public QMainWindow {
+public:
+ CanvasMainWindow(QWidget* parent=0, const char* name=0, WFlags f=0)
+ : QMainWindow(parent,name,f), canvas(232, 258) {
+ view = new BoardView(&canvas, this, 0);
+ setToolBarsMovable( FALSE );
+ QPEToolBar* toolbar = new QPEToolBar(this);
+ toolbar->setHorizontalStretchable( TRUE );
+ }
+
+private:
+ QCanvas canvas;
+ BoardView *view;
+};
+
+
+int main( int argc, char **argv ) {
+ QPEApplication a(argc,argv);
+ CanvasMainWindow *mw = new CanvasMainWindow();
+ a.showMainWidget( mw );
+ return a.exec();
+}
+
diff --git a/noncore/games/chess/mainwindow.ui b/noncore/games/chess/mainwindow.ui
new file mode 100644
index 0000000..dc3ae0f
--- a/dev/null
+++ b/noncore/games/chess/mainwindow.ui
@@ -0,0 +1,220 @@
+<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
+<class>MainWindow</class>
+<widget class="QMainWindow">
+ <property name="name">
+ <cstring>MainWindow</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>256</width>
+ <height>338</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Chess</string>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>TextLabel1</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>236</y>
+ <width>221</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>TextLabel1</string>
+ </property>
+ </widget>
+ <widget class="BoardView">
+ <property name="name">
+ <cstring>ChessBoard</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>224</width>
+ <height>224</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>1</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>224</width>
+ <height>224</height>
+ </size>
+ </property>
+ </widget>
+</widget>
+<menubar>
+ <property name="name">
+ <cstring>menubar</cstring>
+ </property>
+ <item text="Game" name="PopupMenu_2">
+ <action name="newGame"/>
+ <action name="annotateGame"/>
+ </item>
+ <item text="Position" name="PopupMenu_3">
+ <action name="swapSides"/>
+ <action name="undo"/>
+ </item>
+</menubar>
+<toolbars>
+</toolbars>
+<customwidgets>
+ <customwidget>
+ <class>BoardView</class>
+ <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
+ <sizehint>
+ <width>-1</width>
+ <height>-1</height>
+ </sizehint>
+ <container>0</container>
+ <sizepolicy>
+ <hordata>5</hordata>
+ <verdata>5</verdata>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ <pixmap>image0</pixmap>
+ <signal>showMessage(const QString&amp;)</signal>
+ <slot access="public" specifier="">newGame()</slot>
+ <slot access="public" specifier="">swapSides()</slot>
+ <slot access="public" specifier="">setTheme(QString)</slot>
+ <slot access="public" specifier="">undo()</slot>
+ <slot access="public" specifier="">annotateGame()</slot>
+ </customwidget>
+</customwidgets>
+<actions>
+ <actiongroup>
+ <property name="name">
+ <cstring>gameActions</cstring>
+ </property>
+ <property name="text">
+ <string>ActionGroup</string>
+ </property>
+ <property name="usesDropDown">
+ <bool>false</bool>
+ </property>
+ <action>
+ <property name="name">
+ <cstring>newGame</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>new.png</iconset>
+ </property>
+ <property name="text">
+ <string>New Game</string>
+ </property>
+ <property name="menuText">
+ <string>New Game</string>
+ </property>
+ <property name="toolTip">
+ <string>New Game</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>swapSides</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>repeat.png</iconset>
+ </property>
+ <property name="text">
+ <string>Swap sides</string>
+ </property>
+ <property name="toolTip">
+ <string>Swap sides</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>annotateGame</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>txt.png</iconset>
+ </property>
+ <property name="text">
+ <string>Annotate game</string>
+ </property>
+ <property name="toolTip">
+ <string>Annotate game</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>undo</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>back.png</iconset>
+ </property>
+ <property name="text">
+ <string>Undo move</string>
+ </property>
+ <property name="toolTip">
+ <string>Undo move</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>saveGame</cstring>
+ </property>
+ <property name="text">
+ <string>Action</string>
+ </property>
+ </action>
+ </actiongroup>
+</actions>
+<images>
+ <image name="image0">
+ <data format="XPM.GZ" length="3456">789ce5d35d5313491406e07b7e458abea3b68e99cfccd4d65ee0079ac8a720a2d65ef474cf2424229004152dffbba7cf795941182a59bcd8aa6548524fbafb9d9ed3278fd63a47bb5b9db5472bb3b99d1fbb8e1bd96967cd5f9c9c5cbefffbaf6f2bab49dce1ff5eaf13affeb1b24aa6e33aa62b7f620fa7b01517ec423c850bb571b0c3f8bbe0a8db7591ae1fa9c3257e0aa7b0ac8f0ab6aeefc305bc073b783d38ee462ed6f5953a5ce20d38859f894b7629de820bb519c20ee3af829328764924be50275d7806a76a732c2ed9ba7e08176a33811d2cf548a3c4a59a97a9d3aedad4708af153b1655bf14bb880bfc00e3e0fcee2ac9be9f926629b65998eefc21e3e0acee3cce73affb33acfe037ff58e737629b97f026ece128b897e4be9788bfaa7b119cc319fc445cb12bf1215caa8d813d2cfd59243d5fe8faaeb82ab242d7d770097f803d2ce751a66554a6e28f70a636d24fa5633b191fc325fc1cf6f049b04d6d6435ef139cc16fc5ce5aabf3b7e11ade09ae525b573a7f5f5dc5f00bb1aff2ca8b07b0559b315c63fc20d86555ed32f15ced62f812ce61e95fe7d99a67610b3770ada65eb0e776f1bafe4c5cb36bf16bd8c245709dd7719d8b5371cddfc8b821d8aa290e6e78b4d1f9a5ba89e1c7e2a6b14d13bc37879b2bdf7f91b9fffadf65d8df90519123ffc08c9a1a1ad2a86d3ff767d0318d69421fe8843ed229a72c9d4167742ef79ed28ce69c7471f713b567d027beef675ea733bfd0257da5f5bb52da32e8313de18ca7f48c67add30657f539bde07df597c818d04bdae41a84593557654a5bb44d3bb44b7bbfeea53563c2ab467c1a61569f77123e5fd13e1d704a7533a535e3351dd21b3afa65dfeb9cf09677f86ec19a7679e64cea71f3daa788ebb45846cccf93dcaae1942bbb793be38e339ff2b34f28e5f7ab6f4e29e33a8c68f3f6dd5a320cdf29a7deb58c824aeeb31d434b64f48de1351b5736b6fd17d192e1a9321577d5cfe73e5c32c31ac79db16dfccf3e30f55219533e8b53634c73bd3bcc90e285332cf7f21177f51977d9f046775d2e9e6146fc8bbdabcab816c89872270f1e98e1f909c6b4c5cf7f71f5e2f7637e9fe9e742f5e8d3399feb3e0dcc9877744083f613693d174b23befbcc4ccc84b2f0fa1719d7d37c783d28a3b58affd18cef7faefc007d894af5</data>
+ </image>
+</images>
+<connections>
+ <connection>
+ <sender>newGame</sender>
+ <signal>activated()</signal>
+ <receiver>ChessBoard</receiver>
+ <slot>newGame()</slot>
+ </connection>
+ <connection>
+ <sender>swapSides</sender>
+ <signal>activated()</signal>
+ <receiver>ChessBoard</receiver>
+ <slot>swapSides()</slot>
+ </connection>
+ <connection>
+ <sender>annotateGame</sender>
+ <signal>activated()</signal>
+ <receiver>ChessBoard</receiver>
+ <slot>annotateGame()</slot>
+ </connection>
+ <connection>
+ <sender>undo</sender>
+ <signal>activated()</signal>
+ <receiver>ChessBoard</receiver>
+ <slot>undo()</slot>
+ </connection>
+ <connection>
+ <sender>ChessBoard</sender>
+ <signal>showMessage(const QString&amp;)</signal>
+ <receiver>TextLabel1</receiver>
+ <slot>setText(const QString&amp;)</slot>
+ </connection>
+</connections>
+<pixmapinproject/>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/noncore/games/chess/pieces.png b/noncore/games/chess/pieces.png
new file mode 100644
index 0000000..4baeb4a
--- a/dev/null
+++ b/noncore/games/chess/pieces.png
Binary files differ
diff --git a/noncore/games/chess/qpe-chess.control b/noncore/games/chess/qpe-chess.control
new file mode 100644
index 0000000..2a7d2d2
--- a/dev/null
+++ b/noncore/games/chess/qpe-chess.control
@@ -0,0 +1,9 @@
+Files: bin/chess apps/Games/chess.desktop
+Priority: optional
+Section: qpe/games
+Maintainer: Luke Graham <luke@trolltech.com>
+Architecture: arm
+Version: $QPE_VERSION-3
+Depends: qpe-base ($QPE_VERSION)
+Description: Crafty GUI
+ A GUI for the crafty chess engine
diff --git a/noncore/games/chess/simple-l.png b/noncore/games/chess/simple-l.png
new file mode 100644
index 0000000..908e2e1
--- a/dev/null
+++ b/noncore/games/chess/simple-l.png
Binary files differ