Example #1
0
File: Solver.cs Project: MOAAS/IART
        private int GetNumUsedTiles(int[] valueTile, int[] finishTile, Boolean alignedVertically)
        {
            int numUsedTiles = 0;

            Func <Coords, Coords> moveFunction;

            if (alignedVertically)
            {
                if (valueTile[1] > finishTile[1])
                {
                    moveFunction = Coords.MoveUp;
                }
                else
                {
                    moveFunction = Coords.MoveDown;
                }
            }
            else
            {
                if (valueTile[0] < finishTile[0])
                {
                    moveFunction = Coords.MoveRight;
                }
                else
                {
                    moveFunction = Coords.MoveLeft;
                }
            }

            Coords coords    = moveFunction(new Coords(valueTile[0], valueTile[1]));
            int    tileValue = board.TileValue(coords);

            while (tileValue != ZhedBoard.FINISH_TILE)
            {
                if (tileValue == ZhedBoard.USED_TILE)
                {
                    numUsedTiles++;
                    Console.WriteLine("Num used tiles: {0}", numUsedTiles);
                }

                coords    = moveFunction(coords);
                tileValue = board.TileValue(coords);
            }

            if (numUsedTiles != 0)
            {
                Console.WriteLine("Num used tiles: {0}", numUsedTiles);
            }

            return(numUsedTiles);
        }
Example #2
0
        public static ZhedBoard SpreadTile(ZhedBoard board, Coords coords, Func <Coords, Coords> moveFunction)
        {
            int tileValue = board.TileValue(coords);

            if (tileValue <= 0)
            {
                return(board);
            }

            ZhedBoard newBoard = new ZhedBoard(board);

            newBoard.SetTile(coords, USED_TILE);
            newBoard.boardValue += 2 * tileValue;
            newBoard.UpdateValueTiles(coords);
            while (tileValue > 0)
            {
                coords = moveFunction(coords);
                if (!newBoard.inbounds(coords))
                {
                    break;
                }

                switch (newBoard.TileValue(coords))
                {
                case EMPTY_TILE: newBoard.SetTile(coords, USED_TILE);  tileValue--; break;

                case FINISH_TILE: newBoard.SetTile(coords, WINNER_TILE); newBoard.isOver = true; break;

                default: break;
                }
            }

            return(newBoard);
        }