### Repository https://github.com/programarivm/pgn-chess  Hi dear readers! As you most probably know already, last week I started to send a series of pull requests to PGN Chess. At this stage, this PHP library comes out of the box with a few [CLI commands](https://pgn-chess.readthedocs.io/en/latest/command-line-interface/), among which is `db-seed.php` to easily load thousands of PGN games into a database for further processing. > **Remember**: PGN Chess is a chess board representation to play and validate PGN games (player vs player) which also provides with a PHP CLI command to seed a database with PGN games. ### Technology Stack - PHP 7 - PDO - MySQL ### New Features The fact of having a chess database powered by SQL opens the door to a whole new range of possibilities. Let's see how we can do this. <iframe width="560" height="315" src="https://www.youtube.com/embed/mbj1RFaoyLk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> Today, it is the turn of [Feature/game metadata #15](https://github.com/programarivm/pgn-chess/pull/15). This one helps players learn about chess openings, grandmasters' games, events, as well as to improve their memory recall, all at once while they are having fun playing a very interesting chess game. A bit more specifically, I am referring to the `metadata()` method, and I'd even say it is a training tool for chess players actually. Here is an example of the new method in action: ``` $game = new Game; $game->play('w', 'd4'); $game->play('b', 'd5'); $game->play('w', 'Bf4'); $metadata = $game->metadata(); ``` Now, `$metadata` might be an array as the described below. ``` Array ( [Event] => 11. KIIT Elite Open 2018 [Site] => Bhubaneswar IND [Date] => 2018.05.28 [Round] => 6.5 [White] => Kravtsiv, Martyn [Black] => Das, Sayantan [Result] => 1-0 [WhiteElo] => 2655 [BlackElo] => 2437 [EventDate] => 2018.05.25 [ECO] => D02 [movetext] => 1.d4 d5 2.Bf4 Nf6 3.Nf3 c5 4.e3 Nc6 5.Nbd2 e6 6.c3 Bd6 7.Bg3 O-O 8.Bd3 b6 9.e4 dxe4 10.Nxe4 Be7 11.Nxf6+ Bxf6 12.dxc5 bxc5 13.Qc2 h6 14.h4 Qe7 15.O-O-O Rd8 16.Bh7+ Kh8 17.Rxd8+ Nxd8 18.Be4 Bb7 19.Rd1 Rc8 20.Qa4 Bxe4 21.Qxe4 Nc6 22.Bd6 Qe8 23.Bxc5 Na5 24.Qb4 Nc6 25.Qa4 e5 26.Qe4 Na5 27.Rd5 Qb5 28.Bb4 Qf1+ 29.Rd1 Qb5 30.Bxa5 Qxa5 31.a3 Qb5 32.g3 Rc4 33.Qd5 Qb3 34.Nxe5 Rxc3+ 35.bxc3 Qxc3+ 36.Kb1 Bxe5 37.Qd8+ Kh7 38.Qd3+ Qxd3+ 39.Rxd3 Kg6 40.Kc2 Bc7 41.Rd5 Bb6 42.f3 h5 43.Kd3 f6 44.Ke2 Bc7 45.g4 hxg4 46.fxg4 Bb6 47.a4 1-0 ) ``` But it could be this one too. ``` Array ( [Event] => 1. Longtou Cup 2018 [Site] => Qinhuangdao CHN [Date] => 2018.05.28 [Round] => 3.2 [White] => Antipov, Mikhail Al [Black] => Dai, Changren [Result] => 1/2-1/2 [WhiteElo] => 2597 [BlackElo] => 2436 [EventDate] => 2018.05.26 [ECO] => D00 [movetext] => 1.d4 d5 2.Bf4 Nf6 3.e3 e6 4.Nd2 c5 5.c3 Nc6 6.Ngf3 Bd6 7.Bg3 O-O 8.Bb5 h6 9.Qe2 Bxg3 10.hxg3 Qb6 11.Rb1 Bd7 12.Bd3 Ng4 13.Nh4 f5 14.f3 Nf6 15.Ng6 Rfe8 16.f4 Kf7 17.Ne5+ Nxe5 18.fxe5 Ng4 19.Nf3 Qd8 20.Nh2 Nxh2 21.Rxh2 Qg5 22.Kf2 Kg8 23.Rh5 Qg6 24.dxc5 Rec8 25.Rbh1 Rxc5 26.R1h4 Rf8 27.g4 fxg4+ 28.Kg1 Bb5 29.Bxb5 Rxb5 30.Rxh6 Qb1+ 31.Kh2 1/2-1/2 ) ``` Yep, `$metadata` is randomish. It can be anything starting with `d4`, `d5` and `Bf4`, and it will vary in subsequent calls according to the chess games stored in a particular database. Are you curious on what's under the hood? The idea is really simple, let me show you in a nutshell the code that makes it happen. ``` // src/Board.php ... $result = Pdo::getInstance() ->query("SELECT * FROM games WHERE movetext LIKE '$movetext%' ORDER BY RAND() LIMIT 1") ->fetch(\PDO::FETCH_ASSOC); ... ``` Easy peasy lemon squeezy. In my opinion, the relevant difficulty of this exercise consists in making sure that all movetexts are written using the exact same format for the SQL query to work properly.  And here is where a movetext filter in [`src/PGN/Movetext.php`](https://github.com/programarivm/pgn-chess/blob/master/src/PGN/Movetext.php) comes to the rescue in search for unnecessary blank spaces: ``` // src/PGN/Movetext.php ... /** * Filters a movetext. * * Example: * * 1.e4 e5 2. f4 exf4 3. Bc4 d5 4.Bxd5 Qh4+ * * is transformed into: * * 1.e4 e5 2.f4 exf4 3.Bc4 d5 4.Bxd5 Qh4+ * * @return string */ public static function filter(): string { $text = ''; for ($i = 0; $i < count(self::$movetext->numbers); $i++) { $text .= self::$movetext->numbers[$i] . '.' . self::$movetext->notations[$i*2] . ' ' . self::$movetext->notations[$i*2+1] . ' '; } return trim($text); } ... ``` That's all for now. I hope you liked todayโs post. Thank you for reading and sharing your thoughts. ### Documentation For further information please read the [Documentation](https://pgn-chess.readthedocs.io/en/latest/game-methods/). ### License The GNU General Public License. ### Contributions Would you help make this library better? Contributions are welcome. - Feel free to send a pull request - Drop an email at info@programarivm.com with the subject "PGN Chess Contributions" - Leave me a comment on [Twitter](https://twitter.com/programarivm) - Say hello on [Google+](https://plus.google.com/+Programarivm) ### GitHub Account https://github.com/programarivm
author | programarivm |
---|---|
permlink | a-training-tool-for-chess-players-based-on-memory-recall |
category | utopian-io |
json_metadata | {"tags":["utopian-io","development","php","mysql","chess"],"image":["https://cdn.steemitimages.com/DQmR7gi7pNmxbKjA2aLnSkKDZ1RrkLn6m7MgfWXohthPtQh/robot-searching.jpg","https://img.youtube.com/vi/mbj1RFaoyLk/0.jpg","https://cdn.steemitimages.com/DQmSRhfDhVTHULTri9f1XRwXpmAnFQMd3LXw33crcNCwj1q/chess-231x300.jpg"],"links":["https://github.com/programarivm/pgn-chess","https://pgn-chess.readthedocs.io/en/latest/command-line-interface/","https://www.youtube.com/embed/mbj1RFaoyLk","https://github.com/programarivm/pgn-chess/pull/15","https://github.com/programarivm/pgn-chess/blob/master/src/PGN/Movetext.php","https://pgn-chess.readthedocs.io/en/latest/game-methods/","https://twitter.com/programarivm","https://plus.google.com/+Programarivm","https://github.com/programarivm"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-08-24 20:15:03 |
last_update | 2018-08-25 08:16:51 |
depth | 0 |
children | 6 |
last_payout | 2018-08-31 20:15:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 19.881 HBD |
curator_payout_value | 6.379 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,591 |
author_reputation | 2,631,258,794,707 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,260,465 |
net_rshares | 17,958,045,395,776 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
cosmo.crator | 0 | 848,055,430 | 100% | ||
yuxi | 0 | 3,038,410,378 | 10% | ||
elviento | 0 | 281,733,406 | 1% | ||
luigi-tecnologo | 0 | 1,132,256,576 | 4% | ||
doughtaker | 0 | 25,227,784,842 | 100% | ||
dreamarif | 0 | 67,865,525 | 6% | ||
opaulo | 0 | 73,570,625,116 | 16% | ||
utopian-io | 0 | 16,854,589,337,966 | 24.42% | ||
steemtaker | 0 | 2,069,158,477 | 6% | ||
jahedkhan | 0 | 92,453,133 | 3% | ||
idontgnu | 0 | 115,775,541 | 12% | ||
joeycrack | 0 | 127,137,252 | 6% | ||
amosbastian | 0 | 32,850,257,855 | 44.4% | ||
tdre | 0 | 10,350,243,295 | 100% | ||
jjay | 0 | 854,401,658 | 100% | ||
guangzhoulife | 0 | 164,028,006 | 12% | ||
voyagesofcarla2 | 0 | 219,595,061 | 6% | ||
cjd | 0 | 157,379,936 | 12% | ||
umich | 0 | 1,112,024,182 | 12% | ||
statsexpert | 0 | 3,527,844,691 | 60% | ||
trexxie | 0 | 1,264,521,212 | 50% | ||
plgonzalezrx8 | 0 | 421,925,666 | 12% | ||
beetlevc | 0 | 1,240,901,893 | 2% | ||
soundworks | 0 | 212,047,761 | 9.29% | ||
dalz | 0 | 1,491,346,286 | 100% | ||
steem-ua | 0 | 943,018,284,632 | 25.66% |
Thank you for your contribution. I really liked the way you have written everything in the pull requests. As basically it is a CLI tool, is there any way that frontend can call it and get the representation to be shown to the user? Also, there are a lot of .pgn files are removed from the GitHub. It's better to write those files in the .gitignore. Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category. To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/2322222). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | codingdefined |
---|---|
permlink | re-programarivm-a-training-tool-for-chess-players-based-on-memory-recall-20180825t082151213z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/2322222","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-08-25 08:21:51 |
last_update | 2018-08-25 08:21:51 |
depth | 1 |
children | 2 |
last_payout | 2018-09-01 08:21:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 4.232 HBD |
curator_payout_value | 1.361 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 841 |
author_reputation | 529,727,608,718,478 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,302,334 |
net_rshares | 3,839,964,820,901 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
yuxi | 0 | 8,812,094,495 | 30% | ||
espoem | 0 | 18,468,751,317 | 15% | ||
utopian-io | 0 | 3,783,623,754,095 | 5.47% | ||
amosbastian | 0 | 14,764,160,833 | 19.99% | ||
josephace135 | 0 | 13,956,331,985 | 100% | ||
mops2e | 0 | 339,728,176 | 10% |
Hi @codingdefined, thanks again for the review! Happy to know this post is a bit better than the previous ones. Good point on the `.pgn` files. I am not convinced that they should be written in the `.gitignore` file though because this data is required by the tests in order to pass OK as shown in https://travis-ci.org/programarivm/pgn-chess/jobs/420206833. However, the `.pgn` files, which are all included in the `tests` folder, are ignored in the `.gitattributes` file: ``` /examples/ export-ignore /resources/ export-ignore /tests/ export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore .travis.yml export-ignore ``` This way the `tests` folder is not installed locally when doing ``` composer require programarivm/pgn-chess ``` Let me show you something regarding the frontend. I wrote [this prototype](https://github.com/programarivm/react-pgn-chess) with [React](https://reactjs.org/) and [ReactPHP](https://reactphp.org/) -- the frontend prototype is still sketchy, needs some improvement. Anyway, here is how the React frontend uses the ReactPHP chess server: ``` import React from 'react'; import ReactDOM from 'react-dom'; import Board from './components/Board.js'; import './index.css'; var BoardElement = React.createElement(Board, {server: "localhost:3001"}); ReactDOM.render( BoardElement, document.getElementById('chess-board') ); ``` The server looks like this: ``` namespace ReactPgnChess; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use ReactPgnChess\PgnChessGame; require __DIR__ . '/../vendor/autoload.php'; $server = IoServer::factory( new HttpServer( new WsServer( new PgnChessGame() ) ), 3001 ); $server->run(); ```
author | programarivm |
---|---|
permlink | re-codingdefined-re-programarivm-a-training-tool-for-chess-players-based-on-memory-recall-20180825t091333864z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["codingdefined"],"links":["https://travis-ci.org/programarivm/pgn-chess/jobs/420206833","https://github.com/programarivm/react-pgn-chess","https://reactjs.org/","https://reactphp.org/"],"app":"steemit/0.1"} |
created | 2018-08-25 09:13:33 |
last_update | 2018-08-25 11:26:54 |
depth | 2 |
children | 0 |
last_payout | 2018-09-01 09:13:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,813 |
author_reputation | 2,631,258,794,707 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,305,423 |
net_rshares | 0 |
Thank you for your review, @codingdefined! So far this week you've reviewed 3 contributions. Keep up the good work!
author | utopian-io |
---|---|
permlink | re-re-programarivm-a-training-tool-for-chess-players-based-on-memory-recall-20180825t082151213z-20180825t102509z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-08-25 10:25:09 |
last_update | 2018-08-25 10:25:09 |
depth | 2 |
children | 0 |
last_payout | 2018-09-01 10:25:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 116 |
author_reputation | 152,955,367,999,756 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,309,893 |
net_rshares | 0 |
Hi @programarivm! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test mode upvoting quality Utopian-io contributions! Nice work!
author | steem-ua |
---|---|
permlink | re-a-training-tool-for-chess-players-based-on-memory-recall-20180825t084946z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.54"}" |
created | 2018-08-25 08:49:48 |
last_update | 2018-08-25 08:49:48 |
depth | 1 |
children | 0 |
last_payout | 2018-09-01 08:49:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 188 |
author_reputation | 23,214,230,978,060 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,303,920 |
net_rshares | 0 |
Congratulations @programarivm! You have completed the following achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@programarivm) Award for the total payout received <sub>_Click on the badge to view your Board of Honor._</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> > You can upvote this notification to help all Steemit users. Learn why [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
author | steemitboard |
---|---|
permlink | steemitboard-notify-programarivm-20180827t061256000z |
category | utopian-io |
json_metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
created | 2018-08-27 06:12:57 |
last_update | 2018-08-27 06:12:57 |
depth | 1 |
children | 0 |
last_payout | 2018-09-03 06:12:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 623 |
author_reputation | 38,975,615,169,260 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,472,949 |
net_rshares | 0 |
Hey @programarivm **Thanks for contributing on Utopian**. Weโre already looking forward to your next contribution! **Want to chat? Join us on Discord https://discord.gg/h52nFrV.** <a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-a-training-tool-for-chess-players-based-on-memory-recall-20180825t223509z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-08-25 22:35:09 |
last_update | 2018-08-25 22:35:09 |
depth | 1 |
children | 0 |
last_payout | 2018-09-01 22:35:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.020 HBD |
curator_payout_value | 0.004 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 302 |
author_reputation | 152,955,367,999,756 |
root_title | "A Training Tool for Chess Players Based on Memory Recall" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 69,360,583 |
net_rshares | 18,175,868,040 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 17,853,126,273 | 15% | ||
mops2e | 0 | 322,741,767 | 10% |