summaryrefslogtreecommitdiff
path: root/noncore/games/chess
Unidiff
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 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) -DQCONFIG=\"qpe\"
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS) -DQCONFIG=\"qpe\"
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../bin/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= chess
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =chess.h
27 SOURCES =chess.cpp \
28 main.cpp
29 OBJECTS =chess.o \
30 main.o \
31 mainwindow.o
32INTERFACES = mainwindow.ui
33UICDECLS = mainwindow.h
34UICIMPLS = mainwindow.cpp
35 SRCMOC =moc_chess.cpp \
36 moc_mainwindow.cpp
37 OBJMOC =moc_chess.o \
38 moc_mainwindow.o
39
40
41####### Implicit rules
42
43.SUFFIXES: .cpp .cxx .cc .C .c
44
45.cpp.o:
46 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
47
48.cxx.o:
49 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
50
51.cc.o:
52 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
53
54.C.o:
55 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
56
57.c.o:
58 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
59
60####### Build rules
61
62
63all: $(DESTDIR)$(TARGET)
64
65$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
66 $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
67
68moc: $(SRCMOC)
69
70tmake:
71 tmake chess.pro
72
73clean:
74 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
75 -rm -f *~ core
76 -rm -f allmoc.cpp
77
78####### Extension Modules
79
80listpromodules:
81 @echo
82
83listallmodules:
84 @echo
85
86listaddonpromodules:
87 @echo
88
89listaddonentmodules:
90 @echo
91
92
93REQUIRES=
94
95####### Sub-libraries
96
97
98###### Combined headers
99
100
101
102####### Compile
103
104chess.o: chess.cpp \
105 $(QPEDIR)/include/qpe/config.h \
106 $(QPEDIR)/include/qpe/resource.h \
107 chess.h
108
109main.o: main.cpp \
110 mainwindow.h
111
112mainwindow.h: mainwindow.ui
113 $(UIC) mainwindow.ui -o $(INTERFACE_DECL_PATH)/mainwindow.h
114
115mainwindow.cpp: mainwindow.ui
116 $(UIC) mainwindow.ui -i mainwindow.h -o mainwindow.cpp
117
118mainwindow.o: mainwindow.cpp \
119 mainwindow.h \
120 mainwindow.ui
121
122moc_chess.o: moc_chess.cpp \
123 chess.h
124
125moc_mainwindow.o: moc_mainwindow.cpp \
126 mainwindow.h
127
128moc_chess.cpp: chess.h
129 $(MOC) chess.h -o moc_chess.cpp
130
131moc_mainwindow.cpp: mainwindow.h
132 $(MOC) mainwindow.h -o moc_mainwindow.cpp
133
134
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 @@
1<!DOCTYPE CW><CW>
2<customwidgets>
3 <customwidget>
4 <class>BoardView</class>
5 <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
6 <sizehint>
7 <width>-1</width>
8 <height>-1</height>
9 </sizehint>
10 <container>0</container>
11 <sizepolicy>
12 <hordata>5</hordata>
13 <verdata>5</verdata>
14 </sizepolicy>
15 <pixmap>
16 <data format="XPM.GZ" length="4605">789c6dd7d96ee33a1206e0fb7e8aa0ebae31a863c9966d613017d9e3ecce9e0ce6a228c94b6c67f192d83998771f9af517e10493b4daf89a25b258a428f75f7fb61e2ecfb6fefcf56b3697f9b0d82a0632ddfa532e2693d5bffff3afbf7ffd4ed3adf027d94a7fffe3d76ff7b9556c9dbfbe5401ef9bf8d8c464136f9b186ee27513cf9bd8dec47c13d30d74bfb52c3d28cdd322a9058fd6aee7f5a29e047f697bbd96b483573fe2173ffc82fbdbb87fb0762389fdcdd6ee859fe0716ccfd7e6def7fed8c5f1d5c5f77c58c2788959ea70230dfd3982dba9de7f6ff9693b757ee4dbb7f9a3fdf5473d7aea464dfb23fa3e3fdafe319f3d75a3a1edbc0fb7913f9991df8b19f7977081f1ae83c5da89cd8dd0bf34601bffceaced14facfd22c53f36db484f95570a9e3398ed6f1c27ec8c4e239877378d79c85bd4f477089f117d1219ee666c4d7d4cd04fddd98d1de5ebb995abc3ca863fb04467eb26746fc398c7ce5c0aced7c1dade3bfc2983f5766acf7be19f59f466b3d4b752bc1fd9a9f58ffd28311cf6d33f2b9323735ff17752bc17855b4f697c119f2cbcd884fe15cd757d6c711b5ea2dd48766708efd959871ffb319f53c86ad1e67d1fafc89ba9d60bcaf68edffca8ce7ab8033c4b7a2b57e3bc1ae95b7eac1db70091fa9db895a6e61ab472b3af4277730e6cb5d33e69bc3781e6865c6f31ce6d3f6f9b75c881738d3f5e2b119ed27708ef655b4aedf0d6cf5fc50e709f27d84510fb930e3f94a615bdf6bb3f627f7b0cd47f3f5f36d877a5103b67af6cddace23759e20fe00b6e77da016acb77370a6e71df5cc18bf1fadfb610c0bcef304ae6aeab619ef83f57b92f286e5c3cfd1a1de3c803378095bbd9bea98cf305af7430b16d47319adf53f34637daee00af9f7d52ed57c692f5acf7fbdbfc8f3bc113c834be43b35a37d185d84feeed482fd47e77086fdbf0b57d81f75b54b311f8ad6f95e9a319f1adc44fed3689ddf132c589f8e59e385a3b5fdcc8cf1bb30d697a2311eea53a07e1cce7b6948a2f52007676ad956bb14e7e53e6cebb382adff67339eb7a5dac6930f33ce87266cf5388dd6f50ccf83f87a8baed77bb4aed78edaa5c877085738ff3fcdd89f13b58d4f68b7f1e5d48cfd589a118ff10bd49b9ea235fe12aef0fc55669c6fe17c718d42701ececcfafea2118cfb3935e3bcf98cd6f18ecc785fbd99f1beabab4bab77c38cef2b613d5c5908ced357b8c2799aa9637c12ade32dcc787fedc04d7c1fb935e33c7b8cd6f509df578aac10acef02aef0bc76ccbade7caeb6fb656ec6fe1c98f1fc5ec2a82f9f9931bf5ab4e67b0263bf70d80f455956e8efc6acf9d185ba4a51bfb119e779789f97be7f9d1fbda9637b19adf73b33e21fe026ea7162c6f31ad6a7acaad4e9fe1fc1d6be1badf53b36a39e4fb0e5771f1dda257c7fa89a668a76657013b6f509eb5bf99f225bbb3b5fff32b1b0e3c25fffefb3d4288de78a7bdce7010ffdf5cca38dabef7fc73ce1177fcf6b8c77fcc6ef3cf56d6f3ce3392ff8833f79c92bfee26ddef1f1bbbcc785c6f3be8f3be0433ef2b11d3ee6133ee5333ee70bbee42e5ff135dff02ddff13d5388179fc5d4f7f4c08ffcc4354e38e53a3738f39f4d6e719b73ce898958d7a7c74312725450491537a9477d1ad0909e69e4e39b34a609bdf01dbdb2d6abf0fd3ff8e8377aa729cd684e8b704de8833e69e97f57f4e5fbdf8efd3fd30eed724a7bb44f733ff6fa3ae0aebf6be5a30f7d2f473ebe8378f1f1c77442a77416fb3ea70bba0c77f47c465dbaa2eb6ffddfd0adefddfabea37b7aa0477aa21a25beff25a5a17fcbff994a4ea88ebe1b9451d3d734a116b529f7d15df1cbefe71bfbe753ba145af72d224e7ca5f84c4aa9bc7b7edca5f4bfe72f03df3ea485f83b652463bf0a19d765e2df012febfcb9f53d7f79f5f16ff22e5399c95c16f2219f7ec512ffe9eb232bf9fa96ff48b67ddb8eecca9eef719fbb72208772b45ee175fda523c7dff2efcb899cfad57a973339478de672219721ba2b573fea3fe61db9f6792eb9292c37722b77d4926558dbaecfa62ff73eff4eec7fc2d7f2208f612dfde5ef3c44e493cfa523354924953af22fa5e1f7f7adaf9dff4f9d5fcb25aeae7468202d1fdd96dcb123ddcfe179d9f3fbef3a5c95131abbf54fc1fe0deb3771e9a32bd7e35e7cbefc4e757d377043f78c6be4af71f87be25edcab7b73ef6eaaf16eb67e92dddc2ddc87fbf4ff6e9f9ffe73e93f57eecb6dfb081ff7fbbffffcf53f54dd2532</data>
17 </pixmap>
18 <slot access="public">newGame()</slot>
19 <slot access="public">swapSides()</slot>
20 <slot access="public">setTheme(QString)</slot>
21 </customwidget>
22</customwidgets>
23</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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22// human is not offered a promotion yet
23
24#include <qcanvas.h>
25#include <qmainwindow.h>
26#include <qlist.h>
27#include <qimage.h>
28#include <qpainter.h>
29#include <qmessagebox.h>
30#include <qregexp.h>
31
32#include <qpe/config.h>
33#include <qpe/resource.h>
34
35#include "chess.h"
36
37#define CHESS_DEBUG
38
39int pieceSize = 40;
40static QVector < QImage > imgList;
41int timeMoves, timeTime;
42
43int BoardView::convertToRank(int r)
44{
45 r = r / pieceSize;
46 if (humanSide == sideWhite)
47 r = 8 - r;
48 else
49 r++;
50 return r;
51}
52
53char BoardView::convertToFile(int f)
54{
55 f = f / pieceSize;
56 if (humanSide == sideWhite)
57 return f + 'a';
58 else
59 return 'h' - f;
60}
61
62int BoardView::convertFromFile(char f)
63{
64 if (humanSide == sideWhite)
65 f = f - 'a';
66 else
67 f = 'h' - f;
68 return f * pieceSize;
69}
70
71int BoardView::convertFromRank(int r)
72{
73 if (humanSide == sideWhite)
74 r = 8 - r;
75 else
76 r--;
77 return r * pieceSize;
78}
79
80// Pieces
81Piece::Piece(QCanvas * canvas, int t):QCanvasRectangle(canvas)
82{
83 type = t;
84 setSize(pieceSize, pieceSize);
85 show();
86}
87
88Piece *BoardView::newPiece(int t, char f, int r)
89{
90 Piece *tmpPiece = new Piece(canvas(), t);
91 tmpPiece->move(convertFromFile(f), convertFromRank(r));
92 list.append(tmpPiece);
93 return tmpPiece;
94}
95
96void BoardView::deletePiece(Piece * p)
97{
98 list.remove(p);
99 canvas()->update();
100}
101
102void Piece::drawShape(QPainter & p)
103{
104 p.drawImage(int (x()), int (y()), *(imgList[type]));
105}
106
107void BoardView::buildImages(QImage theme)
108{
109 imgList.resize(12);
110 int x;
111 int y = 0;
112
113 for (int j = 0; j < 2; j++) {
114 x = 0;
115 for (int i = 0; i < 6; i++) {
116 imgList.insert(i + (j * 6),
117 new QImage(theme.
118 copy(x, y, pieceSize, pieceSize)));
119 x += pieceSize;
120 }
121 y += pieceSize;
122 }
123}
124
125void BoardView::readStdout()
126{
127 QString input( crafty->readStdout() );
128#ifdef CHESS_DEBUG
129 qDebug("received this string from crafty->\n%s\n", input.latin1());
130#endif
131
132 int startPosition = input.find("setboard");
133 if (startPosition != -1)
134 decodePosition(input.remove(0, startPosition + 9));
135
136 if (input.contains("Black mates")) {
137 playingGame = FALSE;
138 emit(showMessage("Black mates"));
139 } else if (input.contains("White mates")) {
140 playingGame = FALSE;
141 emit(showMessage("White mates"));
142 } else if (input.contains(" resigns")) {
143 playingGame = FALSE;
144 emit(showMessage("Computer resigns"));
145 } else if (input.contains("Draw")) {
146 playingGame = FALSE;
147 emit(showMessage("Draw"));
148 }
149}
150
151// this is pretty close to getting done right
152// maybe dont use sprites and just draw a picture
153// there'll be lots of drawing done anyway
154// eg creating pictures for the webpages,
155// and presenting options for promotions
156void BoardView::decodePosition(const QString & t)
157{
158 qDebug("decode copped %s \n", t.latin1());
159
160 int count = 0;
161 int stringPos = 0;
162 for (int file = 0; file < 8; file++) {
163 for (int rank = 0; rank < 8; rank++) {
164 if (count)
165 count--;
166 else {
167 if (t.at(stringPos).isNumber())
168 count = t.at(stringPos).digitValue();
169 else {
170 newPiece(t.at(stringPos).latin1(), 'a' + file,
171 rank + 1);
172 }
173 }
174 }
175 }
176}
177
178void BoardView::undo()
179{
180 crafty->writeToStdin("undo\n");
181 crafty->writeToStdin("savepos\nclock\n");
182}
183
184void BoardView::emitErrorMessage()
185{
186 if (activeSide != humanSide)
187 emit(showMessage("Not your move"));
188 else
189 emit(showMessage("You are not playing a game"));
190}
191
192void BoardView::annotateGame()
193{
194 crafty->
195 writeToStdin
196 ("savegame game.save\nannotateh game.save bw 0 1.0 1\n");
197 emit(showMessage("Annotating game"));
198}
199
200Piece *BoardView::findPiece(char f, int r)
201{
202 QListIterator < Piece > it(list);
203 Piece *tmpPiece;
204 for (; it.current(); ++it) {
205 tmpPiece = it.current();
206 if (convertToRank(tmpPiece->x()) == r
207 && convertToFile(tmpPiece->y()) == f)
208 return tmpPiece;
209 }
210 return 0;
211}
212
213void BoardView::newGame()
214{
215 activeSide = sideWhite;
216 emit(showMessage("New game"));
217 crafty->writeToStdin("new\n");
218 crafty->writeToStdin("savepos\n");
219 crafty->writeToStdin("time " +
220 QString::number(timeMoves) +
221 "/" + QString::number(timeTime) + "\n");
222 activeSide = sideWhite;
223 if (humanSide == sideBlack)
224 crafty->writeToStdin("go\n");
225}
226
227void BoardView::setTheme(QString filename)
228{
229 QImage theme = Resource::loadImage(QString("chess/") + filename);
230 pieceSize = theme.height() / 2;
231 setFrameStyle(QFrame::Plain);
232 setFixedSize(8 * pieceSize, 8 * pieceSize);
233 canvas()->setBackgroundColor(Qt::red);
234 canvas()->resize(8 * pieceSize, 8 * pieceSize);
235 whiteSquare = theme.copy(6 * pieceSize, 0, pieceSize, pieceSize);
236 activeWhiteSquare = theme.copy(7 * pieceSize, 0, pieceSize, pieceSize);
237 blackSquare =
238 theme.copy(6 * pieceSize, pieceSize, pieceSize, pieceSize);
239 activeBlackSquare =
240 theme.copy(7 * pieceSize, pieceSize, pieceSize, pieceSize);
241 buildImages(theme);
242 drawBackgroundImage(QPoint(-1, -1));
243}
244
245
246// sets the bg to the default background image for the current theme
247// also resposible for drawing the "active" marker
248void BoardView::drawBackgroundImage(QPoint activeSquare)
249{
250 bg = QPixmap(8 * pieceSize, 8 * pieceSize);
251 QPainter p(&bg);
252 bool col = FALSE;
253 for (int i = 0; i < 8; i++) {
254 for (int j = 0; j < 8; j++) {
255 QPoint point(i * pieceSize, j * pieceSize);
256 if (col) {
257 if (point.x() == activeSquare.x()
258 && point.y() == activeSquare.y())
259 p.drawImage(point, activeBlackSquare);
260 else
261 p.drawImage(point, blackSquare);
262 col = FALSE;
263 } else {
264 if (point.x() == activeSquare.x()
265 && point.y() == activeSquare.y())
266 p.drawImage(point, activeWhiteSquare);
267 else
268 p.drawImage(point, whiteSquare);
269 col = TRUE;
270 }
271 }
272 col = !col;
273 }
274 canvas()->setBackgroundPixmap(bg);
275 canvas()->update();
276}
277
278
279// Board view widget
280void BoardView::contentsMousePressEvent(QMouseEvent * e)
281{
282 QCanvasItemList cList = canvas()->collisions(e->pos());
283 if (activeSide == humanSide && playingGame) {
284 if (!activePiece) {
285 if (cList.count()) {
286 activePiece = (Piece *) (*(cList.at(0)));
287 drawBackgroundImage(QPoint
288 (activePiece->x(), activePiece->y()));
289 }
290 } else {
291 if (!(activePiece == (Piece *) (*(cList.at(0))))) {
292 char fromFile = convertToFile(activePiece->x());
293 int fromRank = convertToRank(activePiece->y());
294 char toFile = convertToFile(e->pos().x());
295 int toRank = convertToRank(e->pos().y());
296 QString moveS;
297 moveS.append(fromFile);
298 moveS.append(moveS.number(fromRank));
299 moveS.append(toFile);
300 moveS.append(moveS.number(toRank));
301 if ((activePiece->type == wPawn
302 && fromRank == 7 && toRank == 8)
303 || (activePiece->type == bPawn
304 && fromRank == 2 && toRank == 1)) {
305 // offer a promotion
306 emit(showMessage
307 ("you are meant to be offered a promotion here"));
308 char promoteTo = wQueen;// doesnt matter for now
309 moveS.append(promoteTo);
310 moveS.append("\n");
311 crafty->writeToStdin(moveS.latin1());
312 }
313 }
314 activePiece = 0;
315 drawBackgroundImage(QPoint(-1, -1));
316 }
317 }
318
319 else {
320 emitErrorMessage();
321 }
322}
323
324void BoardView::swapSides()
325{
326 if (activeSide == humanSide && playingGame) {
327 humanSide = !humanSide;
328 crafty->writeToStdin("savepos\ngo\n");
329 } else
330 emitErrorMessage();
331}
332
333BoardView::BoardView(QCanvas *c, QWidget *w, const char *name)
334 : QCanvasView(c, w, name) {
335 humanSide = sideWhite;
336 activeSide = sideWhite;
337 playingGame = TRUE;
338 activePiece = 0;
339 list.setAutoDelete(TRUE);
340 setCanvas(new QCanvas());
341 Config c("Chess", Config::User);
342 c.setGroup("Theme");
343 QString theme = c.readEntry("imagefile", "simple-28");
344 setTheme(theme);
345 crafty = new CraftyProcess(this);
346 crafty->addArgument("crafty");
347 if (!crafty->start()) {
348 QMessageBox::critical(0,
349 tr("Could not find crafty chess engine"),
350 tr("Quit"));
351 exit(-1);
352 }
353
354 connect(crafty, SIGNAL(readyReadStdout()), this, SLOT(readStdout()));
355 connect(crafty, SIGNAL(processExited()), this, SLOT(craftyDied()));
356// crafty->writeToStdin("xboard\nics\nkibitz=2\n");
357 newGame();
358}
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 @@
1<!DOCTYPE DB><DB version="1.0">
2</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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19** $Id$
20**
21**********************************************************************/
22#ifndef CHESS_H
23#define CHESS_H
24
25#include <qwidget.h>
26#include <qcanvas.h>
27#include <qmainwindow.h>
28#include <qpixmap.h>
29#include <qimage.h>
30#include <qstack.h>
31#include <qvector.h>
32#include <qpe/process.h>
33
34#define wPawn 'P'
35 #definewKnight 'N'
36#define wBishop 'B'
37#define wRook 'R'
38#define wQueen 'Q'
39#define wKing 'K'
40#define bPawn 'p'
41#define bKnight 'n'
42#define bBishop 'b'
43#define bRook 'r'
44#define bQueen 'q'
45#define bKing 'k'
46#define NONE N
47
48#define sideWhite 0
49#define sideBlack 1
50
51
52class Piece:public QCanvasRectangle {
53 public:
54 Piece(QCanvas *, int);
55 ~Piece() {
56 };
57
58 char type;
59
60 protected:
61 void drawShape(QPainter &);
62};
63
64
65class CraftyProcess : public Process {
66 public:
67 CraftyProcess(QObject *parent) : Process( parent ) { qDebug("CraftyProcess functions not implemented"); }
68 ~CraftyProcess() { }
69 bool start() { qDebug("CraftyProcess functions not implemented"); return FALSE; }
70 const char *readStdout() { qDebug("CraftyProcess functions not implemented"); return "Blah"; }
71 void writeToStdin(const char *) { qDebug("CraftyProcess functions not implemented"); }
72};
73
74
75class BoardView:public QCanvasView {
76 Q_OBJECT public:
77 BoardView(QCanvas *, QWidget *, const char *);
78 ~BoardView() {
79 };
80
81 protected:
82 void contentsMousePressEvent(QMouseEvent *);
83
84 signals:
85 void showMessage(const QString &);
86
87 public slots:void readStdout();
88 void craftyDied() {
89 qFatal("Crafty died unexpectedly\n");
90 };
91 void newGame();
92 void setTheme(QString);
93 void swapSides();
94 void undo();
95 void annotateGame();
96
97 private:
98 CraftyProcess * crafty;
99 QList < Piece > list;
100 Piece *activePiece;
101
102 void revertLastMove();
103 void emitErrorMessage();
104 void drawBackgroundImage(QPoint activeSquare);
105
106 void buildImages(QImage);
107
108 char convertToFile(int);
109 int convertToRank(int);
110 int convertFromFile(char);
111 int convertFromRank(int);
112
113 void decodePosition(const QString & t);
114
115 Piece *findPiece(char f, int r);
116 Piece *newPiece(int, char, int);
117 void deletePiece(Piece *);
118
119 int pieceSize;
120 QPixmap bg;
121 QImage whiteSquare, blackSquare, activeWhiteSquare, activeBlackSquare;
122
123 bool humanSide;
124 bool activeSide;
125 bool playingGame;
126};
127
128#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 @@
1 SOURCES+= chess.cpp main.cpp
2 HEADERS+= chess.h
3DESTDIR = ../bin
4TARGET = chess
5 DEPENDPATH+= $(QPEDIR)/include
6INTERFACES = mainwindow.ui
7 IMAGES= images/new.png images/repeat.png images/txt.png images/back.png
8 TEMPLATE=app
9 CONFIG+= qt warn_on release
10INCLUDEPATH += $(QPEDIR)/include
11 LIBS+= -lqpe
12 DBFILE= chess.db
13 LANGUAGE= C++
14 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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19** $Id$
20**
21**********************************************************************/
22#include <qpe/qpeapplication.h>
23#include <qpe/qpetoolbar.h>
24#include <qmainwindow.h>
25#include <qcanvas.h>
26#include "chess.h"
27
28
29class CanvasMainWindow : public QMainWindow {
30public:
31 CanvasMainWindow(QWidget* parent=0, const char* name=0, WFlags f=0)
32 : QMainWindow(parent,name,f), canvas(232, 258) {
33 view = new BoardView(&canvas, this, 0);
34 setToolBarsMovable( FALSE );
35 QPEToolBar* toolbar = new QPEToolBar(this);
36 toolbar->setHorizontalStretchable( TRUE );
37 }
38
39private:
40 QCanvas canvas;
41 BoardView *view;
42};
43
44
45int main( int argc, char **argv ) {
46 QPEApplication a(argc,argv);
47 CanvasMainWindow *mw = new CanvasMainWindow();
48 a.showMainWidget( mw );
49 return a.exec();
50}
51
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 @@
1<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
2<class>MainWindow</class>
3<widget class="QMainWindow">
4 <property name="name">
5 <cstring>MainWindow</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>256</width>
12 <height>338</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Chess</string>
17 </property>
18 <widget class="QLabel">
19 <property name="name">
20 <cstring>TextLabel1</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>10</x>
25 <y>236</y>
26 <width>221</width>
27 <height>31</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>TextLabel1</string>
32 </property>
33 </widget>
34 <widget class="BoardView">
35 <property name="name">
36 <cstring>ChessBoard</cstring>
37 </property>
38 <property name="geometry">
39 <rect>
40 <x>10</x>
41 <y>10</y>
42 <width>224</width>
43 <height>224</height>
44 </rect>
45 </property>
46 <property name="sizePolicy">
47 <sizepolicy>
48 <hsizetype>1</hsizetype>
49 <vsizetype>1</vsizetype>
50 <horstretch>0</horstretch>
51 <verstretch>0</verstretch>
52 </sizepolicy>
53 </property>
54 <property name="minimumSize">
55 <size>
56 <width>224</width>
57 <height>224</height>
58 </size>
59 </property>
60 </widget>
61</widget>
62<menubar>
63 <property name="name">
64 <cstring>menubar</cstring>
65 </property>
66 <item text="Game" name="PopupMenu_2">
67 <action name="newGame"/>
68 <action name="annotateGame"/>
69 </item>
70 <item text="Position" name="PopupMenu_3">
71 <action name="swapSides"/>
72 <action name="undo"/>
73 </item>
74</menubar>
75<toolbars>
76</toolbars>
77<customwidgets>
78 <customwidget>
79 <class>BoardView</class>
80 <header location="global">/home/luke/depot/qpe/chess/chess.h</header>
81 <sizehint>
82 <width>-1</width>
83 <height>-1</height>
84 </sizehint>
85 <container>0</container>
86 <sizepolicy>
87 <hordata>5</hordata>
88 <verdata>5</verdata>
89 <horstretch>0</horstretch>
90 <verstretch>0</verstretch>
91 </sizepolicy>
92 <pixmap>image0</pixmap>
93 <signal>showMessage(const QString&amp;)</signal>
94 <slot access="public" specifier="">newGame()</slot>
95 <slot access="public" specifier="">swapSides()</slot>
96 <slot access="public" specifier="">setTheme(QString)</slot>
97 <slot access="public" specifier="">undo()</slot>
98 <slot access="public" specifier="">annotateGame()</slot>
99 </customwidget>
100</customwidgets>
101<actions>
102 <actiongroup>
103 <property name="name">
104 <cstring>gameActions</cstring>
105 </property>
106 <property name="text">
107 <string>ActionGroup</string>
108 </property>
109 <property name="usesDropDown">
110 <bool>false</bool>
111 </property>
112 <action>
113 <property name="name">
114 <cstring>newGame</cstring>
115 </property>
116 <property name="iconSet">
117 <iconset>new.png</iconset>
118 </property>
119 <property name="text">
120 <string>New Game</string>
121 </property>
122 <property name="menuText">
123 <string>New Game</string>
124 </property>
125 <property name="toolTip">
126 <string>New Game</string>
127 </property>
128 </action>
129 <action>
130 <property name="name">
131 <cstring>swapSides</cstring>
132 </property>
133 <property name="iconSet">
134 <iconset>repeat.png</iconset>
135 </property>
136 <property name="text">
137 <string>Swap sides</string>
138 </property>
139 <property name="toolTip">
140 <string>Swap sides</string>
141 </property>
142 </action>
143 <action>
144 <property name="name">
145 <cstring>annotateGame</cstring>
146 </property>
147 <property name="iconSet">
148 <iconset>txt.png</iconset>
149 </property>
150 <property name="text">
151 <string>Annotate game</string>
152 </property>
153 <property name="toolTip">
154 <string>Annotate game</string>
155 </property>
156 </action>
157 <action>
158 <property name="name">
159 <cstring>undo</cstring>
160 </property>
161 <property name="iconSet">
162 <iconset>back.png</iconset>
163 </property>
164 <property name="text">
165 <string>Undo move</string>
166 </property>
167 <property name="toolTip">
168 <string>Undo move</string>
169 </property>
170 </action>
171 <action>
172 <property name="name">
173 <cstring>saveGame</cstring>
174 </property>
175 <property name="text">
176 <string>Action</string>
177 </property>
178 </action>
179 </actiongroup>
180</actions>
181<images>
182 <image name="image0">
183 <data format="XPM.GZ" length="3456">789ce5d35d5313491406e07b7e458abea3b68e99cfccd4d65ee0079ac8a720a2d65ef474cf2424229004152dffbba7cf795941182a59bcd8aa6548524fbafb9d9ed3278fd63a47bb5b9db5472bb3b99d1fbb8e1bd96967cd5f9c9c5cbefffbaf6f2bab49dce1ff5eaf13affeb1b24aa6e33aa62b7f620fa7b01517ec423c850bb571b0c3f8bbe0a8db7591ae1fa9c3257e0aa7b0ac8f0ab6aeefc305bc073b783d38ee462ed6f5953a5ce20d38859f894b7629de820bb519c20ee3af829328764924be50275d7806a76a732c2ed9ba7e08176a33811d2cf548a3c4a59a97a9d3aedad4708af153b1655bf14bb880bfc00e3e0fcee2ac9be9f926629b65998eefc21e3e0acee3cce73affb33acfe037ff58e737629b97f026ece128b897e4be9788bfaa7b119cc319fc445cb12bf1215caa8d813d2cfd59243d5fe8faaeb82ab242d7d770097f803d2ce751a66554a6e28f70a636d24fa5633b191fc325fc1cf6f049b04d6d6435ef139cc16fc5ce5aabf3b7e11ade09ae525b573a7f5f5dc5f00bb1aff2ca8b07b0559b315c63fc20d86555ed32f15ced62f812ce61e95fe7d99a67610b3770ada65eb0e776f1bafe4c5cb36bf16bd8c245709dd7719d8b5371cddfc8b821d8aa290e6e78b4d1f9a5ba89e1c7e2a6b14d13bc37879b2bdf7f91b9fffadf65d8df90519123ffc08c9a1a1ad2a86d3ff767d0318d69421fe8843ed229a72c9d4167742ef79ed28ce69c7471f713b567d027beef675ea733bfd0257da5f5bb52da32e8313de18ca7f48c67add30657f539bde07df597c818d04bdae41a84593557654a5bb44d3bb44b7bbfeea53563c2ab467c1a61569f77123e5fd13e1d704a7533a535e3351dd21b3afa65dfeb9cf09677f86ec19a7679e64cea71f3daa788ebb45846cccf93dcaae1942bbb793be38e339ff2b34f28e5f7ab6f4e29e33a8c68f3f6dd5a320cdf29a7deb58c824aeeb31d434b64f48de1351b5736b6fd17d192e1a9321577d5cfe73e5c32c31ac79db16dfccf3e30f55219533e8b53634c73bd3bcc90e285332cf7f21177f51977d9f046775d2e9e6146fc8bbdabcab816c89872270f1e98e1f909c6b4c5cf7f71f5e2f7637e9fe9e742f5e8d3399feb3e0dcc9877744083f613693d174b23befbcc4ccc84b2f0fa1719d7d37c783d28a3b58affd18cef7faefc007d894af5</data>
184 </image>
185</images>
186<connections>
187 <connection>
188 <sender>newGame</sender>
189 <signal>activated()</signal>
190 <receiver>ChessBoard</receiver>
191 <slot>newGame()</slot>
192 </connection>
193 <connection>
194 <sender>swapSides</sender>
195 <signal>activated()</signal>
196 <receiver>ChessBoard</receiver>
197 <slot>swapSides()</slot>
198 </connection>
199 <connection>
200 <sender>annotateGame</sender>
201 <signal>activated()</signal>
202 <receiver>ChessBoard</receiver>
203 <slot>annotateGame()</slot>
204 </connection>
205 <connection>
206 <sender>undo</sender>
207 <signal>activated()</signal>
208 <receiver>ChessBoard</receiver>
209 <slot>undo()</slot>
210 </connection>
211 <connection>
212 <sender>ChessBoard</sender>
213 <signal>showMessage(const QString&amp;)</signal>
214 <receiver>TextLabel1</receiver>
215 <slot>setText(const QString&amp;)</slot>
216 </connection>
217</connections>
218<pixmapinproject/>
219<layoutdefaults spacing="6" margin="11"/>
220</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 @@
1Files: bin/chess apps/Games/chess.desktop
2Priority: optional
3Section: qpe/games
4Maintainer: Luke Graham <luke@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Crafty GUI
9 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