谁看得懂这是什么吗?

五子棋交流


#1 谁看得懂这是什么吗? 作者:絕版賭徒 发表时间:2013-6-22 0:55:47

// (x1,y1)(x2,y2)     (x3,y3) (x4,y4) 是否平行
static BOOL parallel(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
    return (y2 - y1) * (x4 - x3) == (x2 - x1) * (y4 - y3);
}

// (x1,y1)(x2,y2)     (x3,y3) (x4,y4) 是否垂直
static BOOL perpendicular(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
    return (y2 - y1) * (y4 - y3) == - (x2 - x1) * (x4 - x3);
}

//(x4, y4)(x1,y1) 关于 (x2,y2)(x3,y3)线对称
static void lineSym(int x1, int y1, int x2, int y2, int x3, int y3, int& x4, int& y4)
{
    x4 = (x1 * x2 * x2 - 2 * x1 * x2 * x3 + x1 * x3 * x3 + 2 * x2 * y1 * y2 - 2 * x3 * y1 * y2 - x1 * y2 * y2 +
          2 * x3 * y2 * y2 - 2 * x2 * y1 * y3 + 2 * x3 * y1 * y3 + 2 * x1 * y2 * y3 - 2 * x2 * y2 * y3 - 2 * x3 * y2 * y3 -
          x1 * y3 * y3 + 2 * x2 * y3 * y3) / (x2 * x2 - 2 * x2 * x3 + x3 * x3 + y2 * y2 - 2 * y2 * y3 + y3 * y3);
    y4 = (-(x2 * x2 * y1) + 2 * x2 * x3 * y1 - x3 * x3 * y1 + 2 * x1 * x2 * y2 - 2 * x1 * x3 * y2 - 2 * x2 * x3 * y2 +
          2 * x3 * x3 * y2 + y1 * y2 * y2 - 2 * x1 * x2 * y3 + 2 * x2 * x2 * y3 + 2 * x1 * x3 * y3 - 2 * x2 * x3 * y3 -
          2 * y1 * y2 * y3 + y1 * y3 * y3) / (x2 * x2 - 2 * x2 * x3 + x3 * x3 + y2 * y2 - 2 * y2 * y3 + y3 * y3);
}


// (x3, y3) (x1,y1)关于 (x2,y2)点对称
static void pointSym(int x1, int y1, int x2, int y2, int& x3, int& y3)
{
    x3 = 2 * x2 - x1;
    y3 = 2 * y2 - y1;
}

#2 Re:谁看得懂这是什么吗? 作者:踵酃 发表时间:2013-6-22 1:54:58

看的懂,是代码

-----------------------------------------
static BOOL parallel//check input, return if parallel
static BOOL perpendicular//check input , return if perpendicular

[此帖子已被 踵酃 在 2013-6-22 1:58:53 编辑过]


#3 Re:谁看得懂这是什么吗? 作者:絕版賭徒 发表时间:2013-6-22 2:11:28

// (x1,y1)(x2,y2)     (x3,y3) (x4,y4) 是否平行
static BOOL parallel(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
    return (y2 - y1) * (x4 - x3) == (x2 - x1) * (y4 - y3);
}

// (x1,y1)(x2,y2)     (x3,y3) (x4,y4) 是否垂直
static BOOL perpendicular(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
    return (y2 - y1) * (y4 - y3) == - (x2 - x1) * (x4 - x3);
}

//(x4, y4)(x1,y1) 关于 (x2,y2)(x3,y3)线对称
static void lineSym(int x1, int y1, int x2, int y2, int x3, int y3, int& x4, int& y4)
{
    x4 = (x1 * x2 * x2 - 2 * x1 * x2 * x3 + x1 * x3 * x3 + 2 * x2 * y1 * y2 - 2 * x3 * y1 * y2 - x1 * y2 * y2 +
          2 * x3 * y2 * y2 - 2 * x2 * y1 * y3 + 2 * x3 * y1 * y3 + 2 * x1 * y2 * y3 - 2 * x2 * y2 * y3 - 2 * x3 * y2 * y3 -
          x1 * y3 * y3 + 2 * x2 * y3 * y3) / (x2 * x2 - 2 * x2 * x3 + x3 * x3 + y2 * y2 - 2 * y2 * y3 + y3 * y3);
    y4 = (-(x2 * x2 * y1) + 2 * x2 * x3 * y1 - x3 * x3 * y1 + 2 * x1 * x2 * y2 - 2 * x1 * x3 * y2 - 2 * x2 * x3 * y2 +
          2 * x3 * x3 * y2 + y1 * y2 * y2 - 2 * x1 * x2 * y3 + 2 * x2 * x2 * y3 + 2 * x1 * x3 * y3 - 2 * x2 * x3 * y3 -
          2 * y1 * y2 * y3 + y1 * y3 * y3) / (x2 * x2 - 2 * x2 * x3 + x3 * x3 + y2 * y2 - 2 * y2 * y3 + y3 * y3);
}


