Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @id
- // @name Blindfold_Arimaa
- // @version 1.15
- // @namespace
- // @author Mathew Brown, Matthew Craven
- // @description Play blindfold Arimaa with the javascript client
- // @include http://arimaa.com/arimaa/java/ys/ms4/v5/js_sit.cgi
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
- // ==/UserScript==
- //define common setups so they don't have to be typed out
- var silver_99of9 = 'ra7 hb7 cc7 ed7 me7 cf7 hg7 rh7 ra8 rb8 rc8 dd8 de8 rf8 rg8 rh8';
- var gold_99of9 = 'Ra1 Rb1 Rc1 Dd1 De1 Rf1 Rg1 Rh1 Ra2 Hb2 Cc2 Ed2 Me2 Cf2 Hg2 Rh2';
- var silver_browni = 'ha7 mb7 dc7 ed7 de7 cf7 hg7 rh7 ra8 rb8 cc8 rd8 re8 rf8 rg8 rh8';
- //Hide the board
- $('#boardspan').hidden = true;
- //Widen the movelist to allow reading of setups
- $('#movelist').style.cssText='width:500px'
- //Find and hide the plan button; just remove the temptation :)
- for (i=0; true; ++i) {
- if (document.all[i].defaultValue==='P') {
- document.all[i].hidden=true;
- break; } }
- //Hide the captured pieces
- for (i=1; i<=16; ++i) {
- $('#cap_w'+i).hidden=true;
- $('#cap_b'+i).hidden=true; }
- //send any move, not checked for legality
- //After three seconds, will report errors
- function send(move){
- var obj = {action:"move", sid:arimaa.vars.sessionid, auth: arimaa.vars.auth, move: move}
- var req = new XMLHttpRequest();
- req.open(method = "post", "http://arimaa.com/arimaa/gameserver/client3gs.cgi", true);
- req.send(JSON.stringify(obj));
- setTimeout(function(){
- if (req.responseText.slice(2,7)==='error') { //Check for errors
- console.log('The gameserver rejected your move.');}},3000);};
- //eg 'Ed2nenn' to 'Ed2n Ed3e Ee3n Ee4n'
- function expand(movestring) {
- var piecelist='EeMmHhDdCcRr';
- var currpiece=false;
- var filelist='abcdefgh';
- var currfile=false;
- var filenum=false;
- var ranklist='12345678';
- var currrank=false;
- var ranknum=false;
- var havemoved=false;
- var dirlist='enwsx';
- var dirnum=false;
- var dirfilelist=[1,0,-1,0,0];
- var dirranklist=[0,1,0,-1,0];
- var iscaptured=false;
- var endstring='';
- for (i=0; i<movestring.length; ++i) {
- currchar=movestring[i];
- if (!currpiece) {
- for (j=0; j<piecelist.length; ++j) {
- if (currchar==piecelist[j]) {
- currpiece=currchar;}}
- if (!currpiece) {
- var q='error: bad piece type: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}}
- else if (!currfile) {
- for (j=0; j<filelist.length; ++j) {
- if (currchar==filelist[j]) {
- currfile=currchar;
- filenum=j;}}
- if (!currfile) {
- var q='error: bad file: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}}
- else if (!currrank) {
- for (j=0; j<ranklist.length; ++j) {
- if (currchar==ranklist[j]) {
- currrank=currchar;
- ranknum=j;}}
- if (!currrank) {
- var q='error: bad rank: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}}
- else if (havemoved&&(currchar==' ')) {
- currpiece=false;
- currfile=false;
- filenum=false;
- currrank=false;
- ranknum=false;
- havemoved=false;
- iscaptured=false;}
- else {
- if (iscaptured) {
- var q='error: captured piece moved: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}
- if (currchar=='x') {iscaptured=true;}
- havemoved=false;
- for (j=0; j<dirlist.length; ++j) {
- if (currchar==dirlist[j]) {
- dirnum=j;
- havemoved=true;}}
- if (!havemoved) {
- var q='error: bad direction: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}
- endstring+=currpiece+filelist[filenum];
- endstring+=ranklist[ranknum]+currchar+' ';
- filenum+=dirfilelist[dirnum]
- ranknum+=dirranklist[dirnum]
- if ((filenum<0)||(filenum>7)||(ranknum<0)||(ranknum>7)){
- var q='error: piece moved out of bounds: ';
- console.log(q+movestring.slice(0,i+1));
- return '';}
- }
- }
- if (currpiece&&(!havemoved)) {
- console.log('error: incomplete move');
- return '';}
- return endstring.slice(0,endstring.length-1);}
- //sh==shorthand; accepts compressed moves and expands before sending
- //Provides some help with obvious illegal moves, but doesn't catch nearly all
- function sh(movestring) {
- send(expand(movestring));}
- //Accepts fen-like general gold setups and sends them
- //eg sendset('RHCEMCHR/RRRDDRRR') sends the gold 99of9
- //setup and sendset('rrrddrrr/rhcmechr') sends the
- //silver 99of9 setup. Not checked for legality.
- function sendset(movestring) {
- var lowerrank=7;
- var goldpieces='EMHDCR';
- for (i=0; i<6; ++i) { //First check for which color we send the setup
- if (movestring[0]===goldpieces[i]) {
- lowerrank=1; } }
- var filenames='abcdefgh';
- var endstring='';
- for (i=0; i<8; ++i) {
- endstring+=movestring[i]+filenames[i]+(lowerrank+1)+' ';
- endstring+=movestring[i+9]+filenames[i]+lowerrank+' ';}
- send(endstring.slice(0,endstring.length-1));}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement