/// <summary>
    /// 스폰 위치에서 블록을 생성합니다.
    /// </summary>
    /// <param name="blockPrefab">복제할 프리팹</param>
    /// <param name="coords">좌표</param>
    private Block SpawnRandomBlock()
    {
        var randPrefab = prefabs[UnityEngine.Random.Range(0, prefabs.Count)];

        if (randPrefab.type == BlockType.Top)
        {
            if (remainTopCount > 0)
            {
                remainTopCount--;
            }
            else
            {
                return(SpawnRandomBlock());
            }
        }

        Vector2Int spawnCoords = new Vector2Int(Global.MAX_SIZE.x / 2, Global.MAX_SIZE.y - 1);

        if (blocks.Exists(x => x.coords == spawnCoords))
        {
            throw new Exception("같은 위치에 블록이 있음");
        }

        var block = Instantiate(randPrefab);

        block.coords = spawnCoords;
        block.transform.SetParent(transform, false);
        block.transform.position = BoardUtil.GetPosition(spawnCoords) + new Vector3(0f, 3f, 0f);
        block.ToGoal(BoardUtil.GetPosition(spawnCoords), Global.BLOCK_DROP_SPEED);
        blocks.Add(block);
        return(block);
    }
Exemplo n.º 2
0
        void initBoards()
        {
            var children = new List <Image>();

            for (int i = 0; i < transform.childCount; i++)
            {
                children.Add(transform.GetChild(i).GetComponent <Image>());
            }
            children.Sort((a, b) => getOrder(a.name) - getOrder(b.name));
            int index = 0;

            foreach (var child in children)
            {
                if (child.transform.parent != transform)
                {
                    continue;
                }
                if (index % numOfEdge == 0)
                {
                    _boards.Add(new List <Image>());
                    _colors.Add(new List <Color>());
                }
                _boards[index / numOfEdge].Add(child);
                _colors[index / numOfEdge].Add(child.color);
                index++;
            }

            _boards = BoardUtil.switchXY(BoardUtil.flipY(_boards));
            _colors = BoardUtil.switchXY(BoardUtil.flipY(_colors));
        }
Exemplo n.º 3
0
    private void ShowActionPreview()
    {
        if (Preview == null)
        {
            return;
        }

        if (selectedAction == null || !MouseIsOverMap)
        {
            Preview.Hide();
            return;
        }

        var tileCoord = BoardUtil.GetHoveredTile();
        var tile      = GameWorld.GetTile(tileCoord.x, tileCoord.y);

        if (tile == null)
        {
            Preview.Hide();
            return;
        }

        var previewData = selectedAction.PreviewData(tile);

        Preview.Show(previewData);
    }
Exemplo n.º 4
0
 public void ChangeCoordsAndMove(Vector2Int targetCoords, float speed)
 {
     if (coords.x == targetCoords.x)
     {
         //직선이동
         var pos = BoardUtil.GetPosition(targetCoords);
         ToGoal(pos, speed);
     }
     else
     {
         //곡선이동
         var     mover = GetComponent <Mover>();
         Vector3 via   = GetVia(coords, targetCoords);
         var     des   = new List <Vector3>();
         if (mover.IsMoving())
         {
             des.Add(mover.destination);
         }
         des.Add(via);
         des.Add(BoardUtil.GetPosition(targetCoords));
         mover.speed = speed;
         mover.ToGoal(des);
     }
     coords = targetCoords;
 }
Exemplo n.º 5
0
    IEnumerator CoWaitDrag(Vector3 initPos)
    {
        isReady = false;
        while (true)
        {
            if (Input.GetMouseButtonUp(0))
            {
                break;
            }
            var   mousePos = InputEx.GetMouseWorld();
            float distance = Vector3.Distance(initPos, mousePos);
            if (distance > Global.DRAG_DISTANCE)
            {
                //드래그 완료
                Direction dir         = BoardUtil.GetDirection(initPos, mousePos);
                Block     changeBlock = BlockManager.instance.GetNeighbor(selectBlock, dir);
                if (changeBlock == null)
                {
                    break;
                }
                //블록 스왑
                yield return(StartCoroutine(BlockManager.instance.CoSwapBlock(selectBlock, changeBlock)));

                var selectInfos = MatchManager.instance.Check(selectBlock);
                var targetInfos = MatchManager.instance.Check(changeBlock);
                curMatchInfos = MatchUtil.Distinct(selectInfos.Union(targetInfos).ToList());
                //스왑 실패 (Undo)
                if (curMatchInfos.Count == 0)
                {
                    Debug.Log("Swap Fail");
                    yield return(StartCoroutine(BlockManager.instance.CoUndoSwap()));

                    break;
                }
                //중력 적용 후 맵 생성 (추가 Match가 없을때까지 반복)
                while (true)
                {
                    if (curMatchInfos.Count == 0)
                    {
                        break;
                    }
                    BlockManager.instance.DestoryBlocks(MatchUtil.GetCoordsAll(curMatchInfos));
                    yield return(StartCoroutine(BlockManager.instance.CoApplyGravityAndGenerateMap()));

                    curMatchInfos = MatchManager.instance.CheckAll();
                }
                break;
            }
            yield return(null);
        }
        if (BlockManager.instance.totalTopCount == 0)
        {
            Debug.Log("Win!");
        }

        //초기화
        selectBlock = null;
        isReady     = true;
    }
Exemplo n.º 6
0
        public void test_position_after_move_right()
        {
            var expected = new BoardPosition(0, 0);
            var actual   = BoardUtil.GetNewBoardPosition(new BoardPosition(0, 0), MoveDirection.Right);

            Assert.AreEqual(expected.X + 1, actual.X);
            Assert.AreEqual(expected.Y, actual.Y);
        }
Exemplo n.º 7
0
        public void test_position_after_move_down()
        {
            var expected = new BoardPosition(0, 0);
            var actual   = BoardUtil.GetNewBoardPosition(new BoardPosition(0, 0), MoveDirection.Down);

            Assert.AreEqual(expected.X, actual.X);
            Assert.AreEqual(expected.Y - 1, actual.Y);
        }
    private Board CreateBoard(Vector2Int coords)
    {
        var board = Instantiate(boardPrefab);

        board.coords = coords;
        board.transform.SetParent(transform, false);
        board.transform.position = BoardUtil.GetPosition(board.coords);
        return(board);
    }
Exemplo n.º 9
0
    public Block FindFillBlock()
    {
        //위쪽방향 우선 찾기
        var        nextCoords  = coords;
        Vector2Int maxUpCoords = coords;

        while (true)
        {
            nextCoords = BoardUtil.GetNeighbor(nextCoords, Direction.Up);
            if (!BoardManager.instance.IsEnable(nextCoords))
            {
                maxUpCoords = BoardUtil.GetNeighbor(nextCoords, Direction.Down);
                break;
            }
            var nextBlock = BlockManager.instance.GetBlock(nextCoords);
            if (nextBlock != null)
            {
                return(nextBlock);
            }
        }
        int centerX = Global.MAX_SIZE.x / 2;

        if (coords.x == centerX)
        {
            return(null);
        }
        if (coords.x < centerX)
        {
            nextCoords = maxUpCoords;
            for (int i = 0; i < centerX - coords.x; i++)
            {
                nextCoords = BoardUtil.GetNeighbor(nextCoords, Direction.RightUp);
                var nextBlock = BlockManager.instance.GetBlock(nextCoords);
                if (nextBlock != null)
                {
                    return(nextBlock);
                }
            }
            return(null);
        }
        else
        {
            nextCoords = maxUpCoords;
            for (int i = 0; i < coords.x - centerX; i++)
            {
                nextCoords = BoardUtil.GetNeighbor(nextCoords, Direction.LeftUp);
                var nextBlock = BlockManager.instance.GetBlock(nextCoords);
                if (nextBlock != null)
                {
                    return(nextBlock);
                }
            }
            return(null);
        }
    }
