基于Ubuntu下的QT制作黑白棋游戏

linux下的中国象棋,很不错的,gtk+ 一个在ubunt下开发的中国象棋,使用gtk+,希望对大家有用 立即下载


本文以begin为第一跳转界面

第二跳转界面(heibai)为People to People(人人对战)

第三跳转界面(heibai2)为People to Computer(人机对战)

三张效果图如下:



各个页面源代码如下:


头文件:


begin.h

#ifndef BEGIN_H
#define BEGIN_H
#include <heibai.h>
#include <heibai2.h>
#include <QMainWindow>
#include <QPaintEvent>
#include <QWidget>
#include <QMouseEvent>
#include <phonon/MediaObject>




namespace Ui {
class begin;
}
//enum GridState{Black,White,Empty};
class begin : public QMainWindow
{
    Q_OBJECT


public:
        explicit begin(QWidget *parent = 0);
        ~begin();
        void paintEvent(QPaintEvent *e);
        enum GridState{Black,White,Empty};








private slots:
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void put();
    void put2();
    void do_timer();


private:
        Ui::begin *ui;
        heibai b;
        heibai2 b2;


        int sec;


};


#endif // BEGIN_H



heibai.h


#ifndef HEIBAI_H
#define HEIBAI_H


#include <QWidget>
#include <QPaintEvent>
#include <QMainWindow>




#include <QMouseEvent>
namespace Ui {
class heibai;
}




class heibai : public QWidget
{
    Q_OBJECT


public:
    explicit heibai(QWidget *parent = 0);
    ~heibai();
       void paintEvent(QPaintEvent *e);
       enum GridState{Black,White,Empty};


       void mousePressEvent(QMouseEvent *e);
       void mouseMoveEvent(QMouseEvent *e);
       int judgeRule(int x, int y, int gridNum, void *chess, GridState currentRole);
       int judgeRule2(int x, int y, int gridNum, void *chess, GridState currentRole);


private:
    Ui::heibai *ui;
    int sec;


    QTimer *timer;


        int chessNumber[8][8];
        GridState currentRole;
        int xPoint,yPoint;
        int BlackNumber;
        int WhiteNumber;


signals:
    void give();


private slots:
    void do_timer();
    void do_timer2();
    void on_pushButton_clicked();


    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();
    void on_pushButton_5_clicked();


    void on_pushButton_7_clicked();
    void on_pushButton_8_clicked();


};





#endif // HEIBAI_H




heibai2.h



#ifndef HEIBAI2_H
#define HEIBAI2_H




#include <QWidget>
#include <QPaintEvent>
#include <QMainWindow>




#include <QMouseEvent>


namespace Ui {
class heibai2;
}


class heibai2 : public QWidget
{
    Q_OBJECT


public:
    explicit heibai2(QWidget *parent = 0);
    void paintEvent(QPaintEvent *e);
       enum GridState{Water,Fire,Air};
       void mousePressEvent(QMouseEvent *e);
       void mouseMoveEvent(QMouseEvent *e);
       int judgeRule(int x, int y, int gridNum, void *chess, GridState currentRole);
       int judgeRule2(int x, int y, int gridNum, void *chess, GridState currentRole);
    ~heibai2();


signals:
    void give2();


private slots:


    void do_timer();
    void do_timer2();
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();


    void on_pushButton_5_clicked();


    void on_pushButton_6_clicked();


    void on_pushButton_7_clicked();


private:
    Ui::heibai2 *ui;
    int sec;


        QTimer *timer;
        int chessNumber[8][8];
        GridState currentRole;
        int xPoint,yPoint;
        int BlackNumber;
        int WhiteNumber;
};


#endif // HEIBAI2_H



begin.cpp


#include "begin.h"
#include "ui_begin.h"
#include "QPainter"
#include "QTimer"


begin::begin(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::begin)
{
    ui->setupUi(this);


    connect(&this->b,SIGNAL(give()),this,SLOT(put()));
    connect(&this->b2,SIGNAL(give2()),this,SLOT(put2()));


}


begin::~begin()
{
    delete ui;


}




void begin::put()
{
    this->show();
}




void begin::put2()
{
    this->show();
}






void begin::paintEvent(QPaintEvent *e)                 //background picture
{
    QPainter p(this);
    p.drawPixmap(0,0,1366,768,QPixmap(":/new/prefix1/images /11.png"));


}




void begin::on_pushButton_clicked()
{
    b.setFixedSize(1366,768);
    b.show();
    this->close();
}


void begin::on_pushButton_2_clicked()
{
    b2.setFixedSize(1366,768);
    b2.show();
    this->close();
}







heibai.cpp



#include "heibai.h"
#include "ui_heibai.h"
#include <QTimer>
#include <QPainter>
#include <QPen>
#include "QMovie"
#include "QMessageBox"
heibai::heibai(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::heibai)
{
    ui->setupUi(this);
    sec=11;
     this->setMouseTracking(true);
    QTimer *timer;
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(do_timer2()));
    timer->start(1000);
    QMovie *movie=new QMovie(":/new/prefix1/images /3.gif");
    ui->label->setPixmap(QPixmap(":/new/prefix1/images /black.png"));
    ui->label_2->setPixmap(QPixmap(":/new/prefix1/images /white.png"));
    ui->label_3->setMovie(movie);


    movie->start();
    movie->setSpeed(100);


    BlackNumber=2;
     WhiteNumber=2;
     ui->lcdNumber->display(BlackNumber);
     ui->lcdNumber_2->display(WhiteNumber);


     int i,j;
     currentRole=Empty;


     for(i=0;i<8;i++)
        {
             for(j=0;j<8;j++)
             {
                 chessNumber[i][j]=Empty;
             }
         }
     chessNumber[3][3]=Black;
     chessNumber[4][4]=Black;
     chessNumber[3][4]=White;
     chessNumber[4][3]=White;
}




