tomaztsql posted: " What is 2048 game? It is a classical puzzle game, that is easy and fun to play. The objective of the game is to move the numbers (tiles in the matrix/board) in a way to combine them to create a tile with the number 2048. Install the game Go to "
What is 2048 game? It is a classical puzzle game, that is easy and fun to play. The objective of the game is to move the numbers (tiles in the matrix/board) in a way to combine them to create a tile with the number 2048.
You will need to create a board of desired size (e.g.: 4x4):
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- CREATE MATRIX (board) for @dim dimension -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE OR ALTER PROCEDURE dbo.CREATE_matrix @dim INT AS BEGIN DECLARE @i INT = 1 DECLARE @j INT = 1 DECLARE @TableCreate NVARCHAR(2000) = 'DROP TABLE IF EXISTS dbo.T_2048; CREATE TABLE dbo.T_2048 (ID INT IDENTITY(1,1), ' WHILE (@dim >= @i) BEGIN SET @TableCreate = @TableCreate + 'V' + CAST(@i AS VARCHAR(10)) + ' SMALLINT ,' SET @i = @i + 1 END SET @TableCreate = STUFF(@TableCreate, LEN(@TableCreate), 1, ');') WHILE (@dim >= @j) BEGIN SET @TableCreate = @TableCreate + ' INSERT INTO dbo.T_2048 VALUES (' + STUFF(REPLICATE('0,',@dim), LEN(REPLICATE('0,',@dim)), 1, ');') SET @j = @j+1 END EXEC sp_executesql @tableCreate END; GO
The next step is to create a procedure that will add a new number (number 2) into empty tile:
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ADD NUMBER (board) for @dim dimension -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE OR ALTER PROCEDURE dbo.ADD_number @dim INT AS BEGIN DECLARE @nofTry INT = 10*@dim DECLARE @i INT = 1 WHILE @nofTry > @i BEGIN declare @a int = 1 declare @b int = @dim declare @x int, @y int = 1 SET @x = (SELECT FLOOR(RAND()*(@b-@a+1))+@a) SET @y = (SELECT FLOOR(RAND()*(@b-@a+1))+@a) DECLARE @COL NVARCHAR(100) = ( SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'T_2048' AND TABLE_SCHEMA = 'dbo' AND ORDINAL_POSITION = @x+1 ) --- CHECK if 0 DECLARE @check0 NVARCHAR(1000) = 'SELECT ' +@COL+ ' FROM dbo.T_2048 WHERE ID =' + CAST(@y AS varchar(10)) PRINT @check0 DECLARE @temp TABLE (RES INt) INSERT INTO @temp EXEC sp_executesql @check0 IF (SELECT res FROM @temp) = 0 BEGIN SET @i = @nofTry DECLARE @Sq NVARCHAR(2000) = 'UPDATE dbo.T_2048 SET ' + CAST(@COL AS VARCHAR(100)) + ' = CASE WHEN ' + CAST(@COL AS VARCHAR(100)) + ' = 0 THEN 2 ELSE ' + CAST(@COL AS VARCHAR(100)) + ' END WHERE ID = '+CAST(@y AS VARCHAR(100)) EXEC sp_executesql @Sq --RETURN; END SET @i = @i + 1 END END; GO
Move around the board
Once the board is created, you will need to control the moves. Four procedures that will calculate moves in all four directions are needed (UP, DOWN, LEFT, RIGHT). For the sake of brevity, I am adding only one direction:
---- -------------------------- ---- -------------------------- ---- MOVE UP Procedure ---- -------------------------- ---- -------------------------- CREATE OR ALTER PROCEDURE dbo.MOVE_up @dim INT AS BEGIN DECLARE @Column_counter INT = 2 Declare @max_column INT = (SELECT @dim /* dim */ + 2) while @max_column > @Column_counter BEGIN -- Get first column name DECLARE @col_name VARCHAR(10) = (SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'T_2048' and ORDINAL_POSITION = @Column_counter) print @col_name DECLARE @sql1 NVARCHAR(2000) = 'SELECT id, ' + @col_name + ' as v FROM T_2048' DROP TABLE IF EXISTS #temp; create table #temp (id int, v int) insert into #temp EXEC sp_executesql @sql1 --------------------------------------- -- UP scenarij DECLARE @ii int = 1 while @dim-1 >= @ii -- nof dimensions BEGIN declare @i int = 1 while @dim > @i -- --declare @i int = 1 begin declare @vv_1 int = (select v from #temp where id = @i) declare @vv_2 int = (select v from #temp where id = @i+1) IF (@vv_1 = 0 AND @vv_2 <> 0) BEGIN update #temp set v = @vv_2 where id = @i update #temp set v = 0 where id = @i+1 END IF (@vv_1 <> 0 AND @vv_1 = @vv_2) BEGIN update #temp set v = @vv_1 + @vv_2 where id = @i update #temp set v = 0 where id = @i+1 END IF (@vv_1 <> 0 AND @vv_2 = 0) BEGIN Print 'Do nothing' END set @i = @i + 1 end set @ii = @ii + 1 END -- update back to T_2048 table from #temp table DECLARE @sql_temp_update NVARCHAR(500) SET @SQL_temp_update = 'UPDATE T20 SET '+@col_name+' = t.v FROM t_2048 AS T20 JOIN #temp AS t ON T20.id = t.id' EXEC sp_executesql @SQL_temp_update SET @Column_counter = @Column_counter + 1 END END; GO
And the last procedure is the main procedure that will combine all the moves and adding new numbers:
CREATE OR ALTER PROCEDURE dbo.PLAY_game @move CHAR(1) -- U, D, L, R (Up, Down, Left, Right) ,@dim INT -- size of the matrix AS BEGIN IF @move = 'U' BEGIN EXEC dbo.MOVE_up @dim; EXEC [dbo].[ADD_number] @dim; SELECT * FROM T_2048 END IF @move = 'D' BEGIN EXEC dbo.MOVE_down @dim; EXEC [dbo].[ADD_number] @dim; SELECT * FROM T_2048 END IF @move = 'L' BEGIN EXEC dbo.MOVE_left @dim; EXEC [dbo].[ADD_number] @dim; SELECT * FROM T_2048 END IF @move = 'R' BEGIN EXEC dbo.MOVE_right @dim; EXEC [dbo].[ADD_number] @dim; SELECT * FROM T_2048 END END; GO
Now that you are all set, let's start the game.
Start the game
If you want to play 4x4 board, you will need to create a bord and add two numbers that will be placed at the random position. This can be done with:
EXEC [dbo].[CREATE_matrix] 4; GO EXEC [dbo].[ADD_number] 4; GO 2
Creating an empty table in first procedure and adding two numbers in second procedure.
And now you can start playing by calling the move procedures. In this case, player is taking first move to go UP.
EXEC [dbo].[PLAY_game] 'U', 4
The UP move summed the two 2 numbers into 4 and added a new number 2 on blank tile (blank tile = 0).
As always, the complete code is available on Github repository. And feel free to collaborate.
Connor McDonald posted: "In last weeks' Office Hours session, I posted an "impossible" challenge to two of the most well credentialed Oracle community members on the subject of Testing. Samuel Nitsche and Jacek Gebal bravely undertook a live session of building unit tests for a s"
In last weeks' Office Hours session, I posted an "impossible" challenge to two of the most well credentialed Oracle community members on the subject of Testing. Samuel Nitsche and Jacek Gebal bravely undertook a live session of building unit tests for a sight-unseen application.
I provided a data model, some DDL and a PL/SQL package to implement a cut-down version of AskTom - an app that would accept questions, answers and comments. With minimal prior knowledge, Samuel and Jacek had to wander through the quagmire of my lazy design and lazier coding to dig into the nuts and bolts of this application.
You can see how they went in the video below. Perhaps the biggest takeaway from this session is the power and flexibility of the utPLSQL testing framework. It was amazing to see how quickly tests could be built.
Editorial Team posted: " Just read our Instantproxies review before buying this advanced private proxies. We give you complete details like its features, interface, speed test, pros and cons. Instantproxies Review InstantProxies has been around since 2013 and is best known"
Just read our Instantproxies review before buying this advanced private proxies. We give you complete details like its features, interface, speed test, pros and cons. Instantproxies Review InstantProxies has been around since 2013 and is best known for a dollar-per-proxy pricing, fast servers, and instant set-up. It offers advanced private proxies for social media, web […]
ephemeralnewyork posted: " Unless you know where to look, it's hard to find. But on the east side of City Hall Park is a spot that honors people living with a disease considered a plague when it emerged in the early 1980s. "People With A.I.D.S Plaza," as the street sign rea"
Unless you know where to look, it's hard to find. But on the east side of City Hall Park is a spot that honors people living with a disease considered a plague when it emerged in the early 1980s.
"People With A.I.D.S Plaza," as the street sign reads, spans Park Row between Beekman and Spruce Streets, near the approach for the Brooklyn Bridge.
It's technically an honorific street or a co-named street; both terms are used to described streets that have an official name but also a second one to commemorate a person or event. New York has over a thousand of these, such as "Rivera Avenue" for Mariano Rivera in front of Yankee Stadium, or the 3-block stretch of Worth Street co-named "Avenue of the Strongest" to honor city sanitation workers.
Clues about the backstory of People With A.I.D.S. Plaza aren't easy to come by. The street may have been co-named in 1997, according to the Encyclopedia of New York City: Second Edition, but the wording isn't clear. It's not on a list of honorific street names compiled by a researcher named Gilbert Tauber.
Why City Hall? Possibly to mark the location where AIDS activists and allies held protests—like this one in 1989 organized by ACT UP, with more than 3,000 people protesting Mayor Koch's handling of the disease.
Since People With A.I.D.S. Plaza was added to the map, New York has created more prominent memorials to the thousands of city residents living with AIDS or HIV, or who have died of the virus.
The New York City AIDS Memorial, dedicated in 2016 (above), is a pyramid-like steel sculpture at St. Vincent's Triangle on Seventh Avenue and West 11th Street. Now the site of a small park, St. Vincent's Triangle is across the street from the former St. Vincent's Hospital—which in 1984 established the first AIDS ward in New York City, according to NYC Parks.