Exemplo n.º 10
0
        protected List <string> GetSyllableList(string[] Cells, int size, bool fetchAll, bool filterEdges, bool asGroups)
        {
            List <string> List = new List <string>();

            for (int index = 0; index < Cells.Length; index++)
            {
                string cell = Cells[index];
                if (cell == "")
                {
                    continue;
                }
                Neighbor Neighbor = BoardUtil.FindNeighbors(index, size);

                string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : "";
                string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : "";
                string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : "";
                string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : "";

                if (!fetchAll)
                {
                    if ((r != "" || l != "") && (t != "" || b != ""))
                    {
                        if (!filterEdges)
                        {
                            string x = asGroups ? cell : "(" + cell + ")";
                            if (!List.Contains(x))
                            {
                                List.Add(x);
                            }
                        }
                    }
                    else
                    {
                        if (filterEdges)
                        {
                            string x = asGroups ? cell : "(" + cell + ")";
                            if (!List.Contains(x))
                            {
                                List.Add(x);
                            }
                        }
                    }
                }
                else
                {
                    string x = asGroups ? cell : "(" + cell + ")";
                    if (!List.Contains(x))
                    {
                        List.Add(x);
                    }
                }
            }
            return(List);
        }
Exemplo n.º 11
0
        static int GetStartIndex(string option, int r, int pos, int size, int move)
        {
            switch (option)
            {
            case "R":
                return(BoardUtil.Abs(r, pos - move, size));

            case "C":
                return(BoardUtil.Abs(pos - move, r, size));
            }
            return(-1);
        }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        var   board = new GameObject("Board");
        float minx = float.MaxValue, miny = float.MaxValue, maxx = float.MinValue, maxy = float.MinValue;

        for (int cur = 0; cur < Walls.Length; ++cur)
        {
            int next = (cur + 1) % Walls.Length;

            BoardUtil.CreateWall(Walls[cur], Walls[next], board, Material);
        }

        BoardUtil.CreateFloor(Walls, board, Material, PhysicMaterial);
    }
Exemplo n.º 13
0
        protected void checkStaleMate()
        {
            _staleMate = true;
            var posFuncs = new List <BoardUtil.PosFunc>()
            {
                checkPos
            };

            BoardUtil.functionToEachPos(posFuncs, Info.Board);
            if (_staleMate)
            {
                endGame(true);
            }
        }
Exemplo n.º 14
0
    private Vector3 GetVia(Vector2Int startCoords, Vector2Int targetCoords)
    {
        var       coords = startCoords;
        int       count  = Mathf.Abs(targetCoords.x - startCoords.x);
        Direction dir    = Direction.LeftDown;

        if (startCoords.x < targetCoords.x)
        {
            dir = Direction.RightDown;
        }
        for (int i = 0; i < count; i++)
        {
            coords = BoardUtil.GetNeighbor(coords, dir);
        }
        return(BoardUtil.GetPosition(coords));
    }
