SHOW:
|
|
- or go back to the newest paste.
1 | // ==UserScript== | |
2 | // @id | |
3 | // @name Blindfold_Arimaa | |
4 | - | // @version 1.13 |
4 | + | // @version 1.15 |
5 | // @namespace | |
6 | // @author Mathew Brown, Matthew Craven | |
7 | // @description Play blindfold Arimaa with the javascript client | |
8 | // @include http://arimaa.com/arimaa/java/ys/ms4/v5/js_sit.cgi | |
9 | // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js | |
10 | // ==/UserScript== | |
11 | ||
12 | //define common setups so they don't have to be typed out | |
13 | var silver_99of9 = 'ra7 hb7 cc7 ed7 me7 cf7 hg7 rh7 ra8 rb8 rc8 dd8 de8 rf8 rg8 rh8'; | |
14 | var gold_99of9 = 'Ra1 Rb1 Rc1 Dd1 De1 Rf1 Rg1 Rh1 Ra2 Hb2 Cc2 Ed2 Me2 Cf2 Hg2 Rh2'; | |
15 | var silver_browni = 'ha7 mb7 dc7 ed7 de7 cf7 hg7 rh7 ra8 rb8 cc8 rd8 re8 rf8 rg8 rh8'; | |
16 | ||
17 | //Hide the board | |
18 | $('#boardspan').hidden = true; | |
19 | ||
20 | //Widen the movelist to allow reading of setups | |
21 | $('#movelist').style.cssText='width:500px' | |
22 | ||
23 | //Find and hide the plan button; just remove the temptation :) | |
24 | for (i=0; true; ++i) { | |
25 | if (document.all[i].defaultValue==='P') { | |
26 | document.all[i].hidden=true; | |
27 | break; } } | |
28 | ||
29 | //Hide the captured pieces | |
30 | for (i=1; i<=16; ++i) { | |
31 | $('#cap_w'+i).hidden=true; | |
32 | $('#cap_b'+i).hidden=true; } | |
33 | ||
34 | //send any move, not checked for legality | |
35 | //After three seconds, will report errors | |
36 | function send(move){ | |
37 | var obj = {action:"move", sid:arimaa.vars.sessionid, auth: arimaa.vars.auth, move: move} | |
38 | var req = new XMLHttpRequest(); | |
39 | - | req.send(JSON.stringify(obj));}; |
39 | + | |
40 | req.send(JSON.stringify(obj)); | |
41 | setTimeout(function(){ | |
42 | if (req.responseText.slice(2,7)==='error') { //Check for errors | |
43 | console.log('The gameserver rejected your move.');}},3000);}; | |
44 | ||
45 | //eg 'Ed2nenn' to 'Ed2n Ed3e Ee3n Ee4n' | |
46 | function expand(movestring) { | |
47 | var piecelist='EeMmHhDdCcRr'; | |
48 | var currpiece=false; | |
49 | var filelist='abcdefgh'; | |
50 | var currfile=false; | |
51 | var filenum=false; | |
52 | var ranklist='12345678'; | |
53 | var currrank=false; | |
54 | var ranknum=false; | |
55 | var havemoved=false; | |
56 | var dirlist='enwsx'; | |
57 | var dirnum=false; | |
58 | var dirfilelist=[1,0,-1,0,0]; | |
59 | var dirranklist=[0,1,0,-1,0]; | |
60 | var iscaptured=false; | |
61 | var endstring=''; | |
62 | for (i=0; i<movestring.length; ++i) { | |
63 | currchar=movestring[i]; | |
64 | if (!currpiece) { | |
65 | for (j=0; j<piecelist.length; ++j) { | |
66 | if (currchar==piecelist[j]) { | |
67 | currpiece=currchar;}} | |
68 | if (!currpiece) { | |
69 | var q='error: bad piece type: '; | |
70 | console.log(q+movestring.slice(0,i+1)); | |
71 | return '';}} | |
72 | else if (!currfile) { | |
73 | for (j=0; j<filelist.length; ++j) { | |
74 | if (currchar==filelist[j]) { | |
75 | currfile=currchar; | |
76 | filenum=j;}} | |
77 | if (!currfile) { | |
78 | var q='error: bad file: '; | |
79 | console.log(q+movestring.slice(0,i+1)); | |
80 | return '';}} | |
81 | else if (!currrank) { | |
82 | for (j=0; j<ranklist.length; ++j) { | |
83 | if (currchar==ranklist[j]) { | |
84 | currrank=currchar; | |
85 | ranknum=j;}} | |
86 | if (!currrank) { | |
87 | var q='error: bad rank: '; | |
88 | console.log(q+movestring.slice(0,i+1)); | |
89 | return '';}} | |
90 | else if (havemoved&&(currchar==' ')) { | |
91 | currpiece=false; | |
92 | currfile=false; | |
93 | filenum=false; | |
94 | currrank=false; | |
95 | ranknum=false; | |
96 | havemoved=false; | |
97 | iscaptured=false;} | |
98 | else { | |
99 | if (iscaptured) { | |
100 | var q='error: captured piece moved: '; | |
101 | console.log(q+movestring.slice(0,i+1)); | |
102 | return '';} | |
103 | if (currchar=='x') {iscaptured=true;} | |
104 | havemoved=false; | |
105 | for (j=0; j<dirlist.length; ++j) { | |
106 | if (currchar==dirlist[j]) { | |
107 | dirnum=j; | |
108 | havemoved=true;}} | |
109 | if (!havemoved) { | |
110 | var q='error: bad direction: '; | |
111 | console.log(q+movestring.slice(0,i+1)); | |
112 | return '';} | |
113 | endstring+=currpiece+filelist[filenum]; | |
114 | endstring+=ranklist[ranknum]+currchar+' '; | |
115 | filenum+=dirfilelist[dirnum] | |
116 | ranknum+=dirranklist[dirnum] | |
117 | if ((filenum<0)||(filenum>7)||(ranknum<0)||(ranknum>7)){ | |
118 | var q='error: piece moved out of bounds: '; | |
119 | console.log(q+movestring.slice(0,i+1)); | |
120 | return '';} | |
121 | } | |
122 | } | |
123 | if (currpiece&&(!havemoved)) { | |
124 | console.log('error: incomplete move'); | |
125 | return '';} | |
126 | return endstring.slice(0,endstring.length-1);} | |
127 | ||
128 | //sh==shorthand; accepts compressed moves and expands before sending | |
129 | //Provides some help with obvious illegal moves, but doesn't catch nearly all | |
130 | function sh(movestring) { | |
131 | send(expand(movestring));} | |
132 | ||
133 | //Accepts fen-like general gold setups and sends them | |
134 | //eg sendset('RHCEMCHR/RRRDDRRR') sends the gold 99of9 | |
135 | //setup and sendset('rrrddrrr/rhcmechr') sends the | |
136 | //silver 99of9 setup. Not checked for legality. | |
137 | function sendset(movestring) { | |
138 | var lowerrank=7; | |
139 | var goldpieces='EMHDCR'; | |
140 | for (i=0; i<6; ++i) { //First check for which color we send the setup | |
141 | if (movestring[0]===goldpieces[i]) { | |
142 | lowerrank=1; } } | |
143 | var filenames='abcdefgh'; | |
144 | var endstring=''; | |
145 | for (i=0; i<8; ++i) { | |
146 | endstring+=movestring[i]+filenames[i]+(lowerrank+1)+' '; | |
147 | endstring+=movestring[i+9]+filenames[i]+lowerrank+' ';} | |
148 | send(endstring.slice(0,endstring.length-1));} |