-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03_Play_game.sql
62 lines (50 loc) · 1.28 KB
/
03_Play_game.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
SET NOCOUNT ON;
GO
CREATE OR ALTER PROCEDURE dbo.PLAY_game
/**************************************************************
Procedure: dbo.PLAY_game
Create Date: 2021-11-28
Author: Tomaz Kastrun
Description: Reorganize the numbers in table (update)
based on the selected direction and add
new number 2 in empty tile (where value=0).
Procedure output: updates table: [dbo].[T_2048]
Parameter(s): @dim - size of the matrix; e.g.: 4 = 4x4
@move - directon of move and calculation.
- Possible values: U, D, L, R (Up, Down, Left, Right)
Usage: EXEC dbo.PLAY_game
@move = 'U'
,@dim = 4
ChangeLog:
************************************************************* */
@move CHAR(1)
,@dim INT
AS
BEGIN
BEGIN
IF @move = 'U'
BEGIN
EXEC dbo.MOVE_up @dim;
EXEC [dbo].[FIND_ADD_number] @dim;
SELECT * FROM T_2048
END
IF @move = 'D'
BEGIN
EXEC dbo.MOVE_down @dim;
EXEC [dbo].[FIND_ADD_number] @dim;
SELECT * FROM T_2048
END
IF @move = 'L'
BEGIN
EXEC dbo.MOVE_left @dim;
EXEC [dbo].[FIND_ADD_number] @dim;
SELECT * FROM T_2048
END
IF @move = 'R'
BEGIN
EXEC dbo.MOVE_right @dim;
EXEC [dbo].[FIND_ADD_number] @dim;
SELECT * FROM T_2048
END
END;
GO