-
Nice challenge.
I integrate it with Part 1 and now I can play chess, but I cant "eat" pieces.
Hope Part 3 complete this! :D
|
-
One suggestion for an hypotethic part 3 would be:
Given de following layout:
Example: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'
Transform the Real notation into the especific one:
Real:
'e4'
'e5'
'Nf3'
'd6'
'd4'
Especific:
'Pe2e4'
'pe7e5'
'Ng1f3'
'pd7d6'
'Pd2d4'
Knights would be very hard :p
|
-
My solution "eats" pieces - although I didn't set out to design it that way. Hopefully that's the next challenge, because I'll be all set to go.
3 questions though:
- Do we have to worry about NULL layouts? I'm assuming each movement will have a non-null given that the rules say that table will only contain legal moves.
- Is there a maximum number of moves to deal with?
- I assume that we should be able to do multiple games at once?
I am using a recursive CTE, so the answers to 2 and 3 might affect that decision.
Thanks.
|
-
Sample data and my result:
IF OBJECT_ID('TC59_Layout','U') IS NOT NULL BEGIN
DROP TABLE TC59_Layout
END
GO
CREATE TABLE TC59_Layout(
GameID INT,
Layout VARCHAR(MAX)
)
GO
INSERT INTO TC59_Layout(GameID,Layout)
SELECT 1,'rnbqk2r/ppppbppp/5n2/4p3/2B1P3/5Q2/PPPP1PPP/RNB1K1NR' union all
SELECT 2,'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR' union all
SELECT 3,'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR' union all
SELECT 4,'7r/8/8/8/8/8/8/Q7'
SELECT * FROM TC59_Layout
GO
IF OBJECT_ID('TC59_Movement','U') IS NOT NULL BEGIN
DROP TABLE TC59_Movement
END
GO
CREATE TABLE TC59_Movement(
Seq INT IDENTITY PRIMARY KEY,
GameID INT,
Movement VARCHAR(MAX)
)
GO
INSERT INTO TC59_Movement(GameID,Movement)
SELECT 1,'Pd2d3' UNION ALL
SELECT 1,'pa7a6' UNION ALL
SELECT 1,'Bc1g5' UNION ALL
SELECT 1,'pb7b5' UNION ALL
SELECT 3,'Pa2a3' UNION ALL
SELECT 3,'ph7h6' UNION ALL
SELECT 3,'Pa3a4' UNION ALL
SELECT 3,'ph6h5' UNION ALL
SELECT 3,'Pa4a5' UNION ALL
SELECT 3,'ph5h4' UNION ALL
SELECT 3,'Ra1a2' UNION ALL
SELECT 3,'rh8h7'
go
INSERT INTO TC59_Movement(GameID,Movement)
SELECT 4,'Qa1a8' UNION ALL
SELECT 4,'rh8h1' UNION ALL
SELECT 4,'Qa8h8' UNION ALL
SELECT 4,'rh1a1' UNION ALL
SELECT 4,'Qh8h1' UNION ALL
SELECT 4,'ra1a8' UNION ALL
SELECT 4,'Qh1a1' UNION ALL
SELECT 4,'ra8h8'
go 50
INSERT INTO TC59_Movement(GameID,Movement)
SELECT 4,'Qa1a2'
SELECT * FROM TC59_Movement
GameID Result
1 rnbqk2r/2ppbppp/p4n2/1p2p1B1/2B1P3/3P1Q2/PPP2PPP/RN2K1NR
2 rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
3 rnbqkbn1/pppppppr/8/P7/7p/8/RPPPPPPP/1NBQKBNR
4 7r/8/8/8/8/8/Q7/8
|
-
Thx for posting this sample data.
The 3 first ones goes well, but in 4th one ...maxrecursion 100 crash mine :(
Edit: then, I found the maxrecursion hint ^^
|
-
Does anyone have any performance data with Leszek's sample data? Mine (returning all games):
Reads: 381091
Writes: 64
Duration: 1218
|
-
Reads: 5422 Writes: 0 Duration: 180ms
|
-
Hello, my stats:
(4 row(s) affected)
Table 'Worktable'. Scan count 8, logical reads 7470, physical reads 0, read-ahead reads 0, lob logical reads 4332, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Layout'. Scan count 2, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Movement'. Scan count 414, logical reads 1656, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 374 ms, elapsed time = 383 ms.
|
-
final version:
(4 row(s) affected)
Table 'Worktable'. Scan count 1, logical reads 41, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Movement'. Scan count 2, logical reads 10, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Layout'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 31 ms, elapsed time = 24 ms.
|
-
(4 row(s) affected)
Table 'Worktable'. Scan count 2, logical reads 2498, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Movement'. Scan count 2, logical reads 842, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'TC59Layout'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 63 ms, elapsed time = 73 ms.
I´m getting closer...too many reads :(
|
|