// (x3, y3) (x1,y1)关于 (x2,y2)点对称
static void pointSym(int x1, int y1, int x2, int y2, int& x3, int& y3)
{
    x3 = 2 * x2 - x1;
    y3 = 2 * y2 - y1;
}

static void addmove(int x, int y, int* out)
{
    if(IsLegalMove(x / 2, y / 2))
    {
        out[0] ++;
        out[out[0]] = x / 2 + y / 2 * 16;
    }
}

int CBOOK::BdGet5thNotConsideredMoves(const int* in, int* out, int move)
{
    if(GameAllow5thSymMove)
    {
        return 0;
    }

    out[0] = 0;
    rs_assert(in[0] == 4);
    int total = 0;
    int bx1, bx2, wx3, wx4, by1, by2, wy3, wy4;
    int mbx, mby, mwx, mwy;
    bx1 = 2 * ShowXCoordTable[in[1]];
    bx2 = 2 * ShowXCoordTable[in[3]];
    by1 = 2 * ShowYCoordTable[in[1]];
    by2 = 2 * ShowYCoordTable[in[3]];
    wx3 = 2 * ShowXCoordTable[in[2]];
    wx4 = 2 * ShowXCoordTable[in[4]];
    wy3 = 2 * ShowYCoordTable[in[2]];
    wy4 = 2 * ShowYCoordTable[in[4]];
    int x  = 2 * ShowXCoordTable[move];
    int y  = 2 * ShowYCoordTable[move];
    int x1, y1, x2, y2, x3, y3;


mbx = (bx1 + bx2) / 2;
mby = (by1 + by2) / 2;
mwx = (wx3 + wx4) / 2;
mwy = (wy3 + wy4) / 2;
//(x, y)黑子的第五手

//黑两子所在线和 白两子所在线是否平行
    if(parallel(bx1, by1, bx2, by2, wx3, wy3, wx4, wy4))
    {
//黑两子所在线 和 黑两子中点,白两子中点是否垂直,不垂直就不对称
        if(!perpendicular(bx1, by1, bx2, by2, mbx, mby, mwx, mwy))
        {
            return 0;
        }

//黑两子所在线和其中一白子,是否三点一线,
        if(parallel(bx1, by1, bx2, by2, bx2, by2, wx4, wy4))
        {
            // coline
            if(mbx != mwx || mby != mwy)  //是否黑两子中间点等于白两子中间点
            {
                return 0;
            }

            pointSym(x, y, mbx, mby, x1, y1); 
            lineSym(x, y,  bx1, by1, bx2, by2, x2, y2);
            pointSym(x2, y2, mbx, mby, x3, y3);
addmove(x1, y1, out);  //排除对称点(x1,y1)
            addmove(x2, y2, out);  //排除对称点(x2,y2)
            addmove(x3, y3, out);  //排除对称点(x3,y3)
            return 0;
        }

        lineSym(x, y, mbx, mby, mwx, mwy, x1, y1);
        addmove(x1, y1, out); //排除对称点(x1,y1)
        return 0;
    }

    if(mbx != mwx || mby != mwy)
    {
        return 0;
    }

    if(perpendicular(bx1, by1, bx2, by2, wx3, wy3, wx4, wy4))
    {
        pointSym(x, y, mbx, mby, x1, y1);
        lineSym(x, y,  bx1, by1, bx2, by2, x2, y2);
        pointSym(x2, y2, mbx, mby, x3, y3);
addmove(x1, y1, out);  //排除对称点(x1,y1)
addmove(x2, y2, out);  //排除对称点(x2,y2)
addmove(x3, y3, out);  //排除对称点(x3,y3)
        return 0;
    }
    else
    {
        pointSym(x, y, mbx, mby, x1, y1);
        addmove(x1, y1, out);
    }

    return 0;
}

#4 Re:谁看得懂这是什么吗? 作者:屏蔽 发表时间:2013-6-22 8:30:16

打点对称判断程序。

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]

[ 絕版賭徒 于 2013-6-22 12:14:24 时花20金币送鲜花一朵]


#5 Re:谁看得懂这是什么吗? 作者:伤情路 发表时间:2013-6-22 19:09:27

C++代码?