Beispiel #1
0
        public bool IsPositionOk(Vector2Int pos, FindPositionType type)
        {
            switch (type)
            {
            case FindPositionType.IN_BOARD:
                if (pos.x >= xMin && pos.x < xMax && pos.y >= yMin && pos.y < yMax)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case FindPositionType.OUT_BOARD:
                if (!(pos.x >= xMin && pos.x < xMax && pos.y >= yMin && pos.y < yMax))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(true);
            }
        }
Beispiel #2
0
        public Vector2Int FindNearestEmptyPosition(int x, int y, FindPositionType type = FindPositionType.ANY)
        {
            Queue <Vector2Int> queue = new Queue <Vector2Int> ();

            queue.Enqueue(new Vector2Int(x, y));
            while (queue.Count > 0)
            {
                Vector2Int now = queue.Dequeue();
                if (!IsChessOnPosition(now.x, now.y) && IsPositionOk(now, type))
                {
                    return(new Vector2Int(now.x, now.y));
                }
                foreach (Vector2Int go in goArr)
                {
                    Vector2Int next = now + go;
                    if (!queue.Contains(next))
                    {
                        queue.Enqueue(next);
                    }
                }
            }
            return(new Vector2Int()); //不懂怎样返回null
        }