这是一段用C++编程语言开发的中国象棋程序源代码。该代码实现了中国象棋的基本规则和玩法,并可能包含人机对战、残局研究等功能。
```cpp
#include
#include
class Chess_ZN {
public:
void sendBroadcastDatagram(int flag) { peer->sendBroadcastDatagram(flag); }
void returnPressed() {
QString ss = line[1]->text();
if (ss.trimmed().compare() != 0) {
QByteArray byte;
QDataStream in(&byte, QIODevice::ReadWrite);
in << 15;
in << QHostInfo::localHostName();
in << ss;
if (radio[0]->isChecked()) {
client->write(byte);
} else if (radio[1]->isChecked()) {
peer->returnUdp()->writeDatagram(byte.data(), byte.size(), QHostAddress(line[0]->text()), 10001);
}
edit[0]->append(QHostInfo::localHostName() + : \n + ss);
line[1]->clear();
}
}
private:
void stopWatch() {
if (isTimer) {
if (scene->r_or_b == 0) {
if (scene->diaitemR[0]->flags() == QGraphicsItem::ItemIsMovable) {
label[5]->setText(utf(红方剩余时间为: ));
} else {
label[5]->setText(utf(黑方剩余时间为: ));
}
} else {
if (scene->diaitemB[0]->flags() == QGraphicsItem::ItemIsMovable) {
label[5]->setText(utf(黑方剩余时间为: ));
} else {
label[5]->setText(utf(红方剩余时间为: ));
}
}
lcd->display(--second);
if (second == 0) {
scene->whoturn(0); // 按规定时间到即弃权认输
QByteArray byte;
QDataStream in(&byte, QIODevice::ReadWrite);
in << 17;
client->write(byte);
initAgain();
QMessageBox::information(this, utf(通知...), utf(不好意思,按规定您已经弃权认输了!!!));
}
}
}
void doWithInfo(int mapValue, QPoint point) {
scene->index++;
int x = 8 - point.x();
int y = 9 - point.y();
int xl = DiagramScene::xl;
int yl = DiagramScene::yl;
int xw = DiagramScene::xw;
int yh = DiagramScene::yh;
if (scene->r_or_b == 0) {
if (scene->map[y][x] != 0) {
QUndoCommand *deleteCommand = new DeleteCommand(scene->index, scene->map, scene->diaitemR[(scene->map[y][x]) - 20 - 1]);
undoStack->push(deleteCommand);
}
DiagramItem *diagramItem = scene->diaitemB[mapValue - 20 - 1];
int oldx = diagramItem->localX();
int oldy = diagramItem->localY();
scene->diaitemB[mapValue - 20 - 1]->setPos(xl + xw * x, yl + yh * y);
undoStack->push(new MoveCommand(scene->index, scene->map, diagramItem, QPointF(xl + xw * oldx, yl + yh * oldy)));
} else {
if (scene->map[y][x] != 0) {
QUndoCommand *deleteCommand = new DeleteCommand(scene->index, scene->map, scene->diaitemB[(scene->map[y][x]) - 20 - 1]);
undoStack->push(deleteCommand);
}
DiagramItem *diagramItem = scene->diaitemR[mapValue - 20 - 1];
int oldx = diagramItem->localX();
int oldy = diagramItem->localY();
scene->diaitemR[mapValue - 20 - 1]->setPos(xl + xw * x, yl + yh * y);
undoStack->push(new MoveCommand(scene->index, scene->map, diagramItem, QPointF(xl + xw * oldx, yl + yh * oldy)));
}
}
QString utf(QString s) {
QByteArray ba = s.toLatin1();
const char* schar = ba.data();
return QString::fromLocal8Bit(schar);
}
void initAgain() {
for (int i = 0; i < 16; ++i) {
scene->removeItem(scene->diaitemB[i]);
scene->removeItem(scene->diaitemR[i]);
}
start = false;
second = 120;
isTimer =