• R/O
  • SSH
  • HTTPS

thief: Commit


Commit MetaInfo

Revision13 (tree)
Time2011-10-13 00:44:18
Authorseussnu

Log Message

0.0.6-alpha1
・数式を逆ポーランド記法にする処理を追加

Change Summary

Incremental Difference

--- thief.js (revision 12)
+++ thief.js (revision 13)
@@ -46,8 +46,8 @@
4646 languagePriolity : ['en', 'ja'],
4747 statusPosition : 'bottom', // top or bottom
4848 statusLineFormat : [
49- '${THIEF.global.adventurer.%get@name%} ♥:${THIEF.global.adventurer.%get@hp%} CT:${THIEF.global.adventurer.%get@ct%}',
50- 'Lang:${THIEF.conf.language} Turn : ${THIEF.global.turn}'
49+ '${THIEF.global.adventurer.%get@name%} ♥:${THIEF.global.adventurer.%get@hp%} Turn : ${THIEF.global.turn}',
50+ 'Lang:${THIEF.conf.language} CT:${THIEF.global.adventurer.%get@ct%}'
5151 ],
5252 messagePosition : 'top', // top or bottom
5353 messageLines : 3,
@@ -656,6 +656,137 @@
656656 return this.action();
657657 };
658658
659+THIEF.command.wield = function () {
660+
661+ var val = '2d100 * (2 + 15) + Math.max(3, 4) + (Math.round(11.2) * Math.PI + 6)';
662+ //var val = '(Math.round(11.2) * Math.PI)';
663+ //var val = 'Math.max(3, 4) + Math.round(11.2) + Math.PI';
664+ //var val = '8 + Math.max(3, 4) + Math.PI';
665+ var stack = [];
666+ var revP = [];
667+ var math;
668+ var subIndex;
669+
670+ THIEF.html.addDebugMessage('数式を逆ポーランドに変換開始...');
671+ THIEF.html.addDebugMessage('変換前:' + val);
672+
673+ for(var i = 0; i < val.length; i++){
674+ var ope = val[i];
675+ switch (ope) {
676+ case '+' :
677+ case '-' :
678+ while(/^[\*\/\^%dM]$/.test(stack.getLast())){
679+ revP.push(stack.pop());
680+ }
681+ stack.push(ope);
682+ break;
683+
684+ case '*' :
685+ case '/' :
686+ while(/^[\^%dM]$/.test(stack.getLast())){
687+ revP.push(stack.pop());
688+ }
689+ stack.push(ope);
690+ break;
691+
692+ case '^' :
693+ case '%' :
694+ while(/^[dM]$/.test(stack.getLast())){
695+ revP.push(stack.pop());
696+ }
697+ stack.push(ope);
698+ break;
699+
700+ case 'd' :
701+ while(/^[M]$/.test(stack.getLast())){
702+ revP.push(stack.pop());
703+ }
704+ stack.push(ope);
705+ break;
706+
707+ case 'M' :
708+
709+ // M から演算子 or 空白 までを取り出す
710+ // Math. を必ず含むこと
711+ // Math.PId6 とかは使用上無理
712+ for(subIndex=i+5; subIndex<val.length; subIndex++){
713+ if(/^[\+\-\*\/\^%\(\) ]$/.test(val[subIndex])){
714+ math = val.substring(i+5, subIndex);
715+ break;
716+ } else if(subIndex === val.length-1){
717+ math = val.substring(i+5, val.length);
718+ break;
719+ }
720+ }
721+
722+ if(typeof Math[math] === 'function'){
723+ stack.push('(');
724+ stack.push(Math[math]);
725+ //stack.push(math);
726+ } else {
727+ revP.push(Math[math]);
728+ }
729+
730+ i = subIndex;
731+
732+ break;
733+
734+ case '(' :
735+ stack.push(ope);
736+ break;
737+
738+ case ')' :
739+ // Math 関数の引数の数が不定なので、判別用のダミーの引数を加えておく
740+ if(typeof stack.getLast() === 'function'){
741+ revP.push('dummy');
742+ }
743+
744+ while(stack.getLast() !== '('){
745+ revP.push(stack.pop());
746+ }
747+ stack.pop(); // Delete (
748+ break;
749+
750+ case '0' :
751+ case '1' :
752+ case '2' :
753+ case '3' :
754+ case '4' :
755+ case '5' :
756+ case '6' :
757+ case '7' :
758+ case '8' :
759+ case '9' :
760+ case '.' :
761+ for(subIndex = i+1; subIndex<val.length; subIndex++){
762+ if(/[^0-9.]/.test(val[subIndex])){
763+ revP.push(val.substring(i, subIndex));
764+ subIndex--;
765+ break;
766+ } else if(subIndex === val.length-1){
767+ revP.push(val.substring(i, val.length));
768+ break;
769+ }
770+ }
771+ i = subIndex;
772+ break;
773+
774+ default :
775+ break;
776+
777+ }
778+ }
779+
780+ while(stack.getLast()){
781+ revP.push(stack.pop());
782+ }
783+
784+ THIEF.html.addDebugMessage('変換後:' + revP);
785+ THIEF.html.addDebugMessage('...変換完了');
786+
787+ return true;
788+};
789+
659790 THIEF.util = {};
660791 THIEF.util.init = function() {
661792
@@ -2321,56 +2452,27 @@
23212452 };
23222453
23232454 // 束縛しないように関数化している
2324-THIEF.type.$.manual['h'.charCodeAt(0)] = function() {
2325- return this.goLeft();
2326-};
2327-THIEF.type.$.manual['k'.charCodeAt(0)] = function() {
2328- return this.goUp();
2329-};
2330-THIEF.type.$.manual['j'.charCodeAt(0)] = function() {
2331- return this.goDown();
2332-};
2333-THIEF.type.$.manual['l'.charCodeAt(0)] = function() {
2334- return this.goRight();
2335-};
2336-THIEF.type.$.manual['y'.charCodeAt(0)] = function() {
2337- return this.goUpperLeft();
2338-};
2339-THIEF.type.$.manual['u'.charCodeAt(0)] = function() {
2340- return this.goUpperRight();
2341-};
2342-THIEF.type.$.manual['b'.charCodeAt(0)] = function() {
2343- return this.goLowerLeft();
2344-};
2345-THIEF.type.$.manual['n'.charCodeAt(0)] = function() {
2346- return this.goLowerRight();
2347-};
2348-THIEF.type.$.manual['R'.charCodeAt(0)] = function() {
2349- return this.refreshHTML();
2350-};
2351-THIEF.type.$.manual[','.charCodeAt(0)] = function() {
2352- return this.pickup();
2353-};
2354-THIEF.type.$.manual['d'.charCodeAt(0)] = function() {
2355- return this.drop();
2356-};
2455+THIEF.type.$.manual['h'.charCodeAt(0)] = function() { return this.goLeft(); };
2456+THIEF.type.$.manual['k'.charCodeAt(0)] = function() { return this.goUp(); };
2457+THIEF.type.$.manual['j'.charCodeAt(0)] = function() { return this.goDown(); };
2458+THIEF.type.$.manual['l'.charCodeAt(0)] = function() { return this.goRight(); };
2459+THIEF.type.$.manual['y'.charCodeAt(0)] = function() { return this.goUpperLeft(); };
2460+THIEF.type.$.manual['u'.charCodeAt(0)] = function() { return this.goUpperRight(); };
2461+THIEF.type.$.manual['b'.charCodeAt(0)] = function() { return this.goLowerLeft(); };
2462+THIEF.type.$.manual['n'.charCodeAt(0)] = function() { return this.goLowerRight(); };
2463+THIEF.type.$.manual['R'.charCodeAt(0)] = function() { return this.refreshHTML(); };
2464+THIEF.type.$.manual[','.charCodeAt(0)] = function() { return this.pickup(); };
2465+THIEF.type.$.manual['d'.charCodeAt(0)] = function() { return this.drop(); };
23572466 /*
23582467 THIEF.type.$.manual['i'.charCodeAt(0)] = function() {
23592468 return this.showInventory();
23602469 };
23612470 */
2362-THIEF.type.$.manual['p'.charCodeAt(0)] = function() {
2363- return this.history();
2364-};
2365-THIEF.type.$.manual['s'.charCodeAt(0)] = function() {
2366- return this.rest();
2367-};
2368-THIEF.type.$.manual['.'.charCodeAt(0)] = function() {
2369- return this.rest();
2370-};
2371-THIEF.type.$.manual['#'.charCodeAt(0)] = function() {
2372- return this.extendedCommand();
2373-};
2471+THIEF.type.$.manual['p'.charCodeAt(0)] = function() { return this.history(); };
2472+THIEF.type.$.manual['s'.charCodeAt(0)] = function() { return this.rest(); };
2473+THIEF.type.$.manual['w'.charCodeAt(0)] = function() { return this.wield(); };
2474+THIEF.type.$.manual['.'.charCodeAt(0)] = function() { return this.rest(); };
2475+THIEF.type.$.manual['#'.charCodeAt(0)] = function() { return this.extendedCommand(); };
23742476 THIEF.type.$.next = function() {
23752477 return this.cpu();
23762478 }; // 基本は CPU
Show on old repository browser