This repository has been archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 82cd4c4
Showing
6 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
# Created by https://www.gitignore.io/api/node | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
# End of https://www.gitignore.io/api/node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2017 Falco Nogatz (fnogatz@gmail.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Spieler Sonderpunkte setzen | ||
|
||
Stapelweise die Sonderpunkte von Spielern in einer SWT-Datei überschreiben. Dies ist notwendig, um das Baku Beschleunigte System verhältnismäßig einfach in Swiss-Chess abbilden zu können. Hintergründe zum System in [diesem Artikel](http://www.deutsche-schachjugend.de/dem2017/presse/dem-nachrichten/?tx_ttnews%5Byear%5D=2017&tx_ttnews%5Bmonth%5D=05&tx_ttnews%5Btt_news%5D=2412&cHash=5a8e073ff13e3bbf2fb9575b11d9fdbe). | ||
|
||
**Funktioniert nur mit node 0.10.x!** | ||
|
||
## Usage | ||
|
||
Sonderpunkte für alle Spieler der Nummer 1 bis 123 auf 0.5 setzen: | ||
|
||
```sh | ||
node bin/spieler-sonderpunkte.js --input /input.SWT --output /output.SWT --value 0.5 --from 1 --to 123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var fs = require('fs'); | ||
var change = require('../lib/index'); | ||
|
||
var opts = require('nomnom') | ||
.option('input', { | ||
abbr: 'i', | ||
flag: false, | ||
help: 'SWT file', | ||
required: true | ||
}) | ||
.option('output', { | ||
abbr: 'o', | ||
flag: false, | ||
help: 'SWT file output', | ||
required: true | ||
}) | ||
.option('value', { | ||
help: 'numeric value', | ||
required: false, | ||
default: 0 | ||
}) | ||
.option('from', { | ||
help: 'starting player number', | ||
required: false | ||
}) | ||
.option('to', { | ||
help: 'ending player number', | ||
required: false | ||
}) | ||
.option('version', { | ||
flag: true, | ||
help: 'print version and exit', | ||
callback: function() { | ||
return require('../package.json').version; | ||
} | ||
}) | ||
.parse(); | ||
|
||
opts.value = parseFloat(opts.value) | ||
|
||
change(opts, function(err, out) { | ||
if (err) | ||
throw err; | ||
|
||
fs.writeFileSync(opts.output, out); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module.exports = change; | ||
|
||
var swtparser = require('swtparser'); | ||
|
||
function change(opts, callback) { | ||
if (typeof opts.input === 'object') { | ||
if (require('buffer').Buffer.isBuffer(opts.input)) { | ||
fromBuffer(opts, callback); | ||
} | ||
else if (opts.input instanceof DataView) { | ||
fromDataView(opts, callback); | ||
} | ||
} | ||
else if (typeof opts.input === 'string') { | ||
fromFile(opts, callback); | ||
} | ||
} | ||
|
||
function fromFile(opts, callback) { | ||
require('fs').readFile(opts.input, function(err, buffer) { | ||
if (err) return callback(err); | ||
opts.input = buffer | ||
fromBuffer(opts, callback); | ||
}); | ||
} | ||
|
||
function fromBuffer(opts, callback) { | ||
var arrayBuffer = bufferToArrayBuffer(opts.input); | ||
var view = new DataView(arrayBuffer); | ||
opts.input = view | ||
|
||
fromDataView(opts, callback); | ||
} | ||
|
||
function bufferToArrayBuffer(buffer) { | ||
// see http://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer | ||
var ab = new ArrayBuffer(buffer.length); | ||
var view = new Uint8Array(ab); | ||
for (var i = 0; i < buffer.length; ++i) { | ||
view[i] = buffer[i]; | ||
} | ||
return ab; | ||
} | ||
|
||
function arrayBufferToBuffer(ab) { | ||
var buffer = new Buffer(ab.byteLength); | ||
for (var i = 0; i < buffer.length; ++i) { | ||
buffer[i] = ab[i]; | ||
} | ||
return buffer; | ||
} | ||
|
||
|
||
function fromDataView(opts, callback) { | ||
var dataView = opts.input | ||
var start = opts.from || 1 | ||
var value = opts.value || 0 | ||
|
||
var tnmt = swtparser(dataView, function(err, tnmt) { | ||
if (err) | ||
return callback(err); | ||
|
||
var end = opts.to || tnmt.general[4] | ||
|
||
var Structure = require('swtparser/lib/structure.json'); | ||
|
||
var playerOffset = parseInt(Structure.parameters['start:fixtures_players']) | ||
|
||
if (tnmt.general[3]) { | ||
// at least one round paired | ||
playerOffset += (tnmt.general[4] * tnmt.general[1] * parseInt(Structure.parameters['length:pairing'])) | ||
playerOffset += (tnmt.general[80] * tnmt.general[1] * parseInt(Structure.parameters['length:pairing'])) | ||
} | ||
|
||
var sonderPunkteOffset = Structure.structures.player[2029]; | ||
var offset | ||
|
||
// loop through players | ||
for (var i = (start-1); i < tnmt.general[4] && i < end; i++) { | ||
offset = playerOffset + i * parseInt(Structure.parameters['length:player']) | ||
|
||
// manipulate 'sonderPunkte' field | ||
dataView.setInt8(offset+sonderPunkteOffset.where, value*2) | ||
} | ||
|
||
var buffer = arrayBufferToBuffer(dataView); | ||
callback(null, buffer); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "SWT-sonderpunkte", | ||
"description": "Change the virtual points for all players in a Swiss-Chess Tournament (SWT) file", | ||
"author": "Falco Nogatz <fnogatz@gmail.com>", | ||
"version": "0.0.1", | ||
"private": true, | ||
"keywords": ["chess", "SWT", "swiss-chess"], | ||
"main": "./lib/index.js", | ||
"engines": { | ||
"node": "0.10.x" | ||
}, | ||
"dependencies": { | ||
"nomnom": "1.6.x", | ||
"swtparser": "1.3.x" | ||
}, | ||
"bin": "./bin/change.js" | ||
} |