Qt checkers getting weird output
<p>I have gone over it many times, I am getting an extra checker when I am moving (-1, -1). on the white checker down left. </p>

<p>Don't mind the moving over another checker, its for the next step.</p>

<p>I can't find where i am setting an extra checker on the board[][]</p>

<p>So please if you can in anyone help, it would be much appreciated.</p>

<p><a href="http://i.stack.imgur.com/XB2PC.png" rel="nofollow">Beginning of game</a></p>

<p><a href="http://i.stack.imgur.com/KZh0U.png" rel="nofollow">After moving -1 -1</a></p>

<pre><code>    /**
* \file CheckerWindow.cpp
* \brief Checker window
*/
#include "checkerwindow.h"
#include "ui_checkerwindow.h"
#include &lt;QtGui&gt;
#include &lt;iostream&gt;
/*!
  *Game2
  *\brief Checker
  */
CheckerWindow::CheckerWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::CheckerWindow)
{
    ui-&gt;setupUi(this);
    this-&gt;setFixedSize(500,650);
    this-&gt;setWindowTitle("4x4 Checker");
    // board slots
    // row1
    slot[0] = QRect(50,100,100,100);
    slot[1] = QRect(150,100,100,100);
    slot[2] = QRect(250,100,100,100);
    slot[3] = QRect(350,100,100,100);
    // row2
    slot[4] = QRect(50,200,100,100);
    slot[5] = QRect(150,200,100,100);
    slot[6] = QRect(250,200,100,100);
    slot[7] = QRect(350,200,100,100);
    // row3
    slot[8] = QRect(50,300,100,100);
    slot[9] = QRect(150,300,100,100);
    slot[10] = QRect(250,300,100,100);
    slot[11] = QRect(350,300,100,100);
    // row4
    slot[12] = QRect(50,400,100,100);
    slot[13] = QRect(150,400,100,100);
    slot[14] = QRect(250,400,100,100);
    slot[15] = QRect(350,400,100,100);
    indexMoving=0;
    isMoving=false;
    for (int i = 0; i &lt; 3; i++) {
        for (int j = 0; j &lt; 3; j++) {
            board[i][j] = 0;
        }
    }
    for (int i = 0; i &lt; 3; i++) {
        for (int j = 0; j &lt; 3; j++) {
            color[i][j] = 0;
        }
    }
    board[0][0]=1;
    board[0][2]=1;
    board[3][1]=2;
    board[3][3]=2;
}
CheckerWindow::~CheckerWindow()
{
    delete ui;
}
void CheckerWindow::paintEvent(QPaintEvent* e) {
    QPainter* painter = new QPainter(this);
    painter-&gt;fillRect(this-&gt;rect(),QColor("white"));
    painter-&gt;setPen(QColor("black"));
    int s=0;
    painter-&gt;drawRects(slot, 16);
    //to draw the background
    for (int i = 0; i &lt; 4; i++) {
        for (int j = 0; j &lt; 4; j++) {
            int slotN = i*4 + j;
            if (s == 1) {
                painter-&gt;drawPixmap(slot[slotN].x(), slot[slotN].y(), QPixmap("../Images/wood1.png") );
                s=0;
            } else{
                painter-&gt;drawPixmap(slot[slotN].x(), slot[slotN].y(), QPixmap("../Images/wood2.png") );
                s=1;
            }
        }
        s=1;
        if(i==1) {
            s=0;
        }
    }
    s=0;
    //add the chekers on the board
    for (int i = 0; i &lt; 4; i++) {
        for (int j = 0; j &lt; 4; j++) {
            int slotN = i*4 + j;
            if(color[i][j] == 1) {
                qDebug("coloring");
                painter-&gt;drawPixmap(slot[slotN].x(), slot[slotN].y(), QPixmap("../Images/green.jpeg") );
                color[i][j]=0;
                isMoving=true;
            }
            if (board[i][j] == 1) {
                painter-&gt;drawPixmap(slot[slotN].x(), slot[slotN].y(), QPixmap("../Images/checker1.png") );
            }
            else if (board[i][j] == 2){
                painter-&gt;drawPixmap(slot[slotN].x(), slot[slotN].y(), QPixmap("../Images/checker2.png") );
            }
        }
    }
}
/**
* \brief This mouseEvent() function
* will move the ball downwards by 1, at the same time it should check
* \param The MouseEvent is used to know where the mouse is pressed
*/
void CheckerWindow::mousePressEvent(QMouseEvent *e) {
    for (int i = 0; i &lt; 16; i++) {
        if (slot[i].contains(e-&gt;pos())) {
            qDebug("Inside e-&gt;pos");
            int row = i/4;
            int col = i%4;
            if(board[row][col]==1 || board[row][col]==2) {
                indexMoving=i;
                color[row][col]=1;
                isMoving=true;
                repaint();
                qDebug("color");
            }
            else if(isMoving) {
                qDebug("move");
                int rowOld = indexMoving/4;
                int colOld = indexMoving%4;
                if(board[rowOld][colOld]==1) {
                    if((row == rowOld+1) &amp;&amp; (col == colOld+1) ) {
                        qDebug("IN +1 +1");
                        board[row][col]=1;
                        board[rowOld][colOld]=0;
                        color[rowOld][colOld]=0;
                        repaint();
                    }
                    else if((row == rowOld+1) &amp;&amp; (col == colOld-1) ) {
                        qDebug("IN +1 -1");
                        board[row][col]=1;
                        board[rowOld][colOld]=0;
                        color[rowOld][colOld]=0;
                        repaint();
                    }
                    else if(board[rowOld+1][colOld+1]==2) {
                        qDebug("IN +1 +1 moving over another");
                        board[row][col]=1;
                        board[rowOld][colOld]=3;
                        repaint();
                        board[rowOld][colOld]=0;
                        board[rowOld+1][colOld+1]=3;
                        repaint();
                        board[rowOld+1][colOld+1]=0;
                    }
                    else if(board[rowOld+1][colOld-1]==2) {
                        qDebug("IN +1 -1 moving over another");
                        board[row][col]=1;
                        board[rowOld][colOld]=3;
                        repaint();
                        board[rowOld][colOld]=0;
                        board[rowOld+1][colOld-1]=3;
                        repaint();
                        board[rowOld+1][colOld-1]=0;
                    }
                }
                else if(board[rowOld][colOld]==2) {
                    if((row == rowOld-1) &amp;&amp; (col == colOld-1) ) {
                        qDebug("IN -1 -1");
                        board[row][col]=2;
                        board[rowOld][colOld]=0;
                        color[rowOld][colOld]=0;
                        repaint();
                    }
                    else if((row == rowOld-1) &amp;&amp; (col == colOld+1) ) {
                        qDebug("IN -1 +1");
                        board[row][col]=2;
                        board[rowOld][colOld]=0;
                        color[rowOld][colOld]=0;
                        repaint();
                    }
                    else if(board[rowOld-1][colOld-1]==1) {
                        qDebug("IN +1 +1 moving over another");
                        board[row][col]=2;
                        board[rowOld][colOld]=3;
                        repaint();
                        board[rowOld][colOld]=0;
                        board[rowOld-1][colOld-1]=3;
                        repaint();
                        board[rowOld-1][colOld-1]=0;
                    }
                    else if(board[rowOld-1][colOld+1]==1) {
                        qDebug("IN +1 -1 moving over another");
                        board[row][col]=2;
                        board[rowOld][colOld]=3;
                        repaint();
                        board[rowOld][colOld]=0;
                        board[rowOld-1][colOld+1]=3;
                        repaint();
                        board[rowOld-1][colOld+1]=0;
                    }
                }
                //qDebug("Set is Moving False");
                isMoving=false;
                indexMoving=0;
            }
        }
        else {
            //qDebug("In the else");
            //repaint();
        }
    }
}
</code></pre>