Exemplo n.º 15
0
    public static Vector2Int GetHoveredTile()
    {
        var camera = Camera.main;
        var ray    = camera.ScreenPointToRay(Input.mousePosition);
        var plane  = new Plane(Vector3.back, Vector3.zero);

        if (plane.Raycast(ray, out float dist))
        {
            var point3D = ray.GetPoint(dist);
            return(BoardUtil.Position3DToTileCoord(point3D));
        }
        else
        {
            return(new Vector2Int(99999, 99999));
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// 해당 좌표에 블록을 즉시 생성합니다.
    /// </summary>
    /// <param name="blockPrefab">복제할 프리팹</param>
    /// <param name="coords">좌표</param>
    private Block CreateBlock(Block blockPrefab, Vector2Int coords)
    {
        if (!BoardManager.instance.IsEnable(coords))
        {
            throw new Exception("유효범위 초과");
        }
        if (blocks.Exists(x => x.coords == coords))
        {
            throw new Exception("같은 위치에 블록이 있음");
        }

        var block = Instantiate(blockPrefab);

        block.coords = coords;
        block.transform.SetParent(transform, false);
        block.transform.position = BoardUtil.GetPosition(block.coords);
        blocks.Add(block);
        return(block);
    }
Exemplo n.º 17
0
        public override List <BoardVector> getMovablePos(GameInfo info, BoardVector piecePos)
        {
            var  piece          = info.Board.getPiece(piecePos);
            bool useModMoveInfo = false;

            List <MoveInfo> movableInfo = new List <MoveInfo>();

            if (piece.hasAttribute <StayHomeAttribute>())
            {
                var stayHomeAttr = piece.getAttribute <StayHomeAttribute>();
                if (stayHomeAttr.IsStayHome)
                {
                    movableInfo    = stayHomeAttr.getStayHomeMoveInfo();
                    useModMoveInfo = true;
                }
            }

            if (!useModMoveInfo && piece.hasAttribute <CoVidAttribute>())
            {
                var coVidAttr = piece.getAttribute <CoVidAttribute>();
                if (coVidAttr.useModifiedMoveInfo())
                {
                    movableInfo    = coVidAttr.getModifiedMoveInfo();
                    useModMoveInfo = true;
                }
            }

            if (useModMoveInfo)
            {
                var id         = piece.getOwner().getId();
                var dir        = info.getPlayer(id).FrontDirection;
                var allMovable = new List <BoardVector>();
                foreach (var moveInfo in movableInfo)
                {
                    allMovable.AddRange(BoardUtil.getInfoPos(moveInfo, dir, piecePos, info.Board, id));
                }

                return(allMovable);
            }

            return(base.getMovablePos(info, piecePos));
        }
Exemplo n.º 18
0
        protected static List <Word> GetSyllableList2(string[] Cells, int size, bool filter, bool free)
        {
            List <Word> List = new List <Word>();

            for (int index = 0; index < Cells.Length; index++)
            {
                string cell = Cells[index];
                if (cell == "")
                {
                    continue;
                }
                var Neighbor = BoardUtil.FindNeighbors(index, size);

                string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : "";
                string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : "";
                string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : "";
                string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : "";

                if (filter)
                {
                    if ((r != "" || l != "") && (t != "" || b != ""))
                    {
                    }
                    else
                    {
                        string x = free ? cell : "(" + cell + ")";

                        List.Add(new Word {
                            Tiles = x, Index = index
                        });
                    }
                }
                else
                {
                    string x = free ? cell : "(" + cell + ")";
                    List.Add(new Word {
                        Tiles = x, Index = index
                    });
                }
            }
            return(List);
        }
Exemplo n.º 19
0
        private void DisplayData()
        {
            // 메서드 실행 후 그 결과값을 ReplyEntity 엔터티 개체에 담기
            ReplyEntity re = (new ReplyBiz()).SelectReplyByNum(Convert.ToInt32(Request["Num"]));

            // 각각의 컨트롤에 바인딩
            lblNum.Text      = Request["Num"];
            lblTitle.Text    = re.Title;
            lblName.Text     = re.Name;
            lblEmail.Text    = re.Email;
            lblHomepage.Text = re.Homepage;
            lblPostDate.Text = re.PostDate.ToString();

            // 수정되었을 때에만, 해당 날짜 기록
            if (re.ModifyDate != DateTime.MinValue)
            {
                lblModifyDate.Text = re.ModifyDate.ToString();
            }

            lblReadCount.Text = re.ReadCount.ToString();
            lblPostIP.Text    = re.PostIP;

            #region 인코딩 방식에 따른 컨텐츠 출력
            lblContent.Text =
                BoardUtil.ConvertContentByEncoding(re.Content, re.Encoding);
            //if (re.Encoding == "Text") // 태그 실행 방지/소스 그대로
            //{
            //    lblContent.Text =
            //        re.Content.Replace("&", "&amp;").Replace(
            //                "<", "&lt;").Replace(">", "&gt;").Replace(
            //                        "\r\n", "<br />").Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
            //}
            //else if (re.Encoding == "Mixed") // 태그 실행
            //{
            //    lblContent.Text = re.Content.Replace("\r\n", "<br />");
            //}
            //else // HTML로 표시
            //{
            //    lblContent.Text = re.Content;
            //}
            #endregion
        }
Exemplo n.º 20
0
    public IEnumerator CoSwapBlock(Block blockA, Block blockB)
    {
        if (blockA.coords == blockB.coords)
        {
            throw new Exception("같은 블록 지정 불가");
        }
        Debug.Log($"Swap ({blockA.coords} , {blockB.coords})");
        backUpBlock[0] = blockA;
        backUpBlock[1] = blockB;
        //이동
        blockA.ToGoal(BoardUtil.GetPosition(blockB.coords), Global.BLOCK_SWAP_SPEED);
        blockB.ToGoal(BoardUtil.GetPosition(blockA.coords), Global.BLOCK_SWAP_SPEED);
        yield return(new WaitUntil(() => !blockA.IsMoving() && !blockB.IsMoving()));

        //실제 좌표변경
        Vector2Int temp = blockA.coords;

        blockA.coords = blockB.coords;
        blockB.coords = temp;
    }
Exemplo n.º 21
0
        protected override void turnEnded()
        {
            if (getTurn() % intervalInfluence == 0)
            {
                foreach (var id in _unInfluencedPoses.Keys)
                {
                    var player = Info.getPlayer(id);
                    if (player.isLoser())
                    {
                        continue;
                    }

                    _unInfluencedPoses[id].Clear();
                }
            }

            BoardUtil.functionToEachPos(new List <BoardUtil.PosFunc> {
                placeProcess
            }, Info.Board);

            if (getTurn() % intervalInfluence == 0)
            {
                foreach (var id in _unInfluencedPoses.Keys)
                {
                    if (_unInfluencedPoses[id].Count > 0)
                    {
                        var rand = Random.Range(0, _unInfluencedPoses[id].Count);
                        Info.Board.getPiece(_unInfluencedPoses[id][rand]).getAttribute <CoVidAttribute>().influenced(getTurn());
                    }
                }
            }

            Info.checkLoser();
            if (Info.getRemainPlayerNum() <= 1)
            {
                endGame();
            }
        }
Exemplo n.º 22
0
    /// <summary>
    /// 장애물을 제거합니다.
    /// </summary>
    private void TryDestroyObstacle(List <Vector2Int> targetCoords)
    {
        var obstacles = new List <IObstacle>();

        foreach (var targetCoord in targetCoords)
        {
            foreach (var coords in BoardUtil.GetNeighborAll(targetCoord))
            {
                var block = GetBlock(coords);
                if (block != null && block is IObstacle)
                {
                    var obstacle = block as IObstacle;
                    if (!obstacles.Exists(x => x == obstacle))
                    {
                        obstacles.Add(obstacle);
                    }
                }
            }
        }
        foreach (var obstacle in obstacles)
        {
            (obstacle as Block).TryDestroy();
        }
    }
Exemplo n.º 23
0
        protected static ProbableMove TryHarizontal(int Mode, int Star, string[] Cells, int size, int Index, int offset, string[] Pre, string[] Centers, string[] Post)
        {
            List <Word> Moves     = new List <Word>();
            int         PreCount  = Pre.Length;
            int         PostCount = Post.Length;

            string[]   NewCells = (string[])Cells.Clone();
            List <int> Impacted = new List <int>();

            if (Pre.Length != 0)
            {
                for (int x = Pre.Length - 1; x >= 0; x--)
                {
                    Neighbor n = BoardUtil.FindNeighbors(Index - x, size);
                    if (n.Left != -1)
                    {
                        NewCells[n.Left] += Pre[x];
                        Impacted.Add(n.Left);
                        if (Pre[x] == null)
                        {
                            continue;
                        }
                        Moves.Add(new Word {
                            Tiles = Pre[x], Index = n.Left
                        });
                    }
                    else
                    {
                        return(new ProbableMove {
                            Words = new List <ProbableWord>(), Direction = "H", Moves = new List <Word>()
                        });
                    }
                }
            }
            if (Centers.Length != 0)
            {
                for (int c = 0; c < Centers.Length; c++)
                {
                    int cellIndex = Index + c;
                    if (cellIndex == -1 || Centers[c] == "")
                    {
                        continue;
                    }

                    NewCells[cellIndex] += Centers[c];
                    Impacted.Add(cellIndex);
                    if (Centers[c] == null)
                    {
                        continue;
                    }
                    Moves.Add(new Word {
                        Tiles = Centers[c], Index = cellIndex
                    });
                }
            }

            if (Post.Length != 0)
            {
                for (int x = 0; x < Post.Length; x++)
                {
                    Neighbor n = BoardUtil.FindNeighbors(Index + offset + x, size);
                    if (n.Right != -1)
                    {
                        NewCells[n.Right] += Post[x];
                        Impacted.Add(n.Right);
                        if (Post[x] == null)
                        {
                            continue;
                        }
                        Moves.Add(new Word {
                            Tiles = Post[x], Index = n.Right
                        });
                    }
                    else
                    {
                        return(new ProbableMove {
                            Words = new List <ProbableWord>(), Direction = "H", Moves = new List <Word>()
                        });
                    }
                }
            }
            List <ProbableWord> W = new List <ProbableWord>();

            if (Star < 0 || (Star >= 0 && NewCells[Star].Trim() != ""))
            {
                foreach (int index in Impacted)
                {
                    W.AddRange(WordsAt(NewCells, size, index));
                }
            }
            return(new ProbableMove {
                Mode = Mode, Words = W, Moves = Moves, Direction = "H"
            });
        }
Exemplo n.º 24
0
 public Board NextBoard(Board board, Direction dir)
 {
     return(boards.Find(x => x.coords == BoardUtil.GetNeighbor(board.coords, dir)));
 }
Exemplo n.º 25
0
        static List <ProbableWord> WordsAt(string[] Cells, int size, int index)
        {
            List <ProbableWord> List     = new List <ProbableWord>();
            Neighbor            Neighbor = BoardUtil.FindNeighbors(index, size);

            string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : "";
            string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : "";
            string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : "";
            string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : "";

            List <Word> Lefties  = new List <Word>();
            List <Word> Righties = new List <Word>();

            if (r != "")
            {
                //Move Right..
                Righties.Add(new Word {
                    Tiles = r, Index = Neighbor.Right
                });
                int  index_ = Neighbor.Right;
                bool flg    = true;
                while (flg)
                {
                    Neighbor n  = BoardUtil.FindNeighbors(index_, size);
                    string   r_ = n.Right != -1 ? Cells[n.Right] : "";
                    if (r_ == "")
                    {
                        flg = false;
                        break;
                    }
                    Righties.Add(new Word {
                        Tiles = r_, Index = n.Right
                    });
                    index_ = n.Right;
                }
            }
            if (l != "")
            {
                //Move Left..
                Lefties.Add(new Word {
                    Tiles = l, Index = Neighbor.Left
                });

                int  index_ = Neighbor.Left;
                bool flg    = true;
                while (flg)
                {
                    Neighbor n  = BoardUtil.FindNeighbors(index_, size);
                    string   l_ = n.Left != -1 ? Cells[n.Left] : "";
                    if (l_ == "")
                    {
                        flg = false;
                        break;
                    }
                    Lefties.Add(new Word {
                        Tiles = l_, Index = n.Left
                    });
                    index_ = n.Left;
                }
            }

            List <Word> Topies  = new List <Word>();
            List <Word> Downies = new List <Word>();

            if (t != "")
            {
                //Move Top..
                Topies.Add(new Word {
                    Tiles = t, Index = Neighbor.Top
                });
                int  index_ = Neighbor.Top;
                bool flg    = true;
                while (flg)
                {
                    Neighbor n  = BoardUtil.FindNeighbors(index_, size);
                    string   t_ = n.Top != -1 ? Cells[n.Top] : "";
                    if (t_ == "")
                    {
                        flg = false;
                        break;
                    }
                    Topies.Add(new Word {
                        Tiles = t_, Index = n.Top
                    });
                    index_ = n.Top;
                }
            }

            if (b != "")
            {
                //Move Bottom..
                Downies.Add(new Word {
                    Tiles = b, Index = Neighbor.Bottom
                });
                int  index_ = Neighbor.Bottom;
                bool flg    = true;
                while (flg)
                {
                    Neighbor n  = BoardUtil.FindNeighbors(index_, size);
                    string   d_ = n.Bottom != -1 ? Cells[n.Bottom] : "";
                    if (d_ == "")
                    {
                        flg = false;
                        break;
                    }
                    Downies.Add(new Word {
                        Tiles = d_, Index = n.Bottom
                    });
                    index_ = n.Bottom;
                }
            }

            Topies.Reverse();
            Lefties.Reverse();

            if (Topies.Count + Downies.Count > 0)
            {
                ProbableWord Vertical = MakeAWord(Topies, new Word {
                    Tiles = Cells[index], Index = index
                }, Downies);
                List.Add(Vertical);
            }
            if (Lefties.Count + Righties.Count > 0)
            {
                ProbableWord Harizontal = MakeAWord(Lefties, new Word {
                    Tiles = Cells[index], Index = index
                }, Righties);
                List.Add(Harizontal);
            }
            return(List);
        }
Exemplo n.º 26
0
        public void test_chess_notation(int column, int row, string expected)
        {
            var actual = BoardUtil.GetChessNotation(new BoardPosition(column, row));

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 27
0
 public IEnumerable <Block> GetNeighborAll(Block origin)
 {
     return(BoardUtil.GetNeighborAll(origin.coords).Select(x => GetBlock(x)).Where(x => x != null));
 }
Exemplo n.º 28
0
 public Block GetNeighbor(Block origin, Direction dir)
 {
     return(blocks.Find(x => x.coords == BoardUtil.GetNeighbor(origin.coords, dir)));
 }
Exemplo n.º 29
0
 public Block GetNeighbor(Vector2Int coords, Direction dir)
 {
     return(blocks.Find(x => x.coords == BoardUtil.GetNeighbor(coords, dir)));
 }
Exemplo n.º 30
0
        static List <Word> GetWords(string[] Cells, string option, int r, int size, bool includeDuplicates)
        {
            List <Word> Words   = new List <Word>();
            var         pending = "";
            var         cnt     = 0;

            for (var i = 0; i < size; i++)
            {
                var index = -1;
                switch (option)
                {
                case "R":
                    index = BoardUtil.Abs(r, i, size);
                    break;

                case "C":
                    index = BoardUtil.Abs(i, r, size);
                    break;
                }
                var cell = Cells[index];
                if (cell != "")
                {
                    pending += "(" + cell + ")|";
                    cnt++;
                    continue;
                }
                if (pending != "" && cell == "")
                {
                    if (cnt > 1)
                    {
                        var word = pending.TrimEnd('|');
                        if (includeDuplicates)
                        {
                            int startIndex = GetStartIndex(option, r, i, size, cnt);
                            Words.Add(new Word {
                                Tiles = word, Syllables = cnt, Position = option, Index = startIndex
                            });
                        }
                        else
                        {
                            Word X = Words.Find(x => x.Tiles == word);
                            if (X == null)
                            {
                                int startIndex = GetStartIndex(option, r, i, size, cnt);
                                Words.Add(new Word {
                                    Tiles = word, Syllables = cnt, Position = option, Index = startIndex
                                });
                            }
                        }
                    }
                    pending = "";
                    cnt     = 0;
                    continue;
                }
            }
            if (cnt > 1)
            {
                var word = pending.TrimEnd('|');
                if (includeDuplicates)
                {
                    int startIndex = GetStartIndex(option, r, size, size, cnt);
                    Words.Add(new Word {
                        Tiles = word, Syllables = cnt, Position = option, Index = startIndex
                    });
                }
                else
                {
                    Word X = Words.Find(x => x.Tiles == word);
                    if (X == null)
                    {
                        int startIndex = GetStartIndex(option, r, size, size, cnt);
                        Words.Add(new Word {
                            Tiles = word, Syllables = cnt, Position = option, Index = startIndex
                        });
                    }
                }
            }
            return(Words);
        }