Ejemplo n.º 1
0
    public int SetCheckScore(ChessType[,] gridArray, int x, int y, ChessType chessType)
    {
        Vector2Int inputPos = new Vector2Int(x, y);
        int        score    = 0;

        for (int md = 0; md < 4; md++)
        {
            ChessBoardManager.MoveDir _moveDir = (ChessBoardManager.MoveDir)md;
            string str = "1";
            int    xDir = 0, yDir = 0;
            switch (_moveDir)
            {
            case ChessBoardManager.MoveDir.TransverseLine:
                xDir = 1; yDir = 0;
                break;

            case ChessBoardManager.MoveDir.VerticalLine:
                xDir = 0; yDir = 1;
                break;

            case ChessBoardManager.MoveDir.LeftSlantLine:
                xDir = 1; yDir = -1;
                break;

            case ChessBoardManager.MoveDir.RightSlantLine:
                xDir = 1; yDir = 1;
                break;

            default:
                break;
            }

            bool nextLeft = false, nextRight = false, leftStop = false, rightStop = false, lastLeftPos = true;
            int  count = 1, maxCont = 6;
            for (int i = 1; i < chessMaxBoard; i++)
            {
                if ((leftStop && rightStop) || count >= maxCont)
                {
                    break;
                }

                for (int dir = -1; dir <= 1; dir += 2)
                {
                    if ((nextLeft && dir > 0) || (nextRight && dir < 0))
                    {
                        continue;
                    }
                    if ((dir < 0 && leftStop) || (dir > 0 && rightStop))
                    {
                        continue;
                    }
                    if (count >= maxCont)
                    {
                        break;
                    }

                    Vector2Int newPoint = new Vector2Int(inputPos.x + dir * xDir * i, inputPos.y + dir * yDir * i);
                    if (chessBoardManager.CheckBorder(newPoint))
                    {
                        string ch;
                        if (gridArray[newPoint.x, newPoint.y] == chessType)
                        {
                            ch = "1";
                        }
                        else if (gridArray[newPoint.x, newPoint.y] == ChessType.None)
                        {
                            ch = "0";
                        }
                        else
                        {
                            if (dir > 0)
                            {
                                rightStop = true;
                            }
                            else if (dir < 0)
                            {
                                leftStop = true;
                            }
                            continue;
                        }
                        if (dir < 0)
                        {
                            lastLeftPos = true;
                            str         = ch + str;
                            if (ch == "1")
                            {
                                nextLeft = true;
                            }
                        }
                        else if (dir > 0)
                        {
                            lastLeftPos = false;
                            str         = str + ch;
                            if (ch == "1")
                            {
                                nextRight = true;
                            }
                        }
                        count++;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            int _s;
            if (count <= 5)
            {
                if (scoreDic.TryGetValue(str, out _s))
                {
                    score += _s;
                }
            }
            else if (count <= 6)
            {
                if (scoreDic.TryGetValue(str, out _s))
                {
                    score += _s;
                }
                else
                {
                    str = str.Substring(lastLeftPos ? 0 : 1, 5);
                    if (scoreDic.TryGetValue(str, out _s))
                    {
                        score += _s;
                    }
                }
            }
        }


        return(score);
    }
Ejemplo n.º 2
0
    public virtual int SetCheckScore(int x, int y, ChessType chessType)
    {
        Vector2Int inputPos = new Vector2Int(x, y);
        int        score    = 0;

        for (int md = 0; md < 4; md++)
        {
            ChessBoardManager.MoveDir _moveDir = (ChessBoardManager.MoveDir)md;
            string str = "1";
            int    xDir = 0, yDir = 0;
            switch (_moveDir)
            {
            case ChessBoardManager.MoveDir.TransverseLine:
                xDir = 1; yDir = 0;
                break;

            case ChessBoardManager.MoveDir.VerticalLine:
                xDir = 0; yDir = 1;
                break;

            case ChessBoardManager.MoveDir.LeftSlantLine:
                xDir = 1; yDir = -1;
                break;

            case ChessBoardManager.MoveDir.RightSlantLine:
                xDir = 1; yDir = 1;
                break;

            default:
                break;
            }

            for (int dir = -1; dir <= 1; dir += 2)
            {
                for (int i = 1; i < chessMaxBoard; i++)
                {
                    Vector2Int newPoint = new Vector2Int(inputPos.x + dir * xDir * i, inputPos.y + dir * yDir * i);
                    if (chessBoardManager.CheckBorder(newPoint))
                    {
                        string ch;
                        if (chessBoardManager.GridArray[newPoint.x, newPoint.y] == chessType)
                        {
                            ch = "1";
                        }
                        else if (chessBoardManager.GridArray[newPoint.x, newPoint.y] == ChessType.None)
                        {
                            ch = "0";
                        }
                        else
                        {
                            break;
                        }
                        if (dir < 0)
                        {
                            str = ch + str;
                        }
                        else if (dir > 0)
                        {
                            str = str + ch;
                        }
                        if (ch == "0")
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            int _s;
            if (scoreDic.TryGetValue(str, out _s))
            {
                score += _s;
            }
        }


        return(score);
    }