void heibai::mouseMoveEvent(QMouseEvent *e)
{
    xPoint=e->x();
    yPoint=e->y();
    this->update();
}




heibai::~heibai()
{
    delete ui;


}










void heibai::do_timer()
{
    if(sec>0)
        {
        sec--;
        ui->lcdNumber_3->display(sec);
        }
     else
        {
             sec=11;
        }


}




void heibai::on_pushButton_clicked()
{
    emit give();
    this->close();
}














void heibai::paintEvent(QPaintEvent *e)
{
     QPainter painer(this);
     painer.drawPixmap(0,0,1366,768,QPixmap(":/new/prefix1/images /22.png"));
     QPen pen;
     pen.setBrush(QBrush(Qt::Dense1Pattern));
     pen.setColor(QColor(Qt::blue));
     painer.setPen(pen);
     painer.drawPixmap(110,110,480,480,QPixmap(":/new/prefix1/images /pvm.png"));
     int i,j;
     for(i=0;i<=8;i++)
         {
             painer.drawLine(110,110+(60*i),590,110+(60*i));
             painer.drawLine(110+(60*i),110,110+(60*i),590);
         }
     for(i=0;i<8;i++)
         {
             for(j=0;j<8;j++)
             {
                 if(chessNumber[i][j]==Black)
                 {


                     painer.drawPixmap(110+60*i,110+60*j,60,60,QPixmap(":/new/prefix1/images /black.png"));
                 }
                 else if(chessNumber[i][j]==White)
                 {
                     painer.drawPixmap(110+60*i,110+60*j,60,60,QPixmap(":/new/prefix1/images /white.png"));
                 }
             }
             if(currentRole==Black)
             {
                 painer.drawPixmap(xPoint-30,yPoint-30,60,60,QPixmap(":/new/prefix1/images /black.png"));


             }
             else
             {
                 painer.drawPixmap(xPoint-30,yPoint-30,60,60,QPixmap(":/new/prefix1/images /white.png"));
             }
         }


}












