214
214
map[f] = GameBoard::NONE;
217
t = checkKing(gt, map, mirror, vl, FALSE);
217
t = checkKing(gt, map, mirror, vl, false);
297
297
map1[p] = GameBoard::DUMMY;
299
if (checkKing(gt, map1, mirror, vl, TRUE) != 0) {
299
if (checkKing(gt, map1, mirror, vl, true) != 0) {
301
301
moveListKing(vl, mytype, map, xk, yk, !mirror);
302
302
memmove(map1, map, sizeof(map1));
588
588
x1 = x - 1; x2 = x + 1;
589
589
y1 = y - 1; y2 = y + 1;
592
592
if (validPoint(gt, map, x1, y2, mirror))
593
593
res = (hasEnemyFigure(gt, map, x1, y2, mirror) == 2);
669
669
sock = new Q3Socket(this);
670
670
drw = new Drawer(map, >, this);
671
drw->setEnabled(FALSE);
671
drw->setEnabled(false);
672
672
drw->setFocusPolicy(Qt::NoFocus);
673
673
box = new Q3GroupBox(tr("Game chat"), this);
674
674
lst = new Q3ListBox(box);
676
676
lst->setVScrollBarMode(Q3ScrollView::AlwaysOff);
677
677
lst->setSelectionMode(Q3ListBox::NoSelection);
678
678
edt = new QLineEdit(box);
679
edt->setEnabled(FALSE);
679
edt->setEnabled(false);
680
680
setFocusProxy(edt);
681
681
hist = new Q3GroupBox(tr("History"), this);
682
682
hist->setAlignment(Qt::AlignHCenter);
744
744
connect(protocol,SIGNAL(sendData(const QString&)), this, SIGNAL(sendData(const QString&)));
745
745
sock = new Q3Socket(this);
746
746
drw = new Drawer(map, >, this);
747
drw->setEnabled(FALSE);
747
drw->setEnabled(false);
748
748
drw->setFocusPolicy(Qt::NoFocus);
749
749
box = new Q3GroupBox(tr("Game chat"), this);
750
750
lst = new Q3ListBox(box);
1020
1020
hst = sock->peerAddress().toString() + ':' +
1021
1021
QString::number(sock->peerPort());
1024
1024
protocol->acceptGame(sock);
1025
1025
setCaption(s + hst);
1026
1026
my_stat += hst;
1027
1027
emit showStatus(my_stat);
1028
1028
} else if (gt == WHITE) {
1029
drw->setEnabled(TRUE);
1029
drw->setEnabled(true);
1030
1030
setCursor(QCursor(Qt::ArrowCursor));
1032
1032
} else if (s == "move") {
1033
1033
if (!drw->isEnabled()) {
1034
drw->setEnabled(TRUE);
1034
drw->setEnabled(true);
1035
1035
s = lst[1].lower();
1036
updateHistory(s, TRUE);
1036
updateHistory(s, true);
1037
1037
drw->makeMove(s);
1038
1038
setCursor(QCursor(Qt::ArrowCursor));
1039
1039
my_stat = tr("Your move...");
1060
1060
protocol->sendMove(sock, str);
1061
1061
emit sendData(str);
1062
drw->setEnabled(FALSE);
1062
drw->setEnabled(false);
1063
1063
setCursor(QCursor(Qt::WaitCursor));
1064
updateHistory(str, FALSE);
1064
updateHistory(str, false);
1065
1065
sock_tout = SOCK_WAIT;
1066
1066
my_stat = tr("Waiting a move...");
1067
1067
emit showStatus(my_stat);
1266
1266
save = (QMessageBox::question(this, go,
1267
1267
tr("You scored the game") + s, yes, no) == 0);
1268
1268
} else if (type == 2) {
1269
updateHistory(GAMEOVER_TXT, FALSE);
1269
updateHistory(GAMEOVER_TXT, false);
1270
1270
protocol->sendGameover(sock, "MATE");
1271
1271
save = (QMessageBox::question(this, go,
1272
1272
tr("You have a mate.\nYou lost the game.") + s,
1461
1461
if (hasTakenFigure()) {
1462
1462
if ((tfx == x) && (tfy == y)) {
1463
1463
tfx = tfy = -1;
1466
makeMove(*gt, tfx, tfy, x, y, FALSE, FALSE);
1466
makeMove(*gt, tfx, tfy, x, y, false, false);
1467
1467
} else if (canTake(x, y)) {
1468
1468
takeFigure(x, y);
1469
1469
emit touchFigure(x, y);
1476
1476
Drawer::canTake(int x, int y)
1479
return (Figure::hasMyFigure(*gt, map, x, y, FALSE));
1479
return (Figure::hasMyFigure(*gt, map, x, y, false));
1544
1544
ft = GameBoard::NONE; n = -1;
1545
1545
Figure::str2map(coo, &x, &y);
1546
1546
if (*gt == GameBoard::WHITE) {
1547
n = Figure::map2map(GameBoard::BLACK, x, y, TRUE);
1547
n = Figure::map2map(GameBoard::BLACK, x, y, true);
1550
1550
ft = GameBoard::BLACK_BISHOP;
1562
1562
ft = GameBoard::NONE;
1564
1564
} else if (*gt == GameBoard::BLACK) {
1565
n = Figure::map2map(GameBoard::WHITE, x, y, TRUE);
1565
n = Figure::map2map(GameBoard::WHITE, x, y, true);
1568
1568
ft = GameBoard::WHITE_BISHOP;
1602
1602
et = GameBoard::NOGAME;
1603
1603
if (txt == LONG_XCHG) {
1604
1604
if (et == GameBoard::BLACK)
1605
makeMove(et, 1, 8, 4, 8, TRUE, TRUE);
1605
makeMove(et, 1, 8, 4, 8, true, true);
1606
1606
else if (et == GameBoard::WHITE)
1607
makeMove(et, 1, 1, 4, 1, TRUE, TRUE);
1607
makeMove(et, 1, 1, 4, 1, true, true);
1608
1608
} else if (txt == SHORT_XCHG) {
1609
1609
if (et == GameBoard::BLACK)
1610
makeMove(et, 8, 8, 6, 8, TRUE, TRUE);
1610
makeMove(et, 8, 8, 6, 8, true, true);
1611
1611
else if (et == GameBoard::WHITE)
1612
makeMove(et, 8, 1, 6, 1, TRUE, TRUE);
1612
makeMove(et, 8, 1, 6, 1, true, true);
1614
1614
Figure::str2map(txt.left(2), &fx, &fy);
1615
1615
Figure::str2map(txt.right(2), &tx, &ty);
1616
makeMove(et, fx, fy, tx, ty, TRUE, FALSE);
1616
makeMove(et, fx, fy, tx, ty, true, false);
1637
1637
res = Figure::validMove(gt, map, fx, fy, tx, ty, mirror);
1641
1641
if (gt == GameBoard::WHITE)
1642
1642
et = GameBoard::BLACK;
1643
1643
else if (gt == GameBoard::BLACK)
1644
1644
et = GameBoard::WHITE;
1645
if (Figure::checkKing(et, map, mirror, vl, TRUE) !=
1645
if (Figure::checkKing(et, map, mirror, vl, true) !=
1647
1647
map[nf] = map[nt];
1653
1653
"is in check") + '.');
1657
1657
if (!km && (!lcm || !rcm) && !kk)
1658
1658
x = xchg(fo, map[nt], fx, fy, tx, ty);
1662
1662
emit moved(Figure::map2str(fx, fy) +
1663
1663
Figure::map2str(tx, ty));
1672
1672
tfx = tfy = -1;
1673
1673
} else if (xc) {
1674
1674
if (gt == GameBoard::BLACK)
1675
checkBlackCastle(fx, fy, tx, ty, TRUE);
1675
checkBlackCastle(fx, fy, tx, ty, true);
1676
1676
else if (gt == GameBoard::WHITE)
1677
checkWhiteCastle(fx, fy, tx, ty, TRUE);
1677
checkWhiteCastle(fx, fy, tx, ty, true);
1679
1679
if (mirror && (res & 0x10)) {
1681
1681
} else if (res & 0x20) {
1683
1683
emit gameover(2);
1685
1685
} else if (res & 0x40) {
1687
1687
emit gameover(3);
1697
1697
Drawer::xchg(GameBoard::FigureType o, GameBoard::FigureType n,
1698
1698
int fx, int fy, int tx, int ty)
1702
1702
if (*gt == GameBoard::WHITE) {
1703
1703
km = ((o == n) && (o == GameBoard::WHITE_KING));
1704
1704
if (!km && ((o == n) && (o == GameBoard::WHITE_CASTLE)))
1705
ret = checkWhiteCastle(fx, fy, tx, ty, FALSE);
1705
ret = checkWhiteCastle(fx, fy, tx, ty, false);
1706
1706
} else if (*gt == GameBoard::BLACK) {
1707
1707
km = ((o == n) && (o == GameBoard::BLACK_KING));
1708
1708
if (!km && ((o == n) && (o == GameBoard::BLACK_CASTLE)))
1709
ret = checkBlackCastle(fx, fy, tx, ty, FALSE);
1709
ret = checkBlackCastle(fx, fy, tx, ty, false);
1717
1717
Drawer::checkWhiteCastle(int fx, int fy, int tx, int ty, bool mirror)
1723
1723
if ((fx == 1) && (fy == 1)) {
1724
1724
if ((tx == 4) && (ty == 1))
1726
n1 = Figure::map2map(*gt, 5, 1, FALSE);
1727
n2 = Figure::map2map(*gt, 3, 1, FALSE);
1726
n1 = Figure::map2map(*gt, 5, 1, false);
1727
n2 = Figure::map2map(*gt, 3, 1, false);
1728
1728
} else if (!lcm) {
1729
1729
if (makeXchg()) {
1730
n1 = Figure::map2map(*gt, 5, 1, FALSE);
1731
n2 = Figure::map2map(*gt, 3, 1, FALSE);
1730
n1 = Figure::map2map(*gt, 5, 1, false);
1731
n2 = Figure::map2map(*gt, 3, 1, false);
1732
1732
emit moved(LONG_XCHG);
1738
1738
} else if ((fx == 8) && (fy == 1)) {
1739
1739
if ((tx == 6) && (ty == 1))
1741
n1 = Figure::map2map(*gt, 5, 1, FALSE);
1742
n2 = Figure::map2map(*gt, 7, 1, FALSE);
1741
n1 = Figure::map2map(*gt, 5, 1, false);
1742
n2 = Figure::map2map(*gt, 7, 1, false);
1743
1743
} else if (!rcm) {
1744
1744
if (makeXchg()) {
1745
n1 = Figure::map2map(*gt, 5, 1, FALSE);
1746
n2 = Figure::map2map(*gt, 7, 1, FALSE);
1745
n1 = Figure::map2map(*gt, 5, 1, false);
1746
n2 = Figure::map2map(*gt, 7, 1, false);
1747
1747
emit moved(SHORT_XCHG);
1754
1754
if (n1 != n2) {
1764
1764
Drawer::checkBlackCastle(int fx, int fy, int tx, int ty, bool mirror)
1770
1770
if ((fx == 1) && (fy == 8)) {
1771
1771
if ((tx == 4) && (ty == 8)) {
1773
n1 = Figure::map2map(*gt, 5, 8, FALSE);
1774
n2 = Figure::map2map(*gt, 3, 8, FALSE);
1773
n1 = Figure::map2map(*gt, 5, 8, false);
1774
n2 = Figure::map2map(*gt, 3, 8, false);
1775
1775
} else if (!rcm) {
1776
1776
if (makeXchg()) {
1777
n1 = Figure::map2map(*gt, 5, 8, FALSE);
1778
n2 = Figure::map2map(*gt, 3, 8, FALSE);
1777
n1 = Figure::map2map(*gt, 5, 8, false);
1778
n2 = Figure::map2map(*gt, 3, 8, false);
1779
1779
emit moved(LONG_XCHG);
1785
1785
} else if ((fx == 8) && (fy == 8)) {
1786
1786
if ((tx == 6) && (ty == 8))
1788
n1 = Figure::map2map(*gt, 5, 8, FALSE);
1789
n2 = Figure::map2map(*gt, 7, 8, FALSE);
1788
n1 = Figure::map2map(*gt, 5, 8, false);
1789
n2 = Figure::map2map(*gt, 7, 8, false);
1790
1790
} else if (!lcm) {
1791
1791
if (makeXchg()) {
1792
n1 = Figure::map2map(*gt, 5, 8, FALSE);
1793
n2 = Figure::map2map(*gt, 7, 8, FALSE);
1792
n1 = Figure::map2map(*gt, 5, 8, false);
1793
n2 = Figure::map2map(*gt, 7, 8, false);
1794
1794
emit moved(SHORT_XCHG);
1800
1800
if (n1 != n2) {