void heibai::mousePressEvent(QMouseEvent *e)
{


    int x=e->x();
    x=(x-110)/60;
    int y=e->y();
    y=(y-110)/60;
    int a;
    if(currentRole==Black)
    {
    a=judgeRule(x,y,8,chessNumber,currentRole);
        if(a>0)
        {
                if(currentRole==Black)
                {
                    sec=11;
                    BlackNumber=BlackNumber+a+1;
                    WhiteNumber=WhiteNumber-a;
                    ui->lcdNumber->display(BlackNumber);
                    ui->lcdNumber_2->display(WhiteNumber);
                    currentRole=White;
                }
                else
                {
                    sec=11;
                    BlackNumber=BlackNumber-a;
                    WhiteNumber=WhiteNumber+a+1;
                    ui->lcdNumber->display(BlackNumber);
                    ui->lcdNumber_2->display(WhiteNumber);
                    currentRole=Black;
                }
        }
    }
    if(currentRole==White)
        {
            a=judgeRule(x,y,8,chessNumber,currentRole);
            if(a>0)
            {
                if(currentRole==White)
                {
                    sec=11;
                    BlackNumber=BlackNumber-a;
                    WhiteNumber=WhiteNumber+a+1;
                    ui->lcdNumber->display(BlackNumber);
                    ui->lcdNumber_2->display(WhiteNumber);
                    currentRole=Black;
                }
                else
                {
                        sec=11;
                        BlackNumber=BlackNumber+a+1;
                        WhiteNumber=WhiteNumber-a;
                        ui->lcdNumber->display(BlackNumber);
                        ui->lcdNumber_2->display(WhiteNumber);
                        currentRole=White;
                }
            }
        }
     ui->lineEdit->clear();
     int add=0;
     int i,j;
     for(i=0;i<8;i++)
         for(j=0;j<8;j++)
             if(chessNumber[i][j]!=Empty)
                 add++;
     if(add==64)
     {


         ui->pushButton->setEnabled(true);
         if(BlackNumber>WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The black is win"));
         else if(BlackNumber==WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("Draw"));
         else
             QMessageBox::information(NULL,QString("Tip"),QString("The white is win"));


         sec=0;
     }
     int flag=0;
     for(int i=0;i<8;i++)
         for(int j=0;j<8;j++)
             if(judgeRule2(i,j,8,chessNumber,currentRole))
                 flag=1;
     if(add!=64 && flag==0)
     {
         ui->pushButton->setEnabled(true);
         if(BlackNumber>WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The black is win"));
         else if(BlackNumber==WhiteNumber && BlackNumber != 2 && WhiteNumber != 2)
             QMessageBox::information(NULL,QString("Tip"),QString("Draw"));
         else if(WhiteNumber>BlackNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The white is win"));


         sec=0;
     }
    this->update();
}




int heibai::judgeRule(int x, int y, int gridNum, void *chess, GridState currentRole)
{
    int dir[8][2]={{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};


    if( x < 0 || x>= gridNum || y < 0 || y >= gridNum) // 判断坐标是否合法
        return 0;
    int temp_x = x, temp_y = y;
    int i = 0, eatNum = 0;
    typedef int (*p)[gridNum]; //自定义类型
    p chessBoard = p(chess); //类型转换 并赋值给新变量 chessBoard
    //如果此方格内已有棋子,返回;
    if(chessBoard[temp_x][temp_y]!=Empty)
        return 0;
    for(i = 0 ; i <8; i++) //循环判断8个方向
    {
        temp_x += dir[i][0]; temp_y += dir[i][1]; //准备判断相邻棋子
        //如果没有出界,且相邻棋子是对方棋子,才有吃子的可能.
        if((temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
                && (chessBoard[temp_x][temp_y] != currentRole)
                && chessBoard[temp_x][temp_y]!=Empty)
        {
            temp_x += dir[i][0]; temp_y += dir[i][1]; //继续判断下一个
            //同样判断是否出界
            while(temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
            {
                //遇到空位跳出
                if(chessBoard[temp_x][temp_y] == Empty)
                        break;
                //找到了自己的棋子,可以吃子
                if(chessBoard[temp_x][temp_y] == currentRole)
                {
                    chessBoard[x][y] = currentRole; //改变(x,y)坐标内的信息
                    temp_x -= dir[i][0]; temp_y -= dir[i][1];
                    while((temp_x != x )||(temp_y != y)) //吃子的过程
                    {
                        chessBoard[temp_x][temp_y] = currentRole;
                        temp_x -= dir[i][0]; temp_y -= dir[i][1];
                        eatNum ++;
                    }
                    break;
                }
                //如果仍然是对方棋子,继续沿此方向查找
                temp_x += dir[i][0]; temp_y += dir[i][1];
            }
        }
        temp_x = x; temp_y = y; //一个方向判断结束,准备下一个方向
    }
    return eatNum;
}




void heibai::do_timer2()
{
        if(sec>0)
        {
            sec--;
            ui->lcdNumber_3->display(sec);
        }
        else
       {


        ui->lineEdit->setText("time over");


        if(currentRole==White)
        {
              currentRole=Black;
              sec=11;


        }
        else if(currentRole==Black)
         {
            sec=11;
            currentRole=White;


         }
    }
    this->update();


}










void heibai::on_pushButton_3_clicked()
{
        ui->lcdNumber->display(0);
        timer->stop();
        sec=11;
        BlackNumber=2;
        WhiteNumber=2;
        ui->lcdNumber->display(BlackNumber);
        ui->lcdNumber_3->display(WhiteNumber);
        int i,j;
        currentRole=Empty;
        for(i=0;i<8;i++)
           {


            for(j=0;j<8;j++)
            {
                chessNumber[i][j]=Empty;
            }
        }
        chessNumber[3][3]=Black;
        chessNumber[4][4]=Black;
        chessNumber[3][4]=White;
        chessNumber[4][3]=White;
}








void heibai::on_pushButton_4_clicked()
{
        currentRole=Black;
        BlackNumber=2;
        WhiteNumber=2;
}
int heibai::judgeRule2(int x, int y, int gridNum, void *chess, GridState currentRole)
{
    int dir[8][2]={{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};


    if( x < 0 || x>= gridNum || y < 0 || y >= gridNum) // 判断坐标是否合法
        return 0;
    int temp_x = x, temp_y = y;
    int i = 0, eatNum = 0;
    typedef int (*p)[gridNum]; //自定义类型
    p chessBoard = p(chess); //类型转换 并赋值给新变量 chessBoard
    //如果此方格内已有棋子,返回;
    if(chessBoard[temp_x][temp_y]!=Empty)
        return 0;
    for(i = 0 ; i <8; i++) //循环判断8个方向
    {
        temp_x += dir[i][0]; temp_y += dir[i][1]; //准备判断相邻棋子
        //如果没有出界,且相邻棋子是对方棋子,才有吃子的可能.
        if((temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
                && (chessBoard[temp_x][temp_y] != currentRole)
                && chessBoard[temp_x][temp_y]!=Empty)
        {
            temp_x += dir[i][0]; temp_y += dir[i][1]; //继续判断下一个
            //同样判断是否出界
            while(temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
            {
                //遇到空位跳出
                if(chessBoard[temp_x][temp_y] == Empty)
                        break;
                //找到了自己的棋子,可以吃子
                if(chessBoard[temp_x][temp_y] == currentRole)
                {
                        //改变(x,y)坐标内的信息
                    temp_x -= dir[i][0]; temp_y -= dir[i][1];
                    while((temp_x != x )||(temp_y != y)) //吃子的过程
                    {
                        temp_x -= dir[i][0]; temp_y -= dir[i][1];
                        eatNum ++;
                    }
                    break;
                }
                //如果仍然是对方棋子,继续沿此方向查找
                temp_x += dir[i][0]; temp_y += dir[i][1];
            }
        }
        temp_x = x; temp_y = y; //一个方向判断结束,准备下一个方向
    }
    return eatNum;
}








void heibai::on_pushButton_5_clicked()
{
    BlackNumber=2;
     WhiteNumber=2;
     ui->lcdNumber->display(BlackNumber);
     ui->lcdNumber_2->display(WhiteNumber);
     int i,j;
     currentRole=Empty;
     for(i=0;i<8;i++)
        {
             for(j=0;j<8;j++)
             {
                 chessNumber[i][j]=Empty;
             }
         }
     chessNumber[3][3]=Black;
     chessNumber[4][4]=Black;
     chessNumber[3][4]=White;
     chessNumber[4][3]=White;
}






void heibai::on_pushButton_8_clicked()
{
     QMessageBox::information(NULL,QString("Tip"),QString("The Computer is win!"));
}


void heibai::on_pushButton_7_clicked()
{


     QMessageBox::information(NULL,QString("Regulation"),QString("此游戏默认黑棋先下!点击begin开始,如果开始时是白旗,请再次点击一次begin切换到黑棋。棋子:黑白棋棋子每颗由黑白两色组成,一面白,一面黑,共64个(包括棋盘中央的4个)。棋子呈圆饼形。两个玩家各下一面棋子。棋盘:黑白棋棋盘由64(8*8)格的正方格组成,游戏进行时棋子要下在格内。棋盘为8×8的方格布局,开局时在棋盘正中有摆好的四枚棋子,黑白各2枚,交叉放置,由执黑棋的一方先落子,双方交替下子,棋子落在方格内,一局游戏结束后双方更换执子颜色。步合法的棋步包括:在一个空格新落下一个棋子,并且翻转对手一个或多个棋子。下子方式:把自己颜色的棋子放在棋盘的空格上,而当自己放下的棋子在横、竖、斜八个方向内有一个自己的棋子,则被夹在中间的对方棋子全部翻转会成为自己的棋子。夹住的位置上必须全部是对手的棋子,不能有空格。并且,只有在可以翻转棋子的地方才可以下子。一步棋可以在数个方向上翻棋,任何被夹住的棋子都必须被翻转过来,棋手无权选择不去翻某个棋子必须是刚下的子夹对方才能够翻对方的子,因翻转对方的棋子而夹住的子是不能被翻的。翻转棋子时,有一个棋子的翻转动画大概显示1秒左右每次下子最少必须翻转对方一个棋子,若棋局中下子都不能翻转对方棋子,则自动pass轮空,客户端界面气泡提示:您无子可下由对方继续下子,而对方气泡提示:由于对方无子可下,您可继续下子。若二个玩家都不能下子翻转对方棋子,游戏结束。 "));


}



heibai2.cpp


#include "heibai2.h"
#include "ui_heibai2.h"
#include <QTimer>
#include <QPainter>
#include <QPen>
#include "QMovie"
#include "QMessageBox"


heibai2::heibai2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::heibai2)
{
    ui->setupUi(this);
    sec=11;
     this->setMouseTracking(true);
    QTimer *timer;
    timer= new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(do_timer2()));
    timer->start(1000);


    QMovie *movie=new QMovie(":/new/prefix1/images /1.gif");
    ui->label->setPixmap(QPixmap(":/new/prefix1/images /black.png"));
    ui->label_2->setPixmap(QPixmap(":/new/prefix1/images /white.png"));
    ui->label_3->setMovie(movie);
    movie->start();
    movie->setSpeed(100);


    BlackNumber=2;
     WhiteNumber=2;
     ui->lcdNumber->display(BlackNumber);
     ui->lcdNumber_2->display(WhiteNumber);


     int i,j;
     currentRole=Air;
     for(i=0;i<8;i++)
        {
             for(j=0;j<8;j++)
             {
                 chessNumber[i][j]=Air;
             }
         }
     chessNumber[3][3]=Water;
     chessNumber[4][4]=Water;
     chessNumber[3][4]=Fire;
     chessNumber[4][3]=Fire;
}




void heibai2::mouseMoveEvent(QMouseEvent *e)
{
    xPoint=e->x();
    yPoint=e->y();
    this->update();
}






heibai2::~heibai2()
{
    delete ui;
}












void heibai2::do_timer()
{
    if(sec>0)
        {
        sec--;
        ui->lcdNumber_3->display(sec);
        }
     else
        {
             sec=11;
        }


}








void heibai2::on_pushButton_clicked()
{
    emit give2();
    this->close();
}








void heibai2::paintEvent(QPaintEvent *e)
{
     QPainter painer(this);
      painer.drawPixmap(0,0,1366,768,QPixmap(":/new/prefix1/images /33.png"));
     QPen pen;
     pen.setBrush(QBrush(Qt::Dense1Pattern));
     pen.setColor(QColor(Qt::white));
     painer.setPen(pen);
     painer.drawPixmap(110,110,480,480,QPixmap(":/new/prefix1/images /over.png"));
     int i,j;
     for(i=0;i<=8;i++)
         {
             painer.drawLine(110,110+(60*i),590,110+(60*i));
             painer.drawLine(110+(60*i),110,110+(60*i),590);
         }
     for(i=0;i<8;i++)
         {
             for(j=0;j<8;j++)
             {
                 if(chessNumber[i][j]==Water)
                 {


                     painer.drawPixmap(110+60*i,110+60*j,60,60,QPixmap(":/new/prefix1/images /black.png"));
                 }
                 else if(chessNumber[i][j]==Fire)
                 {
                     painer.drawPixmap(110+60*i,110+60*j,60,60,QPixmap(":/new/prefix1/images /white.png"));
                 }
             }
             if(currentRole==Water)
             {
                 painer.drawPixmap(xPoint-30,yPoint-30,60,60,QPixmap(":/new/prefix1/images /black.png"));


             }
             else
             {
                 painer.drawPixmap(xPoint-30,yPoint-30,60,60,QPixmap(":/new/prefix1/images /white.png"));
             }
         }


}












void heibai2::mousePressEvent(QMouseEvent *e)
{


    int x=e->x();
    x=(x-110)/60;
    int y=e->y();
    y=(y-110)/60;
    int a;
    if(currentRole==Water)
    {
    a=judgeRule(x,y,8,chessNumber,currentRole);
        if(a>0)
        {
                if(currentRole==Water)
                {
                    sec=11;
                    BlackNumber=BlackNumber+a+1;
                    WhiteNumber=WhiteNumber-a;
                    ui->lcdNumber->display(BlackNumber);
                    ui->lcdNumber_2->display(WhiteNumber);
                    currentRole=Fire;
                }
                           int m,n;
                           for(m=0;m<8;m++)
                           {
                               int eatNUmber;
                               for(n=0;n<8;n++)
                               {
                                   eatNUmber=judgeRule(m,n,8,chessNumber,currentRole);
                                   if(eatNUmber>0)
                                       break;


                               }
                               if(eatNUmber>0)
                               {
                                   sec=11;
                                   BlackNumber=BlackNumber-eatNUmber;
                                   WhiteNumber=WhiteNumber+eatNUmber+1;
                                   ui->lcdNumber->display(BlackNumber);
                                   ui->lcdNumber_2->display(WhiteNumber);
                                    currentRole=Water;
                                    sec=11;
                                    break;
                               }




                       }
        }
    }




     ui->lineEdit->clear();
     int add=0;
     int i,j;
     for(i=0;i<8;i++)
         for(j=0;j<8;j++)
             if(chessNumber[i][j]!=Air)
                 add++;
     if(add==64)
     {


         ui->pushButton->setEnabled(true);
         if(BlackNumber>WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The black is win"));
         else if(BlackNumber==WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("Draw"));
         else
             QMessageBox::information(NULL,QString("Tip"),QString("The white is win"));


         sec=0;
     }
     int flag=0;
     for(int i=0;i<8;i++)
         for(int j=0;j<8;j++)
             if(judgeRule2(i,j,8,chessNumber,currentRole))
                 flag=1;
     if(add!=64 && flag==0)
     {
         ui->pushButton->setEnabled(true);
         if(BlackNumber>WhiteNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The black is win"));
         else if(BlackNumber==WhiteNumber && BlackNumber != 2 && WhiteNumber != 2 )
             QMessageBox::information(NULL,QString("Tip"),QString("Draw"));
         else if(WhiteNumber>BlackNumber)
             QMessageBox::information(NULL,QString("Tip"),QString("The white is win"));


         sec=0;
     }
    this->update();
}




int heibai2::judgeRule(int x, int y, int gridNum, void *chess, GridState currentRole)
{
    int dir[8][2]={{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};


    if( x < 0 || x>= gridNum || y < 0 || y >= gridNum) // 判断坐标是否合法
        return 0;
    int temp_x = x, temp_y = y;
    int i = 0, eatNum = 0;
    typedef int (*p)[gridNum]; //自定义类型
    p chessBoard = p(chess); //类型转换 并赋值给新变量 chessBoard
    //如果此方格内已有棋子,返回;
    if(chessBoard[temp_x][temp_y]!=Air)
        return 0;
    for(i = 0 ; i <8; i++) //循环判断8个方向
    {
        temp_x += dir[i][0]; temp_y += dir[i][1]; //准备判断相邻棋子
        //如果没有出界,且相邻棋子是对方棋子,才有吃子的可能.
        if((temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
                && (chessBoard[temp_x][temp_y] != currentRole)
                && chessBoard[temp_x][temp_y]!=Air)
        {
            temp_x += dir[i][0]; temp_y += dir[i][1]; //继续判断下一个
            //同样判断是否出界
            while(temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
            {
                //遇到空位跳出
                if(chessBoard[temp_x][temp_y] == Air)
                        break;
                //找到了自己的棋子,可以吃子
                if(chessBoard[temp_x][temp_y] == currentRole)
                {
                    chessBoard[x][y] = currentRole; //改变(x,y)坐标内的信息
                    temp_x -= dir[i][0]; temp_y -= dir[i][1];
                    while((temp_x != x )||(temp_y != y)) //吃子的过程
                    {
                        chessBoard[temp_x][temp_y] = currentRole;
                        temp_x -= dir[i][0]; temp_y -= dir[i][1];
                        eatNum ++;
                    }
                    break;
                }
                //如果仍然是对方棋子,继续沿此方向查找
                temp_x += dir[i][0]; temp_y += dir[i][1];
            }
        }
        temp_x = x; temp_y = y; //一个方向判断结束,准备下一个方向
    }
    return eatNum;
}




void heibai2::do_timer2()
{
        if(sec>0)
        {
            sec--;
            ui->lcdNumber_3->display(sec);
        }
        else
       {


        ui->lineEdit->setText("time over");


        if(currentRole==Fire)
        {
              currentRole=Water;
              sec=11;


        }
        else if(currentRole==Water)
         {
            sec=11;
            currentRole=Fire;


         }
    }
    this->update();


}










void heibai2::on_pushButton_3_clicked()
{
        ui->lcdNumber->display(0);
        timer->stop();
        sec=11;
        BlackNumber=2;
        WhiteNumber=2;
        ui->lcdNumber->display(BlackNumber);
        ui->lcdNumber_3->display(WhiteNumber);
        int i,j;
        currentRole=Air;
        for(i=0;i<8;i++)
           {


            for(j=0;j<8;j++)
            {
                chessNumber[i][j]=Air;
            }
        }
        chessNumber[3][3]=Water;
        chessNumber[4][4]=Water;
        chessNumber[3][4]=Fire;
        chessNumber[4][3]=Fire;
}








void heibai2::on_pushButton_4_clicked()
{
        currentRole=Water;
        BlackNumber=2;
        WhiteNumber=2;
}
int heibai2::judgeRule2(int x, int y, int gridNum, void *chess, GridState currentRole)
{
    int dir[8][2]={{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};


    if( x < 0 || x>= gridNum || y < 0 || y >= gridNum) // 判断坐标是否合法
        return 0;
    int temp_x = x, temp_y = y;
    int i = 0, eatNum = 0;
    typedef int (*p)[gridNum]; //自定义类型
    p chessBoard = p(chess); //类型转换 并赋值给新变量 chessBoard
    //如果此方格内已有棋子,返回;
    if(chessBoard[temp_x][temp_y]!=Air)
        return 0;
    for(i = 0 ; i <8; i++) //循环判断8个方向
    {
        temp_x += dir[i][0]; temp_y += dir[i][1]; //准备判断相邻棋子
        //如果没有出界,且相邻棋子是对方棋子,才有吃子的可能.
        if((temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
                && (chessBoard[temp_x][temp_y] != currentRole)
                && chessBoard[temp_x][temp_y]!=Air)
        {
            temp_x += dir[i][0]; temp_y += dir[i][1]; //继续判断下一个
            //同样判断是否出界
            while(temp_x < gridNum && temp_x >=0 && temp_y < gridNum && temp_y >= 0)
            {
                //遇到空位跳出
                if(chessBoard[temp_x][temp_y] == Air)
                        break;
                //找到了自己的棋子,可以吃子
                if(chessBoard[temp_x][temp_y] == currentRole)
                {
                        //改变(x,y)坐标内的信息
                    temp_x -= dir[i][0]; temp_y -= dir[i][1];
                    while((temp_x != x )||(temp_y != y)) //吃子的过程
                    {
                        temp_x -= dir[i][0]; temp_y -= dir[i][1];
                        eatNum ++;
                    }
                    break;
                }
                //如果仍然是对方棋子,继续沿此方向查找
                temp_x += dir[i][0]; temp_y += dir[i][1];
            }
        }
        temp_x = x; temp_y = y; //一个方向判断结束,准备下一个方向
    }
    return eatNum;
}






void heibai2::on_pushButton_5_clicked()
{
     QMessageBox::information(NULL,QString("Tip"),QString("Computer is win!"));
}






void heibai2::on_pushButton_6_clicked()
{
     BlackNumber=2;
     WhiteNumber=2;
     ui->lcdNumber->display(BlackNumber);
     ui->lcdNumber_2->display(WhiteNumber);
     int i,j;
  
     for(i=0;i<8;i++)
        {
             for(j=0;j<8;j++)
             {
                 chessNumber[i][j]=Air;
             }
         }
     chessNumber[3][3]=Water;
     chessNumber[4][4]=Water;
     chessNumber[3][4]=Fire;
     chessNumber[4][3]=Fire;




}




void heibai2::on_pushButton_7_clicked()
{
    QMessageBox::information(NULL,QString("Regulation"),QString("此游戏默认黑棋先下!点击begin开始,如果开始时是白旗,请再次点击一次begin切换到黑棋。棋子:黑白棋棋子每颗由黑白两色组成,一面白,一面黑,共64个(包括棋盘中央的4个)。棋子呈圆饼形。两个玩家各下一面棋子。棋盘:黑白棋棋盘由64(8*8)格的正方格组成,游戏进行时棋子要下在格内。棋盘为8×8的方格布局,开局时在棋盘正中有摆好的四枚棋子,黑白各2枚,交叉放置,由执黑棋的一方先落子,双方交替下子,棋子落在方格内,一局游戏结束后双方更换执子颜色。步合法的棋步包括:在一个空格新落下一个棋子,并且翻转对手一个或多个棋子。下子方式:把自己颜色的棋子放在棋盘的空格上,而当自己放下的棋子在横、竖、斜八个方向内有一个自己的棋子,则被夹在中间的对方棋子全部翻转会成为自己的棋子。夹住的位置上必须全部是对手的棋子,不能有空格。并且,只有在可以翻转棋子的地方才可以下子。一步棋可以在数个方向上翻棋,任何被夹住的棋子都必须被翻转过来,棋手无权选择不去翻某个棋子必须是刚下的子夹对方才能够翻对方的子,因翻转对方的棋子而夹住的子是不能被翻的。翻转棋子时,有一个棋子的翻转动画大概显示1秒左右每次下子最少必须翻转对方一个棋子,若棋局中下子都不能翻转对方棋子,则自动pass轮空,客户端界面气泡提示:您无子可下由对方继续下子,而对方气泡提示:由于对方无子可下,您可继续下子。若二个玩家都不能下子翻转对方棋子,游戏结束。 "));
}


main.cpp



#include "begin.h"
#include <QApplication>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    begin w;
    w.show();
    w.setFixedSize(1366,768);


    return a.exec();
}




Ubuntu下的五子棋游戏代码 本段五子棋C语言代码是在Linux下编写的。 立即下载

相关推荐

linux终端的中国象棋

linux终端的中国象棋 学习用 linux终端的中国象棋 学习用 linux终端的中国象棋 学习用

在ubuntu上用QT写一个简单的C++小游戏(附源码)

开心啊,今天

林一百二十八的博客 3763

在linux下ubuntu的五子棋游戏c语言代码(20220212161732).pdf

在linux下ubuntu的五子棋游戏c语言代码(20220212161732).pdf

Qt版的贪吃蛇游戏

**开发环境:**Ubuntu12.04 Qt4.8 项目概述: 用键盘上下左右控制蛇的方向,寻找食物,食物随机出现,蛇路过食物蛇的身体会变长,蛇不能碰墙壁及自己的身体,蛇不能相撞,两条蛇谁先达到一定的分数谁获得胜利 **游戏说明:**程序运行后,单击鼠标左键开始游戏 蛇一:方向键上下左右,蛇二WASD上下左右 1.main.cpp #include <QtGui/QApplication> #include <QTextCodec> #include "widget.h" int

weixin_46810858的博客 458

小龙虾 OpenClaw 安装全攻略:本地部署 AI 智能体一步到位

OpenClaw(昵称小龙虾)是一款 MIT 开源协议的本地优先 AI 智能体执行网关,支持多平台接入、本地部署,能实现自然语言驱动的设备自动化操作,区别于纯对话 AI,可直接操控系统执行实际任务,数据全程本地存储更安全。本文带来 2026 最新版 OpenClaw 安装教程,适配 Windows/macOS/Linux 全系统,新手也能一键搞定。

lujiawei00的专栏 1976

Simplorer-Maxwell联合仿真速度太慢?我用这3个技巧把仿真时间砍半(附SVPWM周期与步长设置避坑)

本文详细介绍了Simplorer-Maxwell联合仿真性能优化的3个关键技巧,包括仿真步长与周期的科学配置、基于任务调度的加速技术以及模型简化与精度平衡。特别针对SVPWM参数设置提供了避坑指南,帮助工程师在不牺牲精度的情况下将仿真时间缩短50%以上,适用于电机驱动系统开发等场景。

weixin_29189381的博客 466

linux终端的中国象棋,在Ubuntu 17.10上玩国际象棋等游戏

Mac OS X和Windows 7的某些版本曾经有国际象棋游戏,但是Ubuntu没有。 Ubuntu的确提供了常见的免费游戏 - 纸牌游戏,一些拼字游戏,但没有国际象棋游戏。 幸运的是,Ubuntu安装与Mac OS X和Windows 7的象棋还是比较是相当容易的。 有一个名为GNOME游戏的免费软件包,它包括一个国际象棋游戏。 由于GNOME游戏包是Linux原生的,因此在Ubuntu 17...

weixin_34523442的博客 1453

基于FPGA低频方波测量-频率与占空比

基于FPGA低频方波测量-频率与占空比

DRAXY的博客 6733

Ubuntu下安装象棋游戏天书棋谈-Gmchess

Gmchess是一款象棋游戏软件,它支持多种网络游戏平台的棋谱读取 同时支持自己摆棋,使用ubuntu系统的朋友们现在可以很方便的安装了! 安装方法: 1.添加key sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 04F95913 2.添加第三方软件源: 9.10用户: ...

congine_mcfeng的专栏 1730

避开SAM3安装大坑:手把手教你用国内镜像和Modelscope权重快速跑通Demo

本文详细介绍了如何在国内环境下快速部署SAM3视觉大模型,包括使用国内镜像加速Python包安装、通过Modelscope获取权重文件以及解决CUDA 11.8等低版本适配问题。手把手教你避开常见安装陷阱,实现高效Demo运行。

weixin_30642561的博客 1407

【数据库系统工程师】5.4Internet基础知识

目录一、思维导图二、知识点1.Internet 概述2.Internet 地址(1)域名(2)IP 地址(3)NAT技术(4)IPv6简介3.Internet 服务(1)域名服务(2)远程登录服务(3)电子邮件服务(4)WWW服务(5)文件传输服务 一、思维导图 二、知识点 1.Internet 概述 2.Internet 地址 (1)域名 ○ 一个完整、通用的层次型主机域名由如下4部分组成: 计算机主机名.本地名.组名.最高层域名 (2)IP 地址 ○ 每个IP地址都由4个小于256的数字组成,数字之

邓邓子的博客 911

[Ubuntu] ubuntu/LINUX游戏集锦(更新十余款大型3D游戏)

类似超级玛莉的游戏 安装方法,终端输入: sudo apt-get install supertux 百战天虫 sudo apt-get install wormux 可爱的小虫子们跑到linux下面了 ============================ chromium雷电,画质一流,和windows版的没有太大区别,个人认为超越了windows版 sudo

yp120yp的专栏 2万+

AutosarMCAL开发——基于EB CRC驱动

本文为博主个人理解总结记录,如有不正,欢迎指正。

qq_45583706的博客 1390

基于Ubuntu的计算器Qt程序设计

简述在Ubuntu操作系统下使用Qt实现带界面的简单计算器,实现加减乘除运算 Ubuntu 16.04 LTS Qt 4.8.2 界面设计新建一个桌面应用,使用Qt creator设计界面做如下布局组件 拖放一个QLineEdit 4*4排列16个QPushButton 修改对应按钮的值 修改主窗口标题为”计算器” 布局 4*4按钮全部选中,进行栅格布局 选中4*4按钮和QLineEdit

郝凡的博客 3866

分布式计算Ray框架:从入门到精通完全教程

想象一下,你有一个机器学习模型要训练,数据集大到让你的笔记本电脑直冒烟;或者你需要并行跑几百个爬虫任务,但线程池和多进程搞得你头晕眼花。传统的单机计算已经hold不住这些场景,分布式计算应运而生。然而,传统的分布式框架(如Hadoop、Spark)要么配置复杂,要么对动态任务支持不佳。这时候,Ray闪亮登场!Ray是一个开源的分布式计算框架,专为高性能、灵活性和易用性而生。它最初由UC Berkeley的RISELab团队开发,目标是让开发者用最少的代码实现分布式任务。无论是数据处理、机器学习,还是仿真任务

大模型大数据攻城狮的专栏 1318

超临界二氧化碳再热再压缩布雷顿循环建模与先进控制

超临界二氧化碳布雷顿循环建模与先进控制研究 本文研究了超临界二氧化碳再热再压缩布雷顿循环系统的建模与控制。通过MATLAB/Simscape构建了包含压缩机、透平、回热器等关键组件的动态模型,并设计了基于模型预测控制(MPC)和自抗扰控制(ADRC)的多层控制策略。系统采用转速控制的压缩机、阀门开度控制的透平,以及可变热源加热器,实现了全动态分析。研究结果表明,MPC与ADRC混合控制方案相较于传统PID控制,功率超调降低至0.9%,效率波动控制在±0.08%,扰动恢复时间缩短至12秒。

AI的内部世界的博客 342

Qt版贪吃蛇游戏

Qt版贪吃蛇游戏 转载请标明出处:牟尼的专栏 http://blog.youkuaiyun.com/u012027907     最近在学习Qt,用了一个多月的时间掌握了Qt中最基本的知识,也完成了《Qt版音乐播放器》、《Qt版贪吃蛇游戏》、《Qt版双人俄罗斯方块》以及《Qt版科学计算器》等,之前在VC下写过这些程序,所以在Qt下只是改变了显示等语句,我写过《C++版贪吃蛇游戏》、《VC版贪吃蛇游戏》

牟尼的专栏 4173

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

俄罗斯方块----Ubuntu终端游戏

我最近在看C++和linux,为了能够更加牢靠的掌握自己的学到的知识,所以采用写小游戏的方法来帮助自己巩固学习。在这篇代码中我用到的C++和linux知识有: C++知识: 1. 类的创建 2. 内联函数 3. pthread线程 linux知识: 1. 进入root模式 2. 给文件增加权限 3. 查看和使用系统的外设

送故事的妖怪 2867

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Ubuntu Linux上几款好玩的免费游戏

1.SuperTuxKart(赛车游戏) wangyetao@linux_u1604:~$ sudo apt-get install supertuxkart 下列【新】软件包将被安装: libenet7 supertuxkart supertuxkart-data 需要下载 423 MB 的归档。 解压缩后会消耗 561 MB 的额外空间。...

dnbug Blog 1万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

基于Qt的飞机小游戏实现

这是学习Qt时期做的一个小项目,现在看感觉有很多可优化的地方,放在这里给新人朋友们提供一个参考。

qq_39347787的博客 2082

Linux下的小游戏

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34335458的博客 1434

[QT]别样贪吃蛇

1、通过这个小游戏的开发,我学习到了更多的的绘图事件,以及一些关系的响应。2、对这些有更多的理解3、使用QT开发,界面的背景来源于互联网。小游戏截图:

Jo Ran 879

基于Ubuntu+Bochs模拟器实现的操作系统图形化的小游戏(2048、flappybird、)

本次课程设计主要实现了图形化,对外设管理部分进行重新实现,实现了 B 级项目难度;本系统修改了外设显卡部分,使系统支持图形化界面,但由于时间精力有限, 我们的主要界面仍然是命令行的形式,但是命令行中所有的文字都是使用像素点拼凑的形式展现出来的,同时在图形化的基础上实现了开机动画,图片显示,以及一个小游戏。本次操作系统课程设计小组成员为 3 人,基于《Orange’s⼀个操作系统的实现》,通过修改或重新实现源码的一个或多个模块来实现一个简单得操作系统。项目设计与功能说明文档 1。操作系统课程设计文档 1。

毕业作品网站 731

Ubuntu下纯代码编写简易贪吃蛇游戏(第二次做)

源文件名snake2.c 运行效果图如下 源代码如下: #include #include #include #include #include #include #include #include #include #define MOVEUP(x) printf("\033[%dA", (x)) 

hacker_num1的博客 2739

Ubuntu中也能玩游戏

Ubuntu中也能玩游戏 如果只是介绍“sl”可以跑小火车(sudo apt-get install sl),“fortune”可以输出“fortune cookie”(sudo apt-get install fortune),“cmatrix”可以模拟黑客帝国(sudo apt-get install cmatrix ),也未免太无趣了一些。但是,你真的可以在终端玩2048、贪吃蛇、俄罗斯方块、pacman等各种游戏哦!你还可以在终端用tpp制作ppt,但是实在是不划算,用w3m浏览网

suwu150 1万+

Ubuntu(Linux)下编写一次QT程序

本文记录了Ubuntu(Linux)下编写一次QT程序的过程。

qq_45902301的博客 2524
上一篇: Ubuntu下C语言实现贪吃蛇游戏
下一篇: Ubuntu下纯代码编写简易贪吃蛇游戏(第二次做)
hacker_num1
博客等级 码龄9年 11粉丝